From e7b7839d85b9a2d28cc0b3dfed05b4617531d653 Mon Sep 17 00:00:00 2001 From: Abhishek Dubey Date: Fri, 26 Jun 2026 05:44:43 +0530 Subject: [PATCH] fix: implement read APIs required by Steampipe resource collection (#1538) * fix: implement read APIs required by Steampipe resource collection IAM ListMFADevices, ECR BatchGetRepositoryScanningConfiguration, and CloudWatch Logs GetDataProtectionPolicy returned UnsupportedOperation (400). Each is invoked per-item by the Steampipe AWS plugin to enrich aws_iam_user, aws_ecr_repository, and aws_cloudwatch_log_group; the 400 aborted the whole table hydration, so those tables collected zero rows against Floci. Implement minimal, wire-accurate responses: - IAM ListMFADevices -> empty MFADevices list (IsTruncated=false) - ECR BatchGetRepositoryScanningConfiguration -> reuse describeRepositories, return MANUAL scan config - CloudWatch Logs GetDataProtectionPolicy -> empty policy at HTTP 200 (the steampipe aws plugin hydrate does not tolerate ResourceNotFound, so 200 is required for collection to succeed) Adds focused tests for each handler. * docs: ground read-API handler comments in AWS wire behavior Rewrite the ListMFADevices, BatchGetRepositoryScanningConfiguration, and GetDataProtectionPolicy handler comments to describe real AWS response shapes, enum values, and error semantics (NoSuchEntity 404, scanFrequency enum, ResourceNotFoundException 400) instead of referencing a specific consumer. Note the known deviations (200-empty vs error, batch-fail vs failures[]). --- .../logs/CloudWatchLogsHandler.java | 15 ++++++++++ .../floci/services/ecr/EcrJsonHandler.java | 30 +++++++++++++++++++ .../floci/services/iam/IamQueryHandler.java | 12 ++++++++ .../logs/CloudWatchLogsHandlerTest.java | 26 ++++++++++++++++ .../services/ecr/EcrIntegrationTest.java | 21 +++++++++++++ .../services/iam/IamIntegrationTest.java | 16 ++++++++++ 6 files changed, 120 insertions(+) diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandler.java b/src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandler.java index b845906ba3..f0472ea95b 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandler.java @@ -52,6 +52,7 @@ public class CloudWatchLogsHandler { case "PutSubscriptionFilter" -> handlePutSubscriptionFilter(request, region); case "DescribeSubscriptionFilters" -> handleDescribeSubscriptionFilters(request, region); case "DeleteSubscriptionFilter" -> handleDeleteSubscriptionFilter(request, region); + case "GetDataProtectionPolicy" -> handleGetDataProtectionPolicy(request, region); default -> Response.status(400) .entity(new AwsErrorResponse("UnsupportedOperation", "Operation " + action + " is not supported.")) .build(); @@ -311,6 +312,20 @@ public class CloudWatchLogsHandler { return Response.ok(objectMapper.createObjectNode()).build(); } + private Response handleGetDataProtectionPolicy(JsonNode request, String region) { + // Data-protection policies are not modeled. Return HTTP 200 with the resolved + // logGroupIdentifier and no policyDocument ("no policy set"). Real AWS returns + // ResourceNotFoundException (HTTP 400) when the resource does not exist — the + // 200-empty response is a deliberate Floci simplification for read-only callers. + String identifier = resolveLogGroupName(request); + ObjectNode response = objectMapper.createObjectNode(); + if (identifier != null) { + response.put("logGroupIdentifier", identifier); + } + // policyDocument intentionally omitted -> no data-protection policy + return Response.ok(response).build(); + } + private String resolveLogGroupName(JsonNode request) { String name = request.path("logGroupName").asText(null); if (name == null || name.isBlank()) { diff --git a/src/main/java/io/github/hectorvent/floci/services/ecr/EcrJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/ecr/EcrJsonHandler.java index 76140e0a9c..16f89f903c 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ecr/EcrJsonHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/ecr/EcrJsonHandler.java @@ -42,6 +42,8 @@ public class EcrJsonHandler { return switch (action) { case "CreateRepository" -> handleCreateRepository(request, region); case "DescribeRepositories" -> handleDescribeRepositories(request, region); + case "BatchGetRepositoryScanningConfiguration" -> + handleBatchGetRepositoryScanningConfiguration(request, region); case "DeleteRepository" -> handleDeleteRepository(request, region); case "GetAuthorizationToken" -> handleGetAuthorizationToken(request); case "ListImages" -> handleListImages(request, region); @@ -99,6 +101,34 @@ public class EcrJsonHandler { return Response.ok(response).build(); } + private Response handleBatchGetRepositoryScanningConfiguration(JsonNode request, String region) { + // Scanning configuration is not modeled. Resolve names via describeRepositories + // and synthesize a wire-accurate RepositoryScanningConfiguration per repo: + // scanFrequency derived from scanOnPush (AWS enum: SCAN_ON_PUSH|CONTINUOUS_SCAN| + // MANUAL), with empty appliedScanFilters. Note: real AWS reports unknown repos + // in the `failures` array; here describeRepositories throws + // RepositoryNotFoundException, failing the whole batch instead. + List names = parseStringList(request.path("repositoryNames")); + String registryId = request.path("registryId").asText(null); + + List repos = service.describeRepositories(names, registryId, region); + + ObjectNode response = objectMapper.createObjectNode(); + ArrayNode configs = objectMapper.createArrayNode(); + for (Repository r : repos) { + ObjectNode cfg = objectMapper.createObjectNode(); + cfg.put("repositoryArn", r.getRepositoryArn()); + cfg.put("repositoryName", r.getRepositoryName()); + cfg.put("scanOnPush", r.isScanOnPush()); + cfg.put("scanFrequency", r.isScanOnPush() ? "SCAN_ON_PUSH" : "MANUAL"); + cfg.set("appliedScanFilters", objectMapper.createArrayNode()); + configs.add(cfg); + } + response.set("scanningConfigurations", configs); + response.set("failures", objectMapper.createArrayNode()); + return Response.ok(response).build(); + } + private Response handleDeleteRepository(JsonNode request, String region) { String repositoryName = request.path("repositoryName").asText(null); String registryId = request.path("registryId").asText(null); diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java index 562439c58f..c69714a174 100644 --- a/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java @@ -56,6 +56,7 @@ public class IamQueryHandler { case "TagUser" -> handleTagUser(params); case "UntagUser" -> handleUntagUser(params); case "ListUserTags" -> handleListUserTags(params); + case "ListMFADevices" -> handleListMFADevices(params); // Groups case "CreateGroup" -> handleCreateGroup(params); @@ -223,6 +224,17 @@ public class IamQueryHandler { return Response.ok(AwsQueryResponse.envelope("ListUserTags", AwsNamespaces.IAM, result)).build(); } + private Response handleListMFADevices(MultivaluedMap params) { + // MFA device state is not modeled; return the wire-accurate empty result + // (MFADevices list + IsTruncated=false). Real AWS returns NoSuchEntity + // (HTTP 404) for an unknown user — Floci returns an empty list regardless. + String result = new XmlBuilder() + .start("MFADevices").end("MFADevices") + .elem("IsTruncated", false) + .build(); + return Response.ok(AwsQueryResponse.envelope("ListMFADevices", AwsNamespaces.IAM, result)).build(); + } + // ========================================================================= // Groups // ========================================================================= diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandlerTest.java index 873dd97d25..647de15382 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandlerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandlerTest.java @@ -70,6 +70,32 @@ class CloudWatchLogsHandlerTest { assertEquals(STREAM, streams.get(0).path("logStreamName").asText()); } + // ──────────────────────────── GetDataProtectionPolicy ──────────────────────────── + + @Test + void getDataProtectionPolicyReturnsEmptyPolicyWith200() { + ObjectNode request = MAPPER.createObjectNode(); + request.put("logGroupIdentifier", GROUP); + + Response response = handler.handle("GetDataProtectionPolicy", request, REGION); + + assertEquals(200, response.getStatus()); + JsonNode body = (JsonNode) response.getEntity(); + assertEquals(GROUP, body.path("logGroupIdentifier").asText()); + assertTrue(body.path("policyDocument").isMissingNode()); + } + + @Test + void getDataProtectionPolicyByNameAlsoSucceeds() { + ObjectNode request = MAPPER.createObjectNode(); + request.put("logGroupName", GROUP); + + Response response = handler.handle("GetDataProtectionPolicy", request, REGION); + + assertEquals(200, response.getStatus()); + assertEquals(GROUP, ((JsonNode) response.getEntity()).path("logGroupIdentifier").asText()); + } + @Test void describeLogStreamsByLogGroupIdentifierArnWithWildcardSuffix() { ObjectNode request = MAPPER.createObjectNode(); diff --git a/src/test/java/io/github/hectorvent/floci/services/ecr/EcrIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ecr/EcrIntegrationTest.java index 1e559764d4..43287183dd 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ecr/EcrIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ecr/EcrIntegrationTest.java @@ -156,6 +156,27 @@ class EcrIntegrationTest { @Test @Order(8) + void batchGetRepositoryScanningConfiguration() { + given() + .header("X-Amz-Target", PREFIX + "BatchGetRepositoryScanningConfiguration") + .contentType(CT) + .body(""" + { "repositoryNames": ["%s"] } + """.formatted(REPO)) + .when() + .post("/") + .then() + .statusCode(200) + .body("scanningConfigurations[0].repositoryName", equalTo(REPO)) + .body("scanningConfigurations[0].repositoryArn", startsWith("arn:aws:ecr:")) + .body("scanningConfigurations[0].scanOnPush", equalTo(false)) + .body("scanningConfigurations[0].scanFrequency", equalTo("MANUAL")) + .body("scanningConfigurations[0].appliedScanFilters", empty()) + .body("failures", empty()); + } + + @Test + @Order(9) void deleteRepositoryForce() { given() .header("X-Amz-Target", PREFIX + "DeleteRepository") diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/IamIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/IamIntegrationTest.java index 113746c3ad..4d925eefee 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/IamIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/IamIntegrationTest.java @@ -369,6 +369,22 @@ class IamIntegrationTest { // Users // ========================================================================= + @Test + @Order(50) + void listMfaDevicesReturnsEmptyList() { + given() + .formParam("Action", "ListMFADevices") + .formParam("UserName", "any-user") + .header("Authorization", + "AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request") + .when() + .post("/") + .then() + .statusCode(200) + .contentType("application/xml") + .body("ListMFADevicesResponse.ListMFADevicesResult.IsTruncated", equalTo("false")); + } + @Test @Order(10) void createUser() {