mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat: implement read-only describe/list APIs for resource collection (#1581)
* feat: implement read-only describe/list APIs for resource collection
Several read-only AWS actions returned UnsupportedOperation (HTTP 400) — or,
where no route existed, a 404 the AWS SDKs deserialize to a retryable
UnknownError. Both break clients that enumerate an account read-only: the 400
aborts the collection of the whole resource type, and the 404 sends the SDK
through its full retry/backoff schedule (~9 attempts, minutes) on every call.
Implement minimal, wire-accurate responses that mirror each service's documented
contract so SDK clients complete the read:
- IAM
- GetLoginProfile -> NoSuchEntity (404), the documented result when a user has
no console password; clients branch on it, so a 200 or 400 misleads them.
- GetAccessKeyLastUsed -> the "never used" shape (ServiceName/Region = N/A, no
LastUsedDate).
- ListSAMLProviders / ListOpenIDConnectProviders / ListServerCertificates ->
empty lists (non-paginated; ListServerCertificates carries IsTruncated=false).
- RDS: DescribeDBSnapshots / DescribeDBProxies / DescribeDBClusterSnapshots ->
empty results (empty wrapper, no Marker).
- DocDB: DescribeDBClusterSnapshots -> empty result (RDS namespace).
- ElastiCache: DescribeCacheSubnetGroups / DescribeCacheParameterGroups -> empty.
- Glue: GetJobs / GetCrawlers / ListDataQualityRulesets /
GetSecurityConfigurations / GetTags -> empty result under each result key.
- SSM: ListDocuments / ListAssociations / DescribeMaintenanceWindows -> empty
(NextToken omitted).
- AWS Backup: GetBackupVaultNotifications / GetBackupVaultAccessPolicy ->
ResourceNotFoundException (400), the documented "not configured" signal.
- S3 Control: ListAccessPoints -> empty AccessPointList (200), replacing the
missing-route 404 that triggered the SDK retry storm.
Responses are grounded in the AWS API reference for each action (error codes,
HTTP statuses, and "empty"/"never used" shapes). Adds focused unit and
integration tests for each handler.
* docs: ground ListAccessPoints comment in the S3 Control contract
Drop the consumer-specific retry magnitude ("~9 attempts") from the
ListAccessPoints comment and justify the empty-200 response purely on the AWS
contract: ListAccessPoints documents a single success path — HTTP 200 with an
AccessPointList (empty when the account has none) and an optional NextToken.
404 is not a documented outcome for the operation, so a missing route leaves
SDK clients unable to map the response to the expected result or a known error.
* fix(glue): keep GetTags delegating to the schema registry
The earlier commit replaced Glue GetTags with a hardcoded empty {"Tags":{}},
which regressed the schema-registry tagging path: GetTags must return the tags
stored for a registry/schema ARN and InvalidInputException for an unknown ARN.
Restore the original handleGetTags delegation and drop the empty-stub test for
it. GetTags was already implemented — only GetJobs/GetCrawlers/
ListDataQualityRulesets/GetSecurityConfigurations were genuine gaps, and those
remain empty stubs.
Fixes GlueSchemaRegistryMetadataAndTagsIntegrationTest (getTagsReturnsAddedTags,
untagResourceRemovesKey, getTagsOnUnknownArnReturnsInvalidInput) and the
sdk-test-java GlueSchemaRegistryTest compat failure.
* fix(iam): omit empty UserName from GetAccessKeyLastUsed
UserName is optional in the IAM model and its type is non-empty
(length 1-128). The emulator has no AccessKeyId->UserName lookup, so
emitting an empty <UserName></UserName> could be rejected by a strict
client. Omit the element entirely instead; callers that need the owner
already have it from the preceding ListAccessKeys response.
* fix(backup): drop unused headers param from vault notification/access-policy stubs
* test(iam): cover GetLoginProfile, ListSAMLProviders, ListOpenIDConnectProviders, ListServerCertificates
This commit is contained in:
1 parent
94a2ff3993
commit
a40dc52f4d
15 files changed
+565
No files matched your search
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.backup.model.*;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -87,6 +88,29 @@ public class BackupController {
|
||||
return Response.ok(out).build();
|
||||
}
|
||||
|
||||
// Notification configuration is an optional, never-configured aspect of a vault in the
|
||||
// emulator. Per the AWS Backup API, GetBackupVaultNotifications returns
|
||||
// ResourceNotFoundException (HTTP 400) when no notification configuration exists for the
|
||||
// vault. We mirror that exact error contract so SDK clients see the documented
|
||||
// "not configured" signal rather than an empty 200 or a generic 400 they can't interpret.
|
||||
@GET
|
||||
@Path("/backup-vaults/{backupVaultName}/notification-configuration")
|
||||
public Response getBackupVaultNotifications(@PathParam("backupVaultName") String vaultName) {
|
||||
throw new AwsException("ResourceNotFoundException",
|
||||
"No notification configuration found for backup vault: " + vaultName, 400);
|
||||
}
|
||||
|
||||
// Access policy is an optional, never-configured aspect of a vault in the emulator. Per the
|
||||
// AWS Backup API, GetBackupVaultAccessPolicy returns ResourceNotFoundException (HTTP 400)
|
||||
// when no policy exists for the vault. We mirror that exact error contract so SDK clients
|
||||
// see the documented "not configured" signal rather than an empty 200 or a generic 400.
|
||||
@GET
|
||||
@Path("/backup-vaults/{backupVaultName}/access-policy")
|
||||
public Response getBackupVaultAccessPolicy(@PathParam("backupVaultName") String vaultName) {
|
||||
throw new AwsException("ResourceNotFoundException",
|
||||
"No access policy found for backup vault: " + vaultName, 400);
|
||||
}
|
||||
|
||||
// ── Plan ───────────────────────────────────────────────────────────────────
|
||||
|
||||
@PUT
|
||||
|
||||
@@ -35,6 +35,7 @@ public class DocDbQueryHandler {
|
||||
return switch (action) {
|
||||
case "CreateDBCluster" -> handleCreateDbCluster(params);
|
||||
case "DescribeDBClusters" -> handleDescribeDbClusters(params);
|
||||
case "DescribeDBClusterSnapshots" -> handleDescribeDbClusterSnapshots(params);
|
||||
case "DeleteDBCluster" -> handleDeleteDbCluster(params);
|
||||
case "ModifyDBCluster" -> handleModifyDbCluster(params);
|
||||
case "CreateDBInstance" -> handleCreateDbInstance(params);
|
||||
@@ -94,6 +95,14 @@ public class DocDbQueryHandler {
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeDBClusters", AwsNamespaces.RDS, xml.build())).build();
|
||||
}
|
||||
|
||||
private Response handleDescribeDbClusterSnapshots(MultivaluedMap<String, String> params) {
|
||||
// Snapshots are not modeled by the emulator; return the wire-accurate empty result
|
||||
// the DocDB/RDS Query API uses (empty <DBClusterSnapshots/>, no <Marker>) so SDK
|
||||
// clients complete the read instead of failing on an unsupported action.
|
||||
XmlBuilder xml = new XmlBuilder().start("DBClusterSnapshots").end("DBClusterSnapshots");
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeDBClusterSnapshots", AwsNamespaces.RDS, xml.build())).build();
|
||||
}
|
||||
|
||||
private Response handleDeleteDbCluster(MultivaluedMap<String, String> params) {
|
||||
String id = params.getFirst("DBClusterIdentifier");
|
||||
if (id == null || id.isBlank()) {
|
||||
|
||||
+18
@@ -62,6 +62,8 @@ public class ElastiCacheQueryHandler {
|
||||
case "CreateCacheCluster" -> handleCreateCacheCluster(params);
|
||||
case "DescribeCacheClusters" -> handleDescribeCacheClusters(params);
|
||||
case "DeleteCacheCluster" -> handleDeleteCacheCluster(params);
|
||||
case "DescribeCacheSubnetGroups" -> handleDescribeCacheSubnetGroups(params);
|
||||
case "DescribeCacheParameterGroups" -> handleDescribeCacheParameterGroups(params);
|
||||
default -> AwsQueryResponse.error("UnsupportedOperation",
|
||||
"Operation " + action + " is not supported.", AwsNamespaces.EC, 400);
|
||||
};
|
||||
@@ -278,6 +280,22 @@ public class ElastiCacheQueryHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Subnet / Parameter Groups (read-only describes for resources not modeled) ────
|
||||
|
||||
private Response handleDescribeCacheSubnetGroups(MultivaluedMap<String, String> params) {
|
||||
// Cache subnet groups are not modeled by the emulator; return the wire-accurate
|
||||
// empty result so SDK clients get a valid 200 instead of an unsupported-action 400.
|
||||
var xml = new XmlBuilder().start("CacheSubnetGroups").end("CacheSubnetGroups");
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeCacheSubnetGroups", AwsNamespaces.EC, xml.build())).build();
|
||||
}
|
||||
|
||||
private Response handleDescribeCacheParameterGroups(MultivaluedMap<String, String> params) {
|
||||
// Cache parameter groups are not modeled by the emulator; return the wire-accurate
|
||||
// empty result so SDK clients get a valid 200 instead of an unsupported-action 400.
|
||||
var xml = new XmlBuilder().start("CacheParameterGroups").end("CacheParameterGroups");
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeCacheParameterGroups", AwsNamespaces.EC, xml.build())).build();
|
||||
}
|
||||
|
||||
// ── IAM Token Validation ──────────────────────────────────────────────────
|
||||
|
||||
private Response handleValidateIamAuthToken(MultivaluedMap<String, String> params) {
|
||||
|
||||
@@ -167,6 +167,13 @@ public class GlueJsonHandler {
|
||||
case "TagResource" -> handleTagResource(request);
|
||||
case "UntagResource" -> handleUntagResource(request);
|
||||
case "GetTags" -> handleGetTags(request);
|
||||
// Read-only Glue actions for resources the emulator does not model. The AWS SDK
|
||||
// expects each to return a 200 with its result key present (empty), so we emit the
|
||||
// documented empty shape rather than an InvalidAction 400 that callers can't read.
|
||||
case "GetJobs" -> Response.ok(Map.of("Jobs", List.of())).build();
|
||||
case "GetCrawlers" -> Response.ok(Map.of("Crawlers", List.of())).build();
|
||||
case "ListDataQualityRulesets" -> Response.ok(Map.of("Rulesets", List.of())).build();
|
||||
case "GetSecurityConfigurations" -> Response.ok(Map.of("SecurityConfigurations", List.of())).build();
|
||||
default -> throw new AwsException("InvalidAction", "Action " + action + " is not supported", 400);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -57,6 +57,12 @@ public class IamQueryHandler {
|
||||
case "UntagUser" -> handleUntagUser(params);
|
||||
case "ListUserTags" -> handleListUserTags(params);
|
||||
case "ListMFADevices" -> handleListMFADevices(params);
|
||||
case "GetLoginProfile" -> handleGetLoginProfile(params);
|
||||
|
||||
// Identity providers & server certificates (read-only, not modeled)
|
||||
case "ListSAMLProviders" -> handleListSAMLProviders(params);
|
||||
case "ListOpenIDConnectProviders" -> handleListOpenIDConnectProviders(params);
|
||||
case "ListServerCertificates" -> handleListServerCertificates(params);
|
||||
|
||||
// Groups
|
||||
case "CreateGroup" -> handleCreateGroup(params);
|
||||
@@ -130,6 +136,7 @@ public class IamQueryHandler {
|
||||
case "DeleteAccessKey" -> handleDeleteAccessKey(params);
|
||||
case "ListAccessKeys" -> handleListAccessKeys(params);
|
||||
case "UpdateAccessKey" -> handleUpdateAccessKey(params);
|
||||
case "GetAccessKeyLastUsed" -> handleGetAccessKeyLastUsed(params);
|
||||
|
||||
// Instance Profiles
|
||||
case "CreateInstanceProfile" -> handleCreateInstanceProfile(params);
|
||||
@@ -235,6 +242,45 @@ public class IamQueryHandler {
|
||||
return Response.ok(AwsQueryResponse.envelope("ListMFADevices", AwsNamespaces.IAM, result)).build();
|
||||
}
|
||||
|
||||
private Response handleGetLoginProfile(MultivaluedMap<String, String> params) {
|
||||
// Login profiles (console passwords) are not modeled. Per the IAM API,
|
||||
// GetLoginProfile returns NoSuchEntity (HTTP 404) when a user has no console
|
||||
// password — a documented, expected result that callers branch on. We must
|
||||
// return that exact error, not an empty 200 or an UnsupportedOperation 400,
|
||||
// which clients would treat as a real failure rather than "no profile".
|
||||
String userName = getParam(params, "UserName");
|
||||
return AwsQueryResponse.error("NoSuchEntity",
|
||||
"Login Profile for User " + (userName != null ? userName : "") + " cannot be found.",
|
||||
AwsNamespaces.IAM, 404);
|
||||
}
|
||||
|
||||
private Response handleListSAMLProviders(MultivaluedMap<String, String> params) {
|
||||
// SAML identity providers are not modeled; return the wire-accurate empty
|
||||
// list (ListSAMLProviders is not paginated — no Marker/IsTruncated).
|
||||
String result = new XmlBuilder()
|
||||
.start("SAMLProviderList").end("SAMLProviderList")
|
||||
.build();
|
||||
return Response.ok(AwsQueryResponse.envelope("ListSAMLProviders", AwsNamespaces.IAM, result)).build();
|
||||
}
|
||||
|
||||
private Response handleListOpenIDConnectProviders(MultivaluedMap<String, String> params) {
|
||||
// OIDC identity providers are not modeled; return the wire-accurate empty
|
||||
// list (ListOpenIDConnectProviders is not paginated).
|
||||
String result = new XmlBuilder()
|
||||
.start("OpenIDConnectProviderList").end("OpenIDConnectProviderList")
|
||||
.build();
|
||||
return Response.ok(AwsQueryResponse.envelope("ListOpenIDConnectProviders", AwsNamespaces.IAM, result)).build();
|
||||
}
|
||||
|
||||
private Response handleListServerCertificates(MultivaluedMap<String, String> params) {
|
||||
// Server certificates are not modeled; return an empty paginated list.
|
||||
String result = new XmlBuilder()
|
||||
.start("ServerCertificateMetadataList").end("ServerCertificateMetadataList")
|
||||
.elem("IsTruncated", false)
|
||||
.build();
|
||||
return Response.ok(AwsQueryResponse.envelope("ListServerCertificates", AwsNamespaces.IAM, result)).build();
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Groups
|
||||
// =========================================================================
|
||||
@@ -647,6 +693,23 @@ public class IamQueryHandler {
|
||||
return Response.ok(AwsQueryResponse.envelopeNoResult("UpdateAccessKey", AwsNamespaces.IAM)).build();
|
||||
}
|
||||
|
||||
private Response handleGetAccessKeyLastUsed(MultivaluedMap<String, String> params) {
|
||||
// Access-key usage is not modeled, so return the IAM API's documented
|
||||
// "never used" shape: an AccessKeyLastUsed with ServiceName=N/A and Region=N/A
|
||||
// and NO LastUsedDate. UserName is optional and its type is non-empty
|
||||
// (length 1-128); since the emulator exposes no AccessKeyId→UserName lookup,
|
||||
// the element is omitted rather than emitted empty — an empty string could be
|
||||
// rejected by a strict client, and callers that need the owner already have it
|
||||
// from the preceding ListAccessKeys call.
|
||||
String result = new XmlBuilder()
|
||||
.start("AccessKeyLastUsed")
|
||||
.elem("ServiceName", "N/A")
|
||||
.elem("Region", "N/A")
|
||||
.end("AccessKeyLastUsed")
|
||||
.build();
|
||||
return Response.ok(AwsQueryResponse.envelope("GetAccessKeyLastUsed", AwsNamespaces.IAM, result)).build();
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Instance Profiles
|
||||
// =========================================================================
|
||||
|
||||
@@ -69,6 +69,9 @@ public class RdsQueryHandler {
|
||||
case "DeleteDBClusterParameterGroup" -> handleDeleteDbClusterParameterGroup(params);
|
||||
case "ModifyDBClusterParameterGroup" -> handleModifyDbClusterParameterGroup(params);
|
||||
case "DescribeDBClusterParameters" -> handleDescribeDbClusterParameters(params);
|
||||
case "DescribeDBSnapshots" -> handleDescribeDbSnapshots(params);
|
||||
case "DescribeDBProxies" -> handleDescribeDbProxies(params);
|
||||
case "DescribeDBClusterSnapshots" -> handleDescribeDbClusterSnapshots(params);
|
||||
case "AddTagsToResource" -> handleAddTagsToResource(params);
|
||||
case "ListTagsForResource" -> handleListTagsForResource(params);
|
||||
case "RemoveTagsFromResource" -> handleRemoveTagsFromResource(params);
|
||||
@@ -586,6 +589,32 @@ public class RdsQueryHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Snapshots & Proxies (not modeled — empty lists) ───────────────────────
|
||||
|
||||
private Response handleDescribeDbSnapshots(MultivaluedMap<String, String> params) {
|
||||
// DB snapshots are not modeled; return the RDS Query API's wire-accurate empty
|
||||
// result (empty <DBSnapshots> wrapper, no <Marker>) so SDK clients complete the
|
||||
// read instead of failing with UnsupportedOperation.
|
||||
String result = new XmlBuilder().start("DBSnapshots").end("DBSnapshots").build();
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeDBSnapshots", AwsNamespaces.RDS, result)).build();
|
||||
}
|
||||
|
||||
private Response handleDescribeDbProxies(MultivaluedMap<String, String> params) {
|
||||
// DB proxies are not modeled; return the RDS Query API's wire-accurate empty
|
||||
// result (empty <DBProxies> wrapper, no <Marker>) so SDK clients complete the
|
||||
// read instead of failing with UnsupportedOperation.
|
||||
String result = new XmlBuilder().start("DBProxies").end("DBProxies").build();
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeDBProxies", AwsNamespaces.RDS, result)).build();
|
||||
}
|
||||
|
||||
private Response handleDescribeDbClusterSnapshots(MultivaluedMap<String, String> params) {
|
||||
// DB cluster snapshots are not modeled; return the RDS Query API's wire-accurate
|
||||
// empty result (empty <DBClusterSnapshots> wrapper, no <Marker>) so SDK clients
|
||||
// complete the read instead of failing with UnsupportedOperation.
|
||||
String result = new XmlBuilder().start("DBClusterSnapshots").end("DBClusterSnapshots").build();
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeDBClusterSnapshots", AwsNamespaces.RDS, result)).build();
|
||||
}
|
||||
|
||||
// ── XML builders ──────────────────────────────────────────────────────────
|
||||
|
||||
private String dbInstanceXml(DbInstance i) {
|
||||
|
||||
@@ -76,6 +76,40 @@ public class S3ControlController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ListAccessPoints — returns the account's S3 access points.
|
||||
*
|
||||
* <p>The emulator has no access-point store. Per the S3 Control API, the only success
|
||||
* response for ListAccessPoints is HTTP 200 with a {@code <ListAccessPointsResult>}
|
||||
* carrying an {@code <AccessPointList>} — empty when the account has none — and an
|
||||
* optional {@code <NextToken>}. 404 is not a documented outcome for this operation, so
|
||||
* without this route an AWS SDK client cannot map the response to the expected result
|
||||
* or to a known error and the read fails (and, depending on the client's retry config,
|
||||
* may burn its retry budget on the unexpected status first). We therefore return the
|
||||
* documented empty list: an {@code <AccessPointList/>} with no {@code <NextToken>},
|
||||
* which ends pagination immediately.
|
||||
*
|
||||
* GET /v20180820/accesspoint
|
||||
* Header: x-amz-account-id
|
||||
*/
|
||||
@GET
|
||||
@Path("/accesspoint")
|
||||
public Response listAccessPoints(
|
||||
@HeaderParam("x-amz-account-id") String accountId,
|
||||
@QueryParam("bucket") String bucket,
|
||||
@QueryParam("maxResults") String maxResults,
|
||||
@QueryParam("nextToken") String nextToken) {
|
||||
|
||||
String xml = new XmlBuilder()
|
||||
.raw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
|
||||
.start("ListAccessPointsResult", AwsNamespaces.S3_CONTROL)
|
||||
.start("AccessPointList")
|
||||
.end("AccessPointList")
|
||||
.end("ListAccessPointsResult")
|
||||
.build();
|
||||
return Response.ok(xml).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* TagResource — replaces all tags on the specified S3 bucket.
|
||||
*
|
||||
|
||||
@@ -61,6 +61,10 @@ public class SsmJsonHandler {
|
||||
// Patch Manager (read-only: AWS-owned predefined baselines)
|
||||
case "DescribePatchBaselines" -> handleDescribePatchBaselines(request, region);
|
||||
case "GetDefaultPatchBaseline" -> handleGetDefaultPatchBaseline(request, region);
|
||||
// Read-only list operations (resources not modeled: empty results)
|
||||
case "ListDocuments" -> handleListDocuments(request, region);
|
||||
case "ListAssociations" -> handleListAssociations(request, region);
|
||||
case "DescribeMaintenanceWindows" -> handleDescribeMaintenanceWindows(request, region);
|
||||
// Agent registration (internal, not in public SDK)
|
||||
case "UpdateInstanceInformation" -> handleUpdateInstanceInformation(request, region);
|
||||
default -> Response.status(400)
|
||||
@@ -245,6 +249,27 @@ public class SsmJsonHandler {
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleListDocuments(JsonNode request, String region) {
|
||||
// SSM documents are not modeled: return an empty list.
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("DocumentIdentifiers", objectMapper.createArrayNode());
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleListAssociations(JsonNode request, String region) {
|
||||
// SSM associations are not modeled: return an empty list.
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("Associations", objectMapper.createArrayNode());
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleDescribeMaintenanceWindows(JsonNode request, String region) {
|
||||
// Maintenance windows are not modeled: return an empty list.
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("WindowIdentities", objectMapper.createArrayNode());
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleLabelParameterVersion(JsonNode request, String region) {
|
||||
String name = request.path("Name").asText();
|
||||
long parameterVersion = request.path("ParameterVersion").asLong();
|
||||
|
||||
Reference in new issue
Block a user