mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(cloudwatchlogs): add logGroupArn to DescribeLogGroups (#3868)
This commit is contained in:
1 parent
78c046b883
commit
0108b9653a
2 files changed
+51
-1
No files matched your search
+48
@@ -0,0 +1,48 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.services.cloudwatchlogs.CloudWatchLogsClient;
|
||||
import software.amazon.awssdk.services.cloudwatchlogs.model.LogGroup;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@DisplayName("CloudWatch Logs DescribeLogGroups")
|
||||
class CloudWatchLogsDescribeLogGroupsTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("returns the AWS LogGroup ARN fields with their distinct formats")
|
||||
void returnsAwsLogGroupArnFields() {
|
||||
String groupName = "/test/" + TestFixtures.uniqueName("logs-describe-arn");
|
||||
try (CloudWatchLogsClient logs = TestFixtures.cloudWatchLogsClient()) {
|
||||
try {
|
||||
logs.createLogGroup(request -> request.logGroupName(groupName));
|
||||
|
||||
LogGroup group = logs.describeLogGroups(request -> request
|
||||
.logGroupNamePrefix(groupName))
|
||||
.logGroups()
|
||||
.stream()
|
||||
.filter(candidate -> groupName.equals(candidate.logGroupName()))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
|
||||
assertThat(group.arn())
|
||||
.isEqualTo("arn:aws:logs:us-east-1:000000000000:log-group:" + groupName + ":*");
|
||||
assertThat(group.logGroupArn())
|
||||
.isEqualTo("arn:aws:logs:us-east-1:000000000000:log-group:" + groupName);
|
||||
assertThat(group.logGroupArn()).doesNotEndWith(":*");
|
||||
} finally {
|
||||
deleteIfPresent(logs, groupName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void deleteIfPresent(CloudWatchLogsClient logs, String groupName) {
|
||||
logs.describeLogGroups(request -> request.logGroupNamePrefix(groupName))
|
||||
.logGroups()
|
||||
.stream()
|
||||
.filter(group -> groupName.equals(group.logGroupName()))
|
||||
.findFirst()
|
||||
.ifPresent(group -> logs.deleteLogGroup(request -> request.logGroupName(groupName)));
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -126,7 +126,9 @@ public class CloudWatchLogsHandler {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("logGroupName", g.getLogGroupName());
|
||||
node.put("createdTime", g.getCreatedTime());
|
||||
node.put("arn", logsService.buildArn(g.getLogGroupName(), region));
|
||||
String logGroupArn = logsService.buildArn(g.getLogGroupName(), region);
|
||||
node.put("arn", logGroupArn + ":*");
|
||||
node.put("logGroupArn", logGroupArn);
|
||||
if (g.getRetentionInDays() != null) {
|
||||
node.put("retentionInDays", g.getRetentionInDays());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user