feat(paymentcryptography): the Multi-Party Approval team of an operation (#8812)

* feat(paymentcryptography): the Multi-Party Approval team of an operation
* docs(paymentcryptography): what the Multi-Party Approval does not make
* docs(paymentcryptography): the action table in the order the handler names
* style(paymentcryptography): the multi-region work comes with the branch
* fix(paymentcryptography): the tests of the team share the operation they name
* fix(paymentcryptography): the removal does not change what a lookup holds
This commit is contained in:
Murtuza Chhil authored and GitHub committed 2026-11-17 22:52:57 -04:00
1 parent 118ec83730
commit e6f4758bc1
9 files changed
+424 -34

No files matched your search

@@ -10,6 +10,7 @@ import io.floci.aws.core.common.Pagination;
import io.floci.aws.services.iam.PolicyDocument;
import io.floci.aws.services.paymentcryptography.model.PaymentCryptographyAlias;
import io.floci.aws.services.paymentcryptography.model.PaymentCryptographyKey;
import io.floci.aws.services.paymentcryptography.model.PaymentCryptographyMpaTeamAssociation;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.core.Response;
@@ -89,6 +90,9 @@ public class PaymentCryptographyJsonHandler {
case "PutResourcePolicy" -> () -> putResourcePolicy(request, region);
case "GetResourcePolicy" -> () -> getResourcePolicy(request, region);
case "DeleteResourcePolicy" -> () -> deleteResourcePolicy(request, region);
case "AssociateMpaTeam" -> () -> associateMpaTeam(request, region);
case "GetMpaTeamAssociation" -> () -> getMpaTeamAssociation(request, region);
case "DisassociateMpaTeam" -> () -> disassociateMpaTeam(request, region);
default -> throw new AwsException("UnknownOperationException",
"Operation " + action + " is not supported by floci", 400);
};
@@ -483,6 +487,47 @@ public class PaymentCryptographyJsonHandler {
return true;
}
// ---- multi-party approval ------------------------------------------------
/**
* Associates a Multi-Party Approval team with a protected operation.
*
* <p>An operation has one team, so a second association replaces the first, as the
* reference replaces one.
*/
private Map<String, Object> associateMpaTeam(JsonNode request, String region) {
PaymentCryptographyMpaTeamAssociation association = service.associateMpaTeam(region,
request.path("Action").asText(), request.path("MpaTeamArn").asText());
return Map.of("MpaTeamAssociation", mpaAssociation(association));
}
/** The Multi-Party Approval team associated with a protected operation. */
private Map<String, Object> getMpaTeamAssociation(JsonNode request, String region) {
PaymentCryptographyMpaTeamAssociation association =
service.mpaTeamAssociation(region, request.path("Action").asText());
return Map.of("MpaTeamAssociation", mpaAssociation(association));
}
/**
* Removes the Multi-Party Approval team associated with a protected operation.
*
* <p>The answer carries the association as it was, its state now {@code DELETE_PENDING}.
*/
private Map<String, Object> disassociateMpaTeam(JsonNode request, String region) {
PaymentCryptographyMpaTeamAssociation association =
service.disassociateMpaTeam(region, request.path("Action").asText());
return Map.of("MpaTeamAssociation", mpaAssociation(association));
}
/** The association, as the model names its members. */
private static Map<String, Object> mpaAssociation(PaymentCryptographyMpaTeamAssociation association) {
Map<String, Object> out = new LinkedHashMap<>();
out.put("Action", association.getAction());
out.put("MpaTeamArn", association.getMpaTeamArn());
out.put("AssociationState", association.getAssociationState());
return out;
}
/** The tags of a request, as the name and the value of each. */
private static Map<String, String> tagsOf(JsonNode request) {
Map<String, String> tags = new LinkedHashMap<>();
@@ -16,6 +16,7 @@ import io.floci.aws.services.acm.CertificateGenerator;
import io.floci.aws.services.paymentcryptography.crypto.DukptCrypto;
import io.floci.aws.services.paymentcryptography.model.PaymentCryptographyAlias;
import io.floci.aws.services.paymentcryptography.model.PaymentCryptographyKey;
import io.floci.aws.services.paymentcryptography.model.PaymentCryptographyMpaTeamAssociation;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
@@ -84,6 +85,7 @@ public class PaymentCryptographyService implements Resettable, StoredResourceArn
private final StorageBackend<String, PaymentCryptographyKey> keyStore;
private final StorageBackend<String, PaymentCryptographyAlias> aliasStore;
private final StorageBackend<String, PaymentCryptographyMpaTeamAssociation> mpaTeamStore;
/** The key exchange: the forms a key may leave in, and the certificates that carry them. */
private final PaymentCryptographyKeyExchange exchange;
@@ -104,6 +106,8 @@ public class PaymentCryptographyService implements Resettable, StoredResourceArn
new TypeReference<>() {}),
storageFactory.create(STORAGE_KEY, "payment-cryptography-settings.json",
new TypeReference<Map<String, List<String>>>() {}),
storageFactory.create(STORAGE_KEY, "payment-cryptography-mpa-teams.json",
new TypeReference<>() {}),
regionResolver,
new SecureRandom(),
requestContext,
@@ -115,8 +119,8 @@ public class PaymentCryptographyService implements Resettable, StoredResourceArn
StorageBackend<String, PaymentCryptographyAlias> aliasStore,
RegionResolver regionResolver,
PaymentCryptographyRequestContext requestContext) {
this(keyStore, aliasStore, new InMemoryStorage<>(), regionResolver, new SecureRandom(),
requestContext, new CertificateGenerator(), Clock.systemUTC());
this(keyStore, aliasStore, new InMemoryStorage<>(), new InMemoryStorage<>(), regionResolver,
new SecureRandom(), requestContext, new CertificateGenerator(), Clock.systemUTC());
}
/**
@@ -128,8 +132,9 @@ public class PaymentCryptographyService implements Resettable, StoredResourceArn
PaymentCryptographyService(StorageBackend<String, PaymentCryptographyKey> keyStore,
StorageBackend<String, PaymentCryptographyAlias> aliasStore,
RegionResolver regionResolver) {
this(keyStore, aliasStore, new InMemoryStorage<>(), regionResolver, new SecureRandom(),
new PaymentCryptographyRequestContext(), new CertificateGenerator(), Clock.systemUTC());
this(keyStore, aliasStore, new InMemoryStorage<>(), new InMemoryStorage<>(), regionResolver,
new SecureRandom(), new PaymentCryptographyRequestContext(),
new CertificateGenerator(), Clock.systemUTC());
}
PaymentCryptographyService(StorageBackend<String, PaymentCryptographyKey> keyStore,
@@ -137,8 +142,8 @@ public class PaymentCryptographyService implements Resettable, StoredResourceArn
RegionResolver regionResolver,
SecureRandom secureRandom,
PaymentCryptographyRequestContext requestContext) {
this(keyStore, aliasStore, new InMemoryStorage<>(), regionResolver, secureRandom,
requestContext, new CertificateGenerator(), Clock.systemUTC());
this(keyStore, aliasStore, new InMemoryStorage<>(), new InMemoryStorage<>(), regionResolver,
secureRandom, requestContext, new CertificateGenerator(), Clock.systemUTC());
}
PaymentCryptographyService(StorageBackend<String, PaymentCryptographyKey> keyStore,
@@ -148,13 +153,14 @@ public class PaymentCryptographyService implements Resettable, StoredResourceArn
PaymentCryptographyRequestContext requestContext,
CertificateGenerator certificates,
Clock clock) {
this(keyStore, aliasStore, new InMemoryStorage<>(), regionResolver, secureRandom,
requestContext, certificates, clock);
this(keyStore, aliasStore, new InMemoryStorage<>(), new InMemoryStorage<>(), regionResolver,
secureRandom, requestContext, certificates, clock);
}
PaymentCryptographyService(StorageBackend<String, PaymentCryptographyKey> keyStore,
StorageBackend<String, PaymentCryptographyAlias> aliasStore,
StorageBackend<String, List<String>> settingsStore,
StorageBackend<String, PaymentCryptographyMpaTeamAssociation> mpaTeamStore,
RegionResolver regionResolver,
SecureRandom secureRandom,
PaymentCryptographyRequestContext requestContext,
@@ -163,6 +169,7 @@ public class PaymentCryptographyService implements Resettable, StoredResourceArn
this.keyStore = keyStore;
this.aliasStore = aliasStore;
this.settingsStore = settingsStore;
this.mpaTeamStore = mpaTeamStore;
this.regionResolver = regionResolver;
this.exchange = new PaymentCryptographyKeyExchange(this, certificates, clock);
this.secureRandom = secureRandom;
@@ -837,6 +844,78 @@ public class PaymentCryptographyService implements Resettable, StoredResourceArn
return current;
}
// ---- multi-party approval ------------------------------------------------
/**
* Associates a Multi-Party Approval team with a protected operation.
*
* <p>An operation has one association, so a second one replaces the first. The team's
* ARN is stored as the request names it: there is no MPA service here to check it
* against, and an ARN the model accepts names a team the emulator cannot see.
*
* <p>The store holds the association, and the caller gets a copy of it, so what the
* caller holds is a snapshot that a later change of the stored association does not
* reach.
*/
public synchronized PaymentCryptographyMpaTeamAssociation associateMpaTeam(
String region, String action, String mpaTeamArn) {
PaymentCryptographyMpaTeamAssociation association =
new PaymentCryptographyMpaTeamAssociation(action, region, mpaTeamArn, "ACTIVE");
mpaTeamStore.put(storageKey(region, action), association);
return copyOf(association);
}
/**
* The MPA team associated with a protected operation.
*
* <p>The store holds the association and the object it holds is mutable, so the read
* takes a copy of it while it holds the lock: what the caller holds is a snapshot, and
* a removal that runs after the read does not change it.
*/
public synchronized PaymentCryptographyMpaTeamAssociation mpaTeamAssociation(
String region, String action) {
PaymentCryptographyMpaTeamAssociation association =
mpaTeamStore.get(storageKey(region, action)).orElse(null);
if (association == null) {
throw new AwsException("ResourceNotFoundException",
"No MPA team is associated with " + action, 400);
}
return copyOf(association);
}
/**
* Removes the association between an MPA team and a protected operation.
*
* <p>The answer carries the association as it was, its state now {@code DELETE_PENDING},
* and the association is gone from the store. The state belongs to that answer alone:
* the stored association is not changed, so a lookup that overlaps the removal answers
* with the association that is there or with the resource the reference cannot find.
*/
public synchronized PaymentCryptographyMpaTeamAssociation disassociateMpaTeam(
String region, String action) {
PaymentCryptographyMpaTeamAssociation association = mpaTeamAssociation(region, action);
mpaTeamStore.delete(storageKey(region, action));
return new PaymentCryptographyMpaTeamAssociation(association.getAction(),
association.getRegion(), association.getMpaTeamArn(), "DELETE_PENDING");
}
/**
* A copy of an association.
*
* <p>The store holds the association and the object it holds is mutable, so what a
* caller gets is a copy: what the caller holds is a snapshot, and a change of the
* stored association does not reach it.
*
* @param association the association to copy
* @return the copy
*/
private static PaymentCryptographyMpaTeamAssociation copyOf(
PaymentCryptographyMpaTeamAssociation association) {
return new PaymentCryptographyMpaTeamAssociation(association.getAction(),
association.getRegion(), association.getMpaTeamArn(),
association.getAssociationState());
}
// ---- the key exchange ----------------------------------------------------
/**
@@ -1416,6 +1495,7 @@ public class PaymentCryptographyService implements Resettable, StoredResourceArn
keyStore.clear();
settingsStore.clear();
aliasStore.clear();
mpaTeamStore.clear();
}
/** The key store, for the tests. */
@@ -0,0 +1,46 @@
package io.floci.aws.services.paymentcryptography.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.quarkus.runtime.annotations.RegisterForReflection;
/**
* A Multi-Party Approval team associated with a protected operation.
*
* <p>The association is the account's, one per protected operation: a second association
* of the same operation replaces the first. The emulator keeps the team's ARN but has no
* MPA service to check it against, so an ARN the model accepts is stored as it came.
*/
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
public class PaymentCryptographyMpaTeamAssociation {
private String action;
private String region;
private String mpaTeamArn;
private String associationState = "ACTIVE";
public PaymentCryptographyMpaTeamAssociation() {
}
public PaymentCryptographyMpaTeamAssociation(String action, String region, String mpaTeamArn,
String associationState) {
this.action = action;
this.region = region;
this.mpaTeamArn = mpaTeamArn;
this.associationState = associationState;
}
public String getAction() { return action; }
public void setAction(String action) { this.action = action; }
public String getRegion() { return region; }
public void setRegion(String region) { this.region = region; }
public String getMpaTeamArn() { return mpaTeamArn; }
public void setMpaTeamArn(String mpaTeamArn) { this.mpaTeamArn = mpaTeamArn; }
public String getAssociationState() { return associationState; }
public void setAssociationState(String associationState) {
this.associationState = associationState;
}
}