mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(resourceexplorer2): give resource-tag conditions the tags of the resource a request names (#8719)
The generated request resources give Resource Explorer's index and view types the aws:ResourceTag/ key, but ResourceExplorer2Service answered no tags, so a condition on an index's or a view's tags saw none. Its storedTags now reads the index or view stored under the ARN in the account it names, in place, matched on the whole ARN both are kept by; each is an immutable record that tagging replaces. Tag changes now take the service's lock, so two on one resource keep each other's tags.
This commit is contained in:
1 parent
6c18ec745e
commit
7ed62b2597
5 files changed
+79
-5
No files matched your search
@@ -25,9 +25,9 @@ import java.util.Optional;
|
||||
* the key an alias names and the tags of a key; EMR, for the clusters of its instance groups and a tag call's
|
||||
* resource and the tags of a cluster; IAM Identity Center, for the accounts its permission sets are provisioned to
|
||||
* and the tags of an instance,
|
||||
* a permission set, an application or a trusted token issuer; Resource Explorer, for its default view; OAM and RAM,
|
||||
* for the sinks, invitations and shares of other accounts they act on, OAM for the tags of a sink or a link, and
|
||||
* RAM for the tags of a resource share;
|
||||
* a permission set, an application or a trusted token issuer; Resource Explorer, for its default view and the tags
|
||||
* of an index or a view; OAM and RAM, for the sinks, invitations and shares of other accounts they act on, OAM for
|
||||
* the tags of a sink or a link, and RAM for the tags of a resource share;
|
||||
* Secrets Manager, for the secret a name or an ARN names, random suffix included, and its tags; EventBridge
|
||||
* Scheduler, for its default schedule group and its groups' tags;
|
||||
* CloudFormation, for the stack or the stack set a name names, whose id it minted, and the tags of a stack, a stack set
|
||||
|
||||
+32
-1
@@ -11,6 +11,7 @@ import io.floci.aws.core.common.StoredResourceArns;
|
||||
import io.floci.aws.core.resource.ExplorerResource;
|
||||
import io.floci.aws.core.resource.ResourceProvider;
|
||||
import io.floci.aws.core.resource.SupportedResourceType;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.InMemoryStorage;
|
||||
import io.floci.aws.core.storage.StorageBackend;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
@@ -494,6 +495,35 @@ public class ResourceExplorer2Service implements StoredResourceArns {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags held on the index or view stored under {@code arn}, in the account it names, read in place: both are
|
||||
* kept by their whole ARN, so the ARN is matched whole, and each is an immutable record that tagging replaces.
|
||||
* Empty for an ARN naming neither.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> storedTags(String arn) {
|
||||
if (!AwsArnUtils.isArnFor(arn, "resource-explorer-2")) {
|
||||
return Map.of();
|
||||
}
|
||||
String account = AwsArnUtils.parse(arn).accountId();
|
||||
if (account.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
Map<String, String> tags = AccountAwareStorageBackend.readInAccount(indexStore, account, arn)
|
||||
.map(Taggable::tags)
|
||||
.or(() -> AccountAwareStorageBackend.readInAccount(viewStore, account, arn).map(Taggable::tags))
|
||||
.orElse(null);
|
||||
Map<String, String> held = new LinkedHashMap<>();
|
||||
if (tags != null) {
|
||||
tags.forEach((key, value) -> {
|
||||
if (key != null && value != null) {
|
||||
held.put(key, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
return held;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Region's default view, which {@code Search} and {@code ListResources} use for a request naming no view, read
|
||||
* without writing anything, since IAM asks before it decides: the one stored, or, where such a request first
|
||||
@@ -1014,7 +1044,8 @@ public class ResourceExplorer2Service implements StoredResourceArns {
|
||||
mutateTags(arn, current -> tagKeys.forEach(current::remove));
|
||||
}
|
||||
|
||||
private void mutateTags(String arn, Consumer<Map<String, String>> mutation) {
|
||||
/** One tag change at a time, so two on one resource each keep the other's tags. */
|
||||
private synchronized void mutateTags(String arn, Consumer<Map<String, String>> mutation) {
|
||||
StoredTaggable stored = resolveTaggable(arn);
|
||||
Map<String, String> updated = stored.entity().tags() != null
|
||||
? new HashMap<>(stored.entity().tags()) : new HashMap<>();
|
||||
|
||||
Reference in new issue
Block a user