fix(account): implement DeleteAlternateContact (#5560)

* fix(account): implement DeleteAlternateContact

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

* docs(account): document DeleteAlternateContact

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-15 18:02:19 -04:00
1 parent ad8fba7f45
commit 9174147cb6
6 files changed
+51 -1

No files matched your search

+1
View File
@@ -13,6 +13,7 @@ Floci supports alternate-contact management over the AWS REST JSON protocol.
| --- | --- |
| `PutAlternateContact` | - |
| `GetAlternateContact` | - |
| `DeleteAlternateContact` | - |
<!-- floci:actions:end -->
Alternate contacts are isolated by caller account and stored 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 Metrics](cloudwatch.md#metrics) | `POST /` with `Action=` or JSON 1.1 | Query / JSON | 11 |
| [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 |
| [AWS Account Management](account.md) | `/putAlternateContact`, `/getAlternateContact`, `/deleteAlternateContact` | 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 |
@@ -47,6 +47,13 @@ public class AccountController {
return Response.ok(response).build();
}
@POST
@Path("/deleteAlternateContact")
public Response deleteAlternateContact(String body) {
accountService.deleteAlternateContact(requestContext.getAccountId(), readTree(body));
return Response.ok().build();
}
private JsonNode readTree(String body) {
try {
return objectMapper.reader()
@@ -56,6 +56,17 @@ public class AccountService implements Resettable {
"The alternate contact does not exist for the specified account and contact type.", 404));
}
public synchronized void deleteAlternateContact(String callerAccountId, JsonNode request) {
String targetAccountId = resolveTargetAccount(callerAccountId, request);
String type = requireContactType(request);
boolean exists = contacts.getForAccount(targetAccountId, type).isPresent();
if (!exists) {
throw new AwsException("ResourceNotFoundException",
"The alternate contact does not exist for the specified account and contact type.", 404);
}
contacts.deleteForAccount(targetAccountId, type);
}
private String resolveTargetAccount(String callerAccountId, JsonNode request) {
JsonNode accountIdNode = request == null ? null : request.get("AccountId");
if (accountIdNode == null || accountIdNode.isNull()) {
@@ -44,6 +44,18 @@ class AccountAlternateContactIntegrationTest {
.post("/getAlternateContact").then().statusCode(400).body("__type", equalTo("SerializationException"));
}
@Test
void putThenDeleteThenGetReturnsResourceNotFound() {
put("security@example.com").statusCode(200);
delete().statusCode(200).body(equalTo(""));
get().statusCode(404).body("__type", equalTo("ResourceNotFoundException"));
}
@Test
void deleteUnsetContactReturnsResourceNotFound() {
delete().statusCode(404).body("__type", equalTo("ResourceNotFoundException"));
}
private static io.restassured.response.ValidatableResponse put(String email) {
return given().contentType("application/json").header("Authorization", AUTH)
.body("{\"AlternateContactType\":\"SECURITY\",\"Name\":\"Security\",\"Title\":\"Owner\",\"EmailAddress\":\"" + email + "\",\"PhoneNumber\":\"+12025550123\"}")
@@ -55,4 +67,10 @@ class AccountAlternateContactIntegrationTest {
.body("{\"AlternateContactType\":\"SECURITY\"}")
.post("/getAlternateContact").then();
}
private static io.restassured.response.ValidatableResponse delete() {
return given().contentType("application/json").header("Authorization", AUTH)
.body("{\"AlternateContactType\":\"SECURITY\"}")
.post("/deleteAlternateContact").then();
}
}
@@ -64,6 +64,19 @@ class AccountServiceTest {
assertEquals("ResourceNotFoundException", error.getErrorCode());
}
@Test
void deleteRemovesContactAndDeletingUnsetThrows() {
ObjectNode request = contactRequest();
service.putAlternateContact(ACCOUNT_ID, request);
service.deleteAlternateContact(ACCOUNT_ID, request);
AwsException getError = assertThrows(AwsException.class,
() -> service.getAlternateContact(ACCOUNT_ID, request));
assertEquals("ResourceNotFoundException", getError.getErrorCode());
AwsException deleteError = assertThrows(AwsException.class,
() -> service.deleteAlternateContact(ACCOUNT_ID, request));
assertEquals("ResourceNotFoundException", deleteError.getErrorCode());
}
private ObjectNode contactRequest() {
ObjectNode request = mapper.createObjectNode();
request.put("AlternateContactType", "SECURITY");