mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(ses): support tag operations on tenant ARNs (#2832)
* feat(ses): support tag operations on tenant ARNs * fix(ses): shield the stored tenant record from tag-callback mutation * test(ses): cover the cross-region guard for tenant TagResource/UntagResource * docs(ses): drop em dashes from the tenant tag additions
This commit is contained in:
1 parent
eb0472fccc
commit
812911fd03
7 files changed
+362
-2
No files matched your search
@@ -1988,6 +1988,7 @@ public class SesService {
|
||||
case "contact-list" -> contactService.listTags(ref.name(), region);
|
||||
case "custom-verification-email-template" -> cvetService.listTags(ref.name(), region);
|
||||
case "dedicated-ip-pool" -> dedicatedIpService.listTags(ref.name(), region);
|
||||
case "tenant" -> listTenantTags(ref.name(), region);
|
||||
default -> throw new AwsException("NotFoundException",
|
||||
"Resource " + arn + " was not found.", 404);
|
||||
};
|
||||
@@ -2018,6 +2019,7 @@ public class SesService {
|
||||
case "contact-list" -> contactService.tag(ref.name(), region, tags);
|
||||
case "custom-verification-email-template" -> cvetService.tag(ref.name(), region, tags);
|
||||
case "dedicated-ip-pool" -> dedicatedIpService.tag(ref.name(), region, tags);
|
||||
case "tenant" -> tagTenant(ref.name(), region, tags);
|
||||
default -> throw new AwsException("NotFoundException",
|
||||
"Resource " + arn + " was not found.", 404);
|
||||
}
|
||||
@@ -2044,11 +2046,41 @@ public class SesService {
|
||||
case "contact-list" -> contactService.untag(ref.name(), region, tagKeys);
|
||||
case "custom-verification-email-template" -> cvetService.untag(ref.name(), region, tagKeys);
|
||||
case "dedicated-ip-pool" -> dedicatedIpService.untag(ref.name(), region, tagKeys);
|
||||
case "tenant" -> untagTenant(ref.name(), region, tagKeys);
|
||||
default -> throw new AwsException("NotFoundException",
|
||||
"Resource " + arn + " was not found.", 404);
|
||||
}
|
||||
}
|
||||
|
||||
// A tenant tag ARN carries two path segments (tenant/<name>/<tenantId>), so parseSesArn's
|
||||
// first-slash split leaves "<name>/<tenantId>" as the resource name; the tenant domain owns
|
||||
// that remainder's decomposition and the id-only resolution (see SesTenantService.TenantTagArn).
|
||||
|
||||
private List<Tag> listTenantTags(String resourceName, String region) {
|
||||
Tenant tenant = tenantService.tenantForTagArn(resourceName, region);
|
||||
// AWS returns a tenant's tags ordered by key (probe-confirmed).
|
||||
return (tenant.tags() == null ? List.<Tag>of() : tenant.tags()).stream()
|
||||
.sorted(Comparator.comparing(Tag::key, Comparator.nullsLast(Comparator.naturalOrder())))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private void tagTenant(String resourceName, String region, List<Tag> newTags) {
|
||||
tenantService.mutateTags(resourceName, region, tags -> SesTags.merge(tags, newTags));
|
||||
LOG.infov("Tagged SES tenant <{0}> (region {1}, +{2} tags)",
|
||||
resourceName, region, newTags.size());
|
||||
}
|
||||
|
||||
private void untagTenant(String resourceName, String region, List<String> tagKeys) {
|
||||
Set<String> toRemove = new HashSet<>(tagKeys);
|
||||
tenantService.mutateTags(resourceName, region, tags -> {
|
||||
List<Tag> remaining = new ArrayList<>(tags);
|
||||
remaining.removeIf(t -> toRemove.contains(t.key()));
|
||||
return remaining;
|
||||
});
|
||||
LOG.infov("Untagged SES tenant <{0}> (region {1}, -{2} keys)",
|
||||
resourceName, region, tagKeys.size());
|
||||
}
|
||||
|
||||
private List<Tag> listConfigurationSetTags(String name, String region) {
|
||||
ConfigurationSet cs = configSetService.find(name, region)
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
@@ -175,6 +176,64 @@ public class SesTenantService {
|
||||
return tenantStore.get(tenantKey(region, tenantName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a tenant by its TenantId, for the ARN-dispatched tag operations: AWS resolves a
|
||||
* tenant tag ARN by the id segment alone; the name segment is not matched (probe-confirmed).
|
||||
*/
|
||||
public Optional<Tenant> findByTenantId(String tenantId, String region) {
|
||||
String prefix = tenantKeyPrefix(region);
|
||||
return tenantStore.scan(k -> k.startsWith(prefix)).stream()
|
||||
.filter(t -> tenantId != null && tenantId.equals(t.tenantId()))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* The name/id decomposition of a tenant tag ARN's resource remainder ({@code <name>/<tenantId>}
|
||||
* after the generic dispatch split off the {@code tenant/} type segment). AWS parses a remainder
|
||||
* without a slash as a null name with the whole segment as the id, and resolves by the id alone
|
||||
* (probe-confirmed): tenant-domain knowledge, so it lives here, not in the tag dispatch.
|
||||
*/
|
||||
record TenantTagArn(String name, String tenantId) {
|
||||
static TenantTagArn parse(String resourceRemainder) {
|
||||
int slash = resourceRemainder.indexOf('/');
|
||||
return new TenantTagArn(slash < 0 ? null : resourceRemainder.substring(0, slash),
|
||||
slash < 0 ? resourceRemainder : resourceRemainder.substring(slash + 1));
|
||||
}
|
||||
}
|
||||
|
||||
/** Resolves a tenant from a tag ARN's resource remainder, for the facade's tag listing. */
|
||||
public Tenant tenantForTagArn(String resourceRemainder, String region) {
|
||||
TenantTagArn arn = TenantTagArn.parse(resourceRemainder);
|
||||
return findByTenantId(arn.tenantId(), region)
|
||||
.orElseThrow(() -> tagArnTenantNotFound(arn));
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a tag mutation for the facade's ARN-dispatched tagging. The tenant is re-resolved by
|
||||
* TenantId and mutated INSIDE the shared lock, so concurrent tag calls can't lose each other's
|
||||
* merges, a concurrent suppression-attribute update isn't overwritten by a stale copy, and a
|
||||
* delete/recreate between the caller's lookup and this write can't resurrect the old record.
|
||||
*/
|
||||
public void mutateTags(String resourceRemainder, String region, UnaryOperator<List<Tag>> mutation) {
|
||||
TenantTagArn arn = TenantTagArn.parse(resourceRemainder);
|
||||
synchronized (tenantMutationLock) {
|
||||
Tenant current = findByTenantId(arn.tenantId(), region)
|
||||
.orElseThrow(() -> tagArnTenantNotFound(arn));
|
||||
// The record's list may be a mutable one (Jackson-built); hand the callback an immutable
|
||||
// copy so an in-place mutation can't reach the stored record, and store an immutable copy
|
||||
// so the persisted list can't be aliased either.
|
||||
List<Tag> tags = current.tags() == null ? List.of() : List.copyOf(current.tags());
|
||||
tenantStore.put(tenantKey(region, current.tenantName()),
|
||||
current.withTags(List.copyOf(mutation.apply(tags))));
|
||||
}
|
||||
}
|
||||
|
||||
/** The tag-dispatch not-found error: the missing space before "with" is AWS's own. */
|
||||
private static AwsException tagArnTenantNotFound(TenantTagArn arn) {
|
||||
return new AwsException("NotFoundException",
|
||||
"No Tenant present with name: " + arn.name() + "with tenantId: " + arn.tenantId(), 404);
|
||||
}
|
||||
|
||||
// ──────────────────────── Resource associations (Phase 2) ────────────────────────
|
||||
// Behavior and messages probe-confirmed against real AWS us-east-1, 2026-08-28.
|
||||
|
||||
|
||||
@@ -19,6 +19,12 @@ public record Tenant(String tenantName,
|
||||
String sendingStatus,
|
||||
TenantSuppressionAttributes suppressionAttributes) {
|
||||
|
||||
/** Copy with different tags (records are immutable; the store is replace-only). */
|
||||
public Tenant withTags(List<Tag> newTags) {
|
||||
return new Tenant(tenantName, tenantId, tenantArn, createdTimestamp, newTags, sendingStatus,
|
||||
suppressionAttributes);
|
||||
}
|
||||
|
||||
/** Copy with different suppression attributes (records are immutable; the store is replace-only). */
|
||||
public Tenant withSuppressionAttributes(TenantSuppressionAttributes attrs) {
|
||||
return new Tenant(tenantName, tenantId, tenantArn, createdTimestamp, tags, sendingStatus, attrs);
|
||||
|
||||
Reference in new issue
Block a user