mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
feat(cloudwatch-logs): add ListTagsForResource, TagResource, and UntagResource support (#172)
Add the newer resource-based tag operations (ListTagsForResource, TagResource, UntagResource) to the CloudWatch Logs handler. These operations use ARN-based resource identification instead of the older log group name-based operations (ListTagsLogGroup, TagLogGroup, UntagLogGroup). The implementation extracts the log group name from the resource ARN and delegates to the existing tag service methods. Fixes #77
This commit is contained in:
1 parent
e78c833794
commit
835f8c6ff4
1 file changed
+43
+43
@@ -45,6 +45,9 @@ public class CloudWatchLogsHandler {
|
||||
case "TagLogGroup" -> handleTagLogGroup(request, region);
|
||||
case "UntagLogGroup" -> handleUntagLogGroup(request, region);
|
||||
case "ListTagsLogGroup" -> handleListTagsLogGroup(request, region);
|
||||
case "ListTagsForResource" -> handleListTagsForResource(request, region);
|
||||
case "TagResource" -> handleTagResource(request, region);
|
||||
case "UntagResource" -> handleUntagResource(request, region);
|
||||
default -> Response.status(400)
|
||||
.entity(new AwsErrorResponse("UnsupportedOperation", "Operation " + action + " is not supported."))
|
||||
.build();
|
||||
@@ -224,6 +227,46 @@ public class CloudWatchLogsHandler {
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleListTagsForResource(JsonNode request, String region) {
|
||||
String resourceArn = request.path("resourceArn").asText();
|
||||
String groupName = extractLogGroupNameFromArn(resourceArn);
|
||||
Map<String, String> tags = logsService.listTagsLogGroup(groupName, region);
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ObjectNode tagsNode = objectMapper.createObjectNode();
|
||||
tags.forEach(tagsNode::put);
|
||||
response.set("tags", tagsNode);
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleTagResource(JsonNode request, String region) {
|
||||
String resourceArn = request.path("resourceArn").asText();
|
||||
String groupName = extractLogGroupNameFromArn(resourceArn);
|
||||
Map<String, String> tags = extractTags(request.path("tags"));
|
||||
logsService.tagLogGroup(groupName, tags, region);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
private Response handleUntagResource(JsonNode request, String region) {
|
||||
String resourceArn = request.path("resourceArn").asText();
|
||||
String groupName = extractLogGroupNameFromArn(resourceArn);
|
||||
List<String> tagKeys = new ArrayList<>();
|
||||
request.path("tagKeys").forEach(k -> tagKeys.add(k.asText()));
|
||||
logsService.untagLogGroup(groupName, tagKeys, region);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
private String extractLogGroupNameFromArn(String arn) {
|
||||
if (arn != null && arn.contains(":log-group:")) {
|
||||
String name = arn.substring(arn.indexOf(":log-group:") + ":log-group:".length());
|
||||
if (name.endsWith(":*")) {
|
||||
name = name.substring(0, name.length() - 2);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
return arn;
|
||||
}
|
||||
|
||||
// ──────────────────────────── Helpers ────────────────────────────
|
||||
|
||||
private ArrayNode buildEventsArray(List<LogEvent> events) {
|
||||
|
||||
Reference in new issue
Block a user