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[]).
This commit is contained in:
Abhishek Dubey authored and GitHub committed 2026-06-25 19:14:43 -05:00
1 parent 952dec060f
commit e7b7839d85
6 files changed
+120

No files matched your search

@@ -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()) {
@@ -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<String> names = parseStringList(request.path("repositoryNames"));
String registryId = request.path("registryId").asText(null);
List<Repository> 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);
@@ -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<String, String> 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
// =========================================================================