fix(accessanalyzer): route GetAnalyzer through GET /analyzer/<name> (#5534)

* fix(accessanalyzer): route GetAnalyzer through GET /analyzer/<name>

Adds getAnalyzer service method and GET /analyzer/{analyzerName} endpoint
in AccessAnalyzerController to return analyzer details. Returns
ResourceNotFoundException (404) when analyzer does not exist. Adds
integration tests for retrieval and not found cases.

Fixes #5353
Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>

* docs(accessanalyzer): sync the action table for GetAnalyzer

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>

* fix(accessanalyzer): share not-found helper and align docs/service matrix

Extract a shared analyzerNotFound helper that returns ResourceNotFoundException
with resourceId/resourceType (analyzer) for both get/delete. Remove trailing
blank lines from the controller. Update docs/services/index.md to list 4
operations. Run make docs-sync to keep action tables in sync.

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>

* fix(accessanalyzer): reuse getAnalyzer in deleteAnalyzer and assert not-found fields

deleteAnalyzer repeated getAnalyzer's validate-and-lookup; it now calls
getAnalyzer before deleting, so the lookup and the not-found error live in
one place. The 404 test now checks the resourceId and resourceType the
shared helper adds, and the stray blank line before the class's closing
brace is gone.

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>

---------

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
Matheus Oliveira authored and GitHub committed 2026-10-14 14:06:51 -04:00
1 parent 15f50cb68e
commit 988991033f
5 files changed
+56 -8

No files matched your search

+1
View File
@@ -14,6 +14,7 @@ Floci supports the analyzer lifecycle used by local governance workflows.
| `ListAnalyzers` | - |
| `CreateAnalyzer` | - |
| `DeleteAnalyzer` | - |
| `GetAnalyzer` | - |
<!-- floci:actions:end -->
Analyzer state is account and Region scoped and persisted through `StorageFactory`.
+1 -1
View File
@@ -47,7 +47,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
| [CloudWatch RUM](rum.md) | `/appmonitor`, `/appmonitor/{name}`, `/appmonitors` | REST JSON | 5 |
| [GuardDuty](guardduty.md) | `/detector`, `/detector/{detectorId}`, `/detector/{detectorId}/admin`, `/admin/*`, `/tags/*` | REST JSON | 13 |
| [AWS Account Management](account.md) | `/putAlternateContact`, `/getAlternateContact` | REST JSON | 2 |
| [IAM Access Analyzer](access-analyzer.md) | `/analyzer`, `/analyzer/{name}` | REST JSON | 3 |
| [IAM Access Analyzer](access-analyzer.md) | `/analyzer`, `/analyzer/{name}` | REST JSON | 4 |
| [IAM Identity Center (SSO Admin)](ssoadmin.md) | `POST /` + `X-Amz-Target: SWBExternalService.*` | JSON 1.1 | 79 |
| [IAM Identity Center OIDC](ssooidc.md) | `/client/register`, `/device_authorization`, `/token`, `/token?aws_iam=t`, `/authorize`, `/device` | REST JSON | 4 |
| [IAM Identity Center Access Portal](ssoportal.md) | `/assignment/accounts`, `/assignment/roles`, `/federation/credentials`, `/logout` | REST JSON | 4 |
@@ -75,6 +75,16 @@ public class AccessAnalyzerController {
return Response.ok(objectMapper.createObjectNode()).build();
}
@GET
@Path("/analyzer/{analyzerName}")
public Response getAnalyzer(@Context HttpHeaders headers, @PathParam("analyzerName") String analyzerName) {
String region = regionResolver.resolveRegion(headers);
Analyzer analyzer = accessAnalyzerService.getAnalyzer(region, analyzerName);
ObjectNode response = objectMapper.createObjectNode();
response.set("analyzer", analyzerSummary(analyzer));
return Response.ok(response).build();
}
private ObjectNode analyzerSummary(Analyzer analyzer) {
ObjectNode node = objectMapper.createObjectNode();
node.put("arn", analyzer.getArn());
@@ -84,13 +84,8 @@ public class AccessAnalyzerService implements Resettable {
}
public synchronized void deleteAnalyzer(String region, String analyzerName) {
validateAnalyzerName(analyzerName);
String key = storageKey(region, analyzerName);
if (analyzers.get(key).isEmpty()) {
throw new AwsException("ResourceNotFoundException",
"The specified analyzer could not be found.", 404);
}
analyzers.delete(key);
getAnalyzer(region, analyzerName);
analyzers.delete(storageKey(region, analyzerName));
}
private static int analyzerLimit(String type) {
@@ -158,4 +153,24 @@ public class AccessAnalyzerService implements Resettable {
private static AwsException validation(String message) {
return new AwsException("ValidationException", message, 400);
}
public Analyzer getAnalyzer(String region, String analyzerName) {
validateAnalyzerName(analyzerName);
String key = storageKey(region, analyzerName);
return analyzers.get(key).orElseThrow(() -> analyzerNotFound(analyzerName));
}
private static AwsException analyzerNotFound(String analyzerName) {
return new AwsException("ResourceNotFoundException", "The specified analyzer could not be found.", 404,
resourceFields(analyzerName, "analyzer"));
}
private static Map<String, Object> resourceFields(String resourceId, String resourceType) {
Map<String, Object> fields = new LinkedHashMap<>();
fields.put("resourceType", resourceType);
if (resourceId != null) {
fields.put("resourceId", resourceId);
}
return fields;
}
}
@@ -69,4 +69,26 @@ class AccessAnalyzerIntegrationTest {
.body("{\"analyzerName\":\"bad-analyzer\",\"type\":\"INVALID\"}")
.put("/analyzer").then().statusCode(400).body("__type", equalTo("ValidationException"));
}
@Test
void getAnalyzerReturnsAnalyzer() {
given().contentType("application/json").header("Authorization", AUTH)
.body("{\"analyzerName\":\"test-analyzer\",\"type\":\"ACCOUNT\"}")
.put("/analyzer").then().statusCode(200).body("arn", notNullValue());
given().header("Authorization", AUTH).get("/analyzer/test-analyzer")
.then().statusCode(200).body("analyzer.name", equalTo("test-analyzer"))
.body("analyzer.type", equalTo("ACCOUNT"))
.body("analyzer.status", equalTo("ACTIVE"))
.body("analyzer.arn", notNullValue());
given().header("Authorization", AUTH).delete("/analyzer/test-analyzer").then().statusCode(200);
}
@Test
void getAnalyzerNotFoundReturns404() {
given().header("Authorization", AUTH).get("/analyzer/nonexistent")
.then().statusCode(404)
.body("__type", equalTo("ResourceNotFoundException"))
.body("resourceId", equalTo("nonexistent"))
.body("resourceType", equalTo("analyzer"));
}
}