diff --git a/docs/services/iam.md b/docs/services/iam.md
index 675b2f07ca..224bfa4f32 100644
--- a/docs/services/iam.md
+++ b/docs/services/iam.md
@@ -3526,8 +3526,8 @@ floci populates:
and endpoint groups, EMR Serverless for its applications, job runs and sessions, EMR on EKS for its virtual clusters,
job runs, managed endpoints, job templates and security configurations, Cost Explorer for its anomaly monitors and
subscriptions, Security Hub for its hubs and configuration policies, Control Tower for its landing zones and enabled
- controls, and GuardDuty for its detectors and Malware Protection plans. Tag keys differing only in case are one
- condition key holding every value.
+ controls, GuardDuty for its detectors and Malware Protection plans, and Cloud Map for its namespaces and services. Tag
+ keys differing only in case are one condition key holding every value.
- EC2 resource keys such as a network interface's `ec2:Vpc`, `ec2:Subnet`, `ec2:AvailabilityZone` and
`ec2:NetworkInterfaceID`: for every action on a resource EC2 holds, the members of the resource the
key names, an ARN for a key the Service Reference types as one. `resourceKeys` in
diff --git a/src/main/java/io/floci/aws/core/common/StoredResourceArns.java b/src/main/java/io/floci/aws/core/common/StoredResourceArns.java
index 0695d3981a..59f626fc28 100644
--- a/src/main/java/io/floci/aws/core/common/StoredResourceArns.java
+++ b/src/main/java/io/floci/aws/core/common/StoredResourceArns.java
@@ -55,10 +55,10 @@ import java.util.Optional;
* Serverless, for the tags of an application, a job run or a session; EMR on EKS, for the tags of a virtual cluster, a
* job run, a managed endpoint, a job template or a security configuration; Cost Explorer, for the tags of an anomaly
* monitor or subscription; Security Hub, for the tags of a hub or a configuration policy; Control Tower, for the tags
- * of a landing zone or an enabled control; GuardDuty, for the tags of a detector or a Malware Protection plan); looked
- * up lazily by {@code ResourceArnBuilder} and {@code IamConditionContextResolver} through
- * {@code Instance} for the namespace a request or an ARN is of, so IAM never depends on that
- * service directly.
+ * of a landing zone or an enabled control; GuardDuty, for the tags of a detector or a Malware Protection plan; Cloud
+ * Map, for the tags of a namespace or a service); looked up lazily by {@code ResourceArnBuilder} and
+ * {@code IamConditionContextResolver} through {@code Instance} for the namespace a request or an
+ * ARN is of, so IAM never depends on that service directly.
*
* Each answer is a lookup of what the service holds, asked for by an entry of the generated table ({@code find},
* {@code through}, a default, {@code forwarded}, a type's {@code resourceTagKeys}): never a fact about what an operation acts on, which the table alone
diff --git a/src/main/java/io/floci/aws/services/cloudmap/CloudMapService.java b/src/main/java/io/floci/aws/services/cloudmap/CloudMapService.java
index 1f50770e06..2091aba76a 100644
--- a/src/main/java/io/floci/aws/services/cloudmap/CloudMapService.java
+++ b/src/main/java/io/floci/aws/services/cloudmap/CloudMapService.java
@@ -14,6 +14,7 @@ import io.floci.aws.core.common.Digests;
import io.floci.aws.core.common.PaginatedResult;
import io.floci.aws.core.common.Pagination;
import io.floci.aws.core.common.RegionResolver;
+import io.floci.aws.core.common.StoredResourceArns;
import io.floci.aws.core.common.dns.DnsAnswer;
import io.floci.aws.core.common.dns.DnsRecord;
import io.floci.aws.core.storage.AccountAwareStorageBackend;
@@ -56,9 +57,12 @@ import java.util.function.Function;
* whose status reaches SUCCESS immediately (or after a configurable delay).
*/
@ApplicationScoped
-public class CloudMapService {
+public class CloudMapService implements StoredResourceArns {
private static final Logger LOG = Logger.getLogger(CloudMapService.class);
+ private static final String SERVICE = "servicediscovery";
+ private static final String NAMESPACE_RESOURCE = "namespace/";
+ private static final String SERVICE_RESOURCE = "service/";
private static final String ALNUM = "abcdefghijklmnopqrstuvwxyz0123456789";
/** Route 53 answers a service discovery query with at most eight records. */
private static final int MAX_DNS_ANSWERS = 8;
@@ -161,7 +165,7 @@ public class CloudMapService {
if (tags != null) {
ns.setTags(tags);
}
- ns.setArn(regionResolver.buildArn("servicediscovery", region, "namespace/" + ns.getId()));
+ ns.setArn(regionResolver.buildArn(SERVICE, region, NAMESPACE_RESOURCE + ns.getId()));
return ns;
}
@@ -259,7 +263,7 @@ public class CloudMapService {
if (tags != null) {
service.setTags(tags);
}
- service.setArn(regionResolver.buildArn("servicediscovery", region, "service/" + service.getId()));
+ service.setArn(regionResolver.buildArn(SERVICE, region, SERVICE_RESOURCE + service.getId()));
serviceStore.put(service.getId(), service);
if (nsId != null) {
namespaceStore.get(nsId).ifPresent(n -> {
@@ -860,28 +864,83 @@ public class CloudMapService {
return taggable(resourceArn).getTags();
}
- public void tagResource(String resourceArn, Map tags) {
+ /**
+ * Gives the namespace or the service a new map holding its tags and {@code tags}. Tag calls run one at a time, so
+ * two of them never lose one's tags, and a lookup reads one whole set.
+ */
+ public synchronized void tagResource(String resourceArn, Map tags) {
Object resource = taggableRaw(resourceArn);
if (resource instanceof Namespace ns) {
- ns.getTags().putAll(tags);
+ Map merged = new LinkedHashMap<>(ns.getTags());
+ merged.putAll(tags);
+ ns.setTags(merged);
namespaceStore.put(ns.getId(), ns);
} else if (resource instanceof Service s) {
- s.getTags().putAll(tags);
+ Map merged = new LinkedHashMap<>(s.getTags());
+ merged.putAll(tags);
+ s.setTags(merged);
serviceStore.put(s.getId(), s);
}
}
- public void untagResource(String resourceArn, List tagKeys) {
+ /** Gives the namespace or the service a new map without {@code tagKeys}, one tag call at a time. */
+ public synchronized void untagResource(String resourceArn, List tagKeys) {
Object resource = taggableRaw(resourceArn);
if (resource instanceof Namespace ns) {
- tagKeys.forEach(ns.getTags()::remove);
+ Map remaining = new LinkedHashMap<>(ns.getTags());
+ tagKeys.forEach(remaining::remove);
+ ns.setTags(remaining);
namespaceStore.put(ns.getId(), ns);
} else if (resource instanceof Service s) {
- tagKeys.forEach(s.getTags()::remove);
+ Map remaining = new LinkedHashMap<>(s.getTags());
+ tagKeys.forEach(remaining::remove);
+ s.setTags(remaining);
serviceStore.put(s.getId(), s);
}
}
+ @Override
+ public String namespace() {
+ return SERVICE;
+ }
+
+ /** A request names a namespace or a service by the id its ARN ends in: nothing to find. */
+ @Override
+ public Optional find(String type, List names, String region) {
+ return Optional.empty();
+ }
+
+ /**
+ * The tags of the namespace or the service whose ARN is {@code arn}, in the request's account, where the tag
+ * handlers read: an ARN of another account names none. Each is read in place by the id its ARN ends in, one stored
+ * before storage was account-aware included. That is the id the handlers find it by, in every Region, so an ARN
+ * naming another Region than the resource's reads its tags too, as a request sent there acts on it. A tag without
+ * a value reads as an empty one. Tag calls give the resource a new map, so the read is of one whole set.
+ */
+ @Override
+ public Map storedTags(String arn) {
+ if (!AwsArnUtils.isArnFor(arn, SERVICE)) {
+ return Map.of();
+ }
+ AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
+ String account = regionResolver.getAccountId();
+ if (!parsed.accountId().equals(account)) {
+ return Map.of();
+ }
+ String resource = parsed.resource();
+ Optional