mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudfront): give resource-tag conditions the tags of the resource a request names (#8700)
The generated request resources give ten CloudFront types the aws:ResourceTag/ key, but CloudFrontKeyValueStoreService, the namespace's StoredResourceArns, answered no tags, so a condition on a CloudFront resource's tags saw none. It now reads the tags CloudFront holds under the ARN, in place, from the tag store CloudFrontService writes, where the tag handlers keep them: in the request's account, by the whole ARN, since CloudFront ARNs name the default account whichever account owns the resource. DeleteFunction now removes the tags kept under the function's ARN, its name, and CreateFunction drops any left there, so a function created again under a deleted one's name starts with none. CloudFront's tag writes already put a new map in place of the held one.
This commit is contained in:
1 parent
bcf5e58886
commit
15519216c3
7 files changed
+156
-20
No files matched your search
@@ -38,9 +38,10 @@ import java.util.Optional;
|
||||
* for the tags of a table and its indexes; ECR, for the tags of a repository; Redshift, for the key a snapshot records
|
||||
* and the tags of a cluster, a snapshot, a parameter group, a subnet group, a snapshot copy grant, a snapshot
|
||||
* schedule, an event subscription or an integration; SSM, for the parameter a legacy ARN names, the document of
|
||||
* another account an association runs and the tags of a parameter, a document or an association); 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>
|
||||
* another account an association runs and the tags of a parameter, a document or an association; CloudFront, for the
|
||||
* key value store a name names and the tags of any resource it tags); 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
|
||||
|
||||
@@ -985,7 +985,7 @@ public class CloudFrontController {
|
||||
appendKeyValueStoreAssociations(xml, fn);
|
||||
xml.end("FunctionConfig")
|
||||
.start("FunctionMetadata")
|
||||
.elem("FunctionARN", service.arn("function/" + fn.getName()))
|
||||
.elem("FunctionARN", service.functionArn(fn.getName()))
|
||||
.elem("Stage", fn.getStage())
|
||||
.elem("CreatedTime", fn.getCreatedTime() != null ? fn.getCreatedTime().toString() : "")
|
||||
.elem("LastModifiedTime",
|
||||
@@ -2533,7 +2533,7 @@ public class CloudFrontController {
|
||||
appendKeyValueStoreAssociations(xml, fn);
|
||||
return xml.end("FunctionConfig")
|
||||
.start("FunctionMetadata")
|
||||
.elem("FunctionARN", service.arn("function/" + fn.getName()))
|
||||
.elem("FunctionARN", service.functionArn(fn.getName()))
|
||||
.elem("Stage", fn.getStage())
|
||||
.elem("CreatedTime", fn.getCreatedTime() != null ? fn.getCreatedTime().toString() : "")
|
||||
.elem("LastModifiedTime",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.floci.aws.services.cloudfront;
|
||||
|
||||
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;
|
||||
@@ -49,12 +50,19 @@ public class CloudFrontKeyValueStoreService implements StoredResourceArns {
|
||||
private static final String STATUS_READY = "READY";
|
||||
|
||||
private final StorageBackend<String, KeyValueStore> store;
|
||||
/**
|
||||
* The tags CloudFront holds by resource ARN, which {@link CloudFrontService} keeps; the factory hands every caller
|
||||
* of the file the same store, so this one reads the tags it writes.
|
||||
*/
|
||||
private final StorageBackend<String, Map<String, String>> tags;
|
||||
private final RegionResolver regionResolver;
|
||||
|
||||
@Inject
|
||||
public CloudFrontKeyValueStoreService(StorageFactory factory, RegionResolver regionResolver) {
|
||||
this.store = factory.create("cloudfront", "cloudfront-key-value-stores.json",
|
||||
new TypeReference<Map<String, KeyValueStore>>() {});
|
||||
this.tags = factory.create("cloudfront", CloudFrontService.TAGS_FILE,
|
||||
new TypeReference<Map<String, Map<String, String>>>() {});
|
||||
this.regionResolver = regionResolver;
|
||||
}
|
||||
|
||||
@@ -145,6 +153,26 @@ public class CloudFrontKeyValueStoreService implements StoredResourceArns {
|
||||
}
|
||||
return store.get(names.getFirst()).map(KeyValueStore::getArn);
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags CloudFront holds under {@code arn}, whatever its resource type, read in place where its tag handlers
|
||||
* keep and read them: in the account the request runs in, by the whole ARN. CloudFront ARNs name the configured
|
||||
* default account whichever account owns the resource, so the ARN's account does not say where its tags are.
|
||||
* Empty when it holds none there.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> storedTags(String arn) {
|
||||
Map<String, String> held = new LinkedHashMap<>();
|
||||
if (!AwsArnUtils.isArnFor(arn, "cloudfront")) {
|
||||
return held;
|
||||
}
|
||||
tags.get(arn).ifPresent(stored -> stored.forEach((key, value) -> {
|
||||
if (key != null && value != null) {
|
||||
held.put(key, value);
|
||||
}
|
||||
}));
|
||||
return held;
|
||||
}
|
||||
public Optional<KeyValueStore> findByArn(String arn) {
|
||||
if (arn == null) {
|
||||
return Optional.empty();
|
||||
|
||||
@@ -65,6 +65,8 @@ import java.util.regex.Pattern;
|
||||
@ApplicationScoped
|
||||
public class CloudFrontService implements ServerCertificateReferenceProvider {
|
||||
|
||||
/** The file CloudFront's tags are stored in, by resource ARN, which IAM's tag lookup also reads. */
|
||||
static final String TAGS_FILE = "cloudfront-tags.json";
|
||||
private static final String CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
private static final int MAX_CUSTOM_RESPONSE_HEADERS_POLICIES = 20;
|
||||
private static final int MAX_DISTRIBUTIONS_PER_RESPONSE_HEADERS_POLICY = 100;
|
||||
@@ -209,7 +211,7 @@ public class CloudFrontService implements ServerCertificateReferenceProvider {
|
||||
new TypeReference<Map<String, CloudFrontOriginAccessIdentity>>() {});
|
||||
this.functionStore = factory.create("cloudfront", "cloudfront-functions.json",
|
||||
new TypeReference<Map<String, CloudFrontFunction>>() {});
|
||||
this.tagStore = factory.create("cloudfront", "cloudfront-tags.json",
|
||||
this.tagStore = factory.create("cloudfront", TAGS_FILE,
|
||||
new TypeReference<Map<String, Map<String, String>>>() {});
|
||||
this.cdpStore = factory.create("cloudfront", "cloudfront-continuous-deployment-policies.json",
|
||||
new TypeReference<Map<String, ContinuousDeploymentPolicy>>() {});
|
||||
@@ -1877,10 +1879,17 @@ public class CloudFrontService implements ServerCertificateReferenceProvider {
|
||||
fn.setEtag(UUID.randomUUID().toString());
|
||||
fn.setCreatedTime(Instant.now());
|
||||
fn.setLastModifiedTime(Instant.now());
|
||||
// A function's ARN is its name: a new one starts with no tags, whatever was left under that ARN before.
|
||||
tagStore.delete(functionArn(fn.getName()));
|
||||
functionStore.put(fn.getName(), fn);
|
||||
return fn;
|
||||
}
|
||||
|
||||
/** The ARN of the function {@code name}, which is the one its tags are kept under. */
|
||||
public String functionArn(String name) {
|
||||
return arn("function/" + name);
|
||||
}
|
||||
|
||||
public CloudFrontFunction describeFunction(String name, String stage) {
|
||||
String effectiveStage = normalizeFunctionStage(stage);
|
||||
Optional<CloudFrontFunction> function = functionStore.get(functionKey(name, effectiveStage));
|
||||
@@ -1940,6 +1949,7 @@ public class CloudFrontService implements ServerCertificateReferenceProvider {
|
||||
}
|
||||
functionStore.delete(name);
|
||||
functionStore.delete(functionKey(name, "LIVE"));
|
||||
tagStore.delete(functionArn(name));
|
||||
}
|
||||
|
||||
public List<CloudFrontFunction> listFunctions(String stage, String marker, int maxItems) {
|
||||
|
||||
Reference in new issue
Block a user