mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(bcm-pricing-calculator): give resource-tag conditions the tags of the workload estimate a request names (#9112)
The generated request resources give Pricing Calculator's workload estimate type the aws:ResourceTag/ key, but no service answered the bcm- pricing-calculator namespace's stored tags, so a condition on an estimate's tags saw none. BcmPricingCalculatorService now answers it: a workload estimate records no ARN, so storedTags takes the ARN only when it is the one the estimate's account and id give in the request's partition, which has no Region, then reads the estimate by its id, in the request's account, in place. An estimate's tags are the ones it was created with, which nothing changes. The package now builds that ARN to compare, so partition/smoke-exemptions.tsv gets a row saying why it needs no partition smoke case.
This commit is contained in:
1 parent
3027145979
commit
30c37a129c
6 files changed
+138
-7
No files matched your search
@@ -63,9 +63,9 @@ import java.util.Optional;
|
||||
* for the tags of a cluster; EKS, for the tags of a cluster, a node group, a Fargate profile, an add-on, a Pod Identity
|
||||
* association or an access entry; Resource Groups, for the tags of a group; CloudWatch Logs, for a delivery, the
|
||||
* delivery destinations of a delivery source and the tags of a log group, a destination, a delivery source, a
|
||||
* delivery destination or a delivery); 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>
|
||||
* delivery destination or a delivery; Pricing Calculator, for the tags of a workload estimate); 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
|
||||
|
||||
+41
-1
@@ -4,9 +4,12 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.floci.aws.core.common.AwsArnUtils;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.common.StoredResourceArns;
|
||||
import io.floci.aws.core.common.UuidShapes;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.StorageBackend;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
import io.floci.aws.services.bcmpricingcalculator.model.WorkloadEstimate;
|
||||
@@ -22,11 +25,12 @@ import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ApplicationScoped
|
||||
public class BcmPricingCalculatorService {
|
||||
public class BcmPricingCalculatorService implements StoredResourceArns {
|
||||
private static final Pattern NAME = Pattern.compile("[a-zA-Z0-9-]+");
|
||||
private static final Pattern ACCOUNT = Pattern.compile("\\d{12}");
|
||||
private static final List<String> RATE_TYPES = List.of(
|
||||
@@ -37,6 +41,9 @@ public class BcmPricingCalculatorService {
|
||||
public record UsageError(String key, String errorCode, String errorMessage) {}
|
||||
public record UsageBatchResult(List<WorkloadEstimateUsage> items, List<UsageError> errors) {}
|
||||
|
||||
private static final String NAMESPACE = "bcm-pricing-calculator";
|
||||
private static final String WORKLOAD_ESTIMATE = "workload-estimate/";
|
||||
|
||||
private final StorageBackend<String, WorkloadEstimate> estimates;
|
||||
private final StorageBackend<String, WorkloadEstimateUsage> usages;
|
||||
private final RegionResolver regionResolver;
|
||||
@@ -102,6 +109,39 @@ public class BcmPricingCalculatorService {
|
||||
return estimate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String namespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
/** A request names a workload estimate by its id: nothing to find. */
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags of the workload estimate whose ARN is {@code arn}, in the request's account, where the handlers read: an
|
||||
* ARN of another account names none. A workload estimate records no ARN, so the ARN has to be the one its account
|
||||
* and id give in the request's partition, which has no Region; the estimate is read in place by its id, one stored
|
||||
* before storage was account-aware included. Its tags are the ones it was created with, which nothing changes.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> storedTags(String arn) {
|
||||
if (!AwsArnUtils.isArnFor(arn, NAMESPACE)) {
|
||||
return Map.of();
|
||||
}
|
||||
String account = regionResolver.getAccountId();
|
||||
String resource = AwsArnUtils.parse(arn).resource();
|
||||
if (!resource.startsWith(WORKLOAD_ESTIMATE)
|
||||
|| !arn.equals(regionResolver.buildGlobalArn(NAMESPACE, account, resource))) {
|
||||
return Map.of();
|
||||
}
|
||||
return new LinkedHashMap<>(AccountAwareStorageBackend
|
||||
.readInAccount(estimates, account, resource.substring(WORKLOAD_ESTIMATE.length()))
|
||||
.map(WorkloadEstimate::getTags).orElse(Map.of()));
|
||||
}
|
||||
|
||||
public WorkloadEstimate get(String id) {
|
||||
validateId(id);
|
||||
return estimates.get(id).orElseThrow(() -> notFound(id));
|
||||
|
||||
Reference in new issue
Block a user