mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(applicationautoscaling): give resource-tag conditions the tags of the target a request names (#8726)
The generated request resources give Application Auto Scaling's ScalableTarget type the aws:ResourceTag/ key, but its service answered no tags, so a condition on a scalable target's tags saw none. Its storedTags now reads the target whose ARN is the ARN, among the targets of the account and Region it names, a pre-multi-account one of the default account included, as the handlers find it. Tag changes already store a copy of the target under its lock; the tags field is now volatile.
This commit is contained in:
1 parent
151cb586f9
commit
65c6440b8f
6 files changed
+114
-8
No files matched your search
@@ -20,11 +20,11 @@ import java.util.Optional;
|
||||
* points at.
|
||||
*
|
||||
* <p>Implemented by the service that owns such resources or whose requests name them (EventBridge, for its
|
||||
* connections and API destinations; Application Auto Scaling, for its scalable targets; Redshift Data, for the
|
||||
* Redshift Serverless workgroups it runs statements on and the targets of its sessions; Payment Cryptography, for
|
||||
* 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,
|
||||
* connections and API destinations; Application Auto Scaling, for its scalable targets and their tags; Redshift
|
||||
* Data, for the Redshift Serverless workgroups it runs statements on and the targets of its sessions; Payment
|
||||
* Cryptography, for 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 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;
|
||||
|
||||
+38
@@ -1,6 +1,7 @@
|
||||
package io.floci.aws.services.applicationautoscaling;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.floci.aws.core.common.AwsArnUtils;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.PaginatedResult;
|
||||
import io.floci.aws.core.common.Pagination;
|
||||
@@ -38,6 +39,7 @@ import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -1004,6 +1006,42 @@ public class ApplicationAutoScalingService implements StoredResourceArns {
|
||||
return findTarget(region, names.get(0), names.get(1), names.get(2)).map(ScalableTarget::getScalableTargetArn);
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags held on the scalable target whose ARN is {@code arn}, read in place where its handlers find it: among
|
||||
* the targets of the account and Region the ARN names, a pre-multi-account one of the default account included,
|
||||
* matched on the whole ARN. Tagging stores a copy of the target, so the read is of one whole set. Empty for an ARN
|
||||
* naming no target.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> storedTags(String arn) {
|
||||
if (!AwsArnUtils.isArnFor(arn, "application-autoscaling")) {
|
||||
return Map.of();
|
||||
}
|
||||
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
|
||||
String account = parsed.accountId();
|
||||
if (account.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
String prefix = parsed.region() + "::";
|
||||
List<ScalableTarget> held;
|
||||
if (targets instanceof AccountAwareStorageBackend<ScalableTarget> aware) {
|
||||
String scoped = AccountAwareStorageBackend.rawKey(account, prefix);
|
||||
boolean legacyToo = account.equals(aware.defaultAccountId());
|
||||
held = aware.scanRaw(key -> key.startsWith(scoped)
|
||||
|| (legacyToo && !AccountAwareStorageBackend.hasAccountPrefix(key) && key.startsWith(prefix)));
|
||||
} else {
|
||||
held = targets.scan(key -> key.startsWith(prefix));
|
||||
}
|
||||
Map<String, String> tags = new LinkedHashMap<>();
|
||||
held.stream().filter(target -> arn.equals(target.getScalableTargetArn())).findFirst()
|
||||
.ifPresent(target -> target.getTags().forEach((key, value) -> {
|
||||
if (key != null && value != null) {
|
||||
tags.put(key, value);
|
||||
}
|
||||
}));
|
||||
return tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looked up by {@link ScalingPolicyAlarmActionHandler} when an alarm's AlarmActions references
|
||||
* a scaling-policy ARN, and by the CloudFormation provisioner, whose physical id for a policy
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ public class ScalableTarget {
|
||||
private String scalableTargetArn;
|
||||
private double creationTime;
|
||||
private SuspendedState suspendedState = new SuspendedState();
|
||||
private Map<String, String> tags = new HashMap<>();
|
||||
private volatile Map<String, String> tags = new HashMap<>();
|
||||
|
||||
public ScalableTarget() {}
|
||||
|
||||
|
||||
Reference in new issue
Block a user