mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(redshift-serverless): give resource-tag conditions the tags of the namespace, workgroup or snapshot a request names (#8615)
The generated request resources give Redshift Serverless's namespace, workgroup, snapshot and recovery point types aws:ResourceTag/ keys, but RedshiftServerlessService did not answer storedTags, so a condition on their tags saw none. It now reads the namespace, the workgroup or the snapshot stored under the ARN in the account and Region it names, a pre-multi-account one of the default account included, in place, matched on the whole ARN. A tag change is already stored on a copy, so the tags read are one whole set.
This commit is contained in:
1 parent
d8460bc305
commit
a5064a2f5a
5 files changed
+126
-5
No files matched your search
@@ -33,9 +33,10 @@ import java.util.Optional;
|
||||
* network connector; Glue, for the tags of a resource it tags; Step Functions, for the tags of a state machine, its
|
||||
* versions and executions, and an activity; CodeBuild, for the project a build belongs to and the tags of a project or
|
||||
* a report group; Athena, for the workgroup and the data catalog a request naming none uses and the tags of a
|
||||
* workgroup or a data catalog); looked up lazily by {@code ResourceArnBuilder} and
|
||||
* {@code IamConditionContextResolver} through {@code Instance<StoredResourceArns>} for the namespace a request or an
|
||||
* ARN is of, so IAM never depends on that service directly.</p>
|
||||
* workgroup or a data catalog; Redshift Serverless, for the tags of a namespace, a workgroup or a snapshot); looked up
|
||||
* lazily by {@code ResourceArnBuilder} and {@code IamConditionContextResolver} through
|
||||
* {@code Instance<StoredResourceArns>} for the namespace a request or an ARN is of, so IAM never depends on that
|
||||
* service directly.</p>
|
||||
*
|
||||
* <p>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
|
||||
|
||||
@@ -51,6 +51,7 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.function.UnaryOperator;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -1093,6 +1094,48 @@ public class RedshiftServerlessService implements Resettable, StoredResourceArns
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags of the namespace, the workgroup or the snapshot stored under {@code arn} in the account and Region it
|
||||
* names, a pre-multi-account one of the default account included, read in place and matched on the whole ARN;
|
||||
* empty for an ARN naming nothing stored. A tag change is stored on a copy, so the tags read are one whole set.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> storedTags(String arn) {
|
||||
if (!AwsArnUtils.isArnFor(arn, "redshift-serverless")) {
|
||||
return Map.of();
|
||||
}
|
||||
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
|
||||
String account = parsed.accountId();
|
||||
String region = parsed.region();
|
||||
Map<String, String> tags = tagsIn(namespaces, account, region, arn, Namespace::getNamespaceArn,
|
||||
Namespace::getTags)
|
||||
.or(() -> tagsIn(workgroups, account, region, arn, Workgroup::getWorkgroupArn, Workgroup::getTags))
|
||||
.or(() -> tagsIn(snapshots, account, region, arn, RedshiftServerlessSnapshot::getSnapshotArn,
|
||||
RedshiftServerlessSnapshot::getTags))
|
||||
.orElse(Map.of());
|
||||
Map<String, String> copy = new LinkedHashMap<>();
|
||||
tags.forEach((key, value) -> {
|
||||
if (value != null) {
|
||||
copy.put(key, value);
|
||||
}
|
||||
});
|
||||
return copy;
|
||||
}
|
||||
|
||||
private static <V> Optional<Map<String, String>> tagsIn(AccountAwareStorageBackend<V> store, String account,
|
||||
String region, String arn, Function<V, String> arnOf,
|
||||
Function<V, Map<String, String>> tagsOf) {
|
||||
List<V> held = new ArrayList<>(store.scanForAccount(account, key -> key.startsWith(region + "::")));
|
||||
if (account.equals(store.defaultAccountId())) {
|
||||
held.addAll(store.scanUnscopedLegacy(stored -> arn.equals(arnOf.apply(stored))));
|
||||
}
|
||||
return held.stream()
|
||||
.filter(stored -> arn.equals(arnOf.apply(stored)))
|
||||
.map(tagsOf)
|
||||
.filter(Objects::nonNull)
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
/** The snapshot {@code snapshotName} of {@code accountId} in {@code region}, whoever is calling. */
|
||||
public Optional<RedshiftServerlessSnapshot> findSnapshotOfAccount(String accountId, String snapshotName,
|
||||
String region) {
|
||||
|
||||
Reference in new issue
Block a user