mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(athena): give resource-tag conditions the tags of the workgroup or data catalog a request names (#8607)
The generated request resources give Athena's workgroup and data catalog types aws:ResourceTag/ keys, but AthenaStoredResourceArns did not answer storedTags, so a condition on their tags saw none. It now answers from AthenaService.storedTags, which reads the workgroup or the data catalog stored under the ARN in the account and Region it names, a pre-multi-account one of the default account in place, matched on the whole ARN; the built-in primary workgroup and AwsDataCatalog carry none. The tag lists are volatile, as tagging already replaces a list whole.
This commit is contained in:
1 parent
057684feac
commit
cf3d7e827c
8 files changed
+117
-9
No files matched your search
@@ -32,9 +32,10 @@ import java.util.Optional;
|
||||
* execution of a callback, and the tags of a function, an event source mapping, a web function, a MicroVM image or a
|
||||
* 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); 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>
|
||||
* 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>
|
||||
*
|
||||
* <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
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.floci.aws.core.common.PaginatedResult;
|
||||
import io.floci.aws.core.common.Pagination;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.common.RequestScopes;
|
||||
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.athena.model.CreateWorkGroupConfigurationRequest;
|
||||
@@ -432,6 +433,43 @@ public class AthenaService {
|
||||
return requireTaggedDataCatalog(arn.region(), name, resourceArn).getTags();
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags of the workgroup or the data catalog stored under {@code arn} in the account and Region it names, read
|
||||
* in place and matched on the whole ARN; empty for an ARN naming nothing stored, the built-in {@code primary}
|
||||
* workgroup and {@code AwsDataCatalog} included, which carry none.
|
||||
*/
|
||||
public Map<String, String> storedTags(String arn) {
|
||||
if (!AwsArnUtils.isArnFor(arn, "athena")) {
|
||||
return Map.of();
|
||||
}
|
||||
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
|
||||
String resource = parsed.resource();
|
||||
if (!arn.equals(AwsArnUtils.Arn.of("athena", parsed.region(), parsed.accountId(), resource).toString())) {
|
||||
return Map.of();
|
||||
}
|
||||
List<WorkGroupTag> tags = null;
|
||||
if (resource.startsWith(WORKGROUP_RESOURCE) && resource.indexOf('/', WORKGROUP_RESOURCE.length()) < 0) {
|
||||
tags = AccountAwareStorageBackend.readInAccount(workGroupStore, parsed.accountId(),
|
||||
workGroupKey(parsed.region(), resource.substring(WORKGROUP_RESOURCE.length())))
|
||||
.map(WorkGroup::getTags)
|
||||
.orElse(null);
|
||||
} else if (resource.startsWith(DATA_CATALOG_RESOURCE)) {
|
||||
tags = AccountAwareStorageBackend.readInAccount(dataCatalogStore, parsed.accountId(),
|
||||
catalogKey(parsed.region(), resource.substring(DATA_CATALOG_RESOURCE.length())))
|
||||
.map(DataCatalog::getTags)
|
||||
.orElse(null);
|
||||
}
|
||||
Map<String, String> byKey = new LinkedHashMap<>();
|
||||
if (tags != null) {
|
||||
for (WorkGroupTag tag : tags) {
|
||||
if (tag.getKey() != null && tag.getValue() != null) {
|
||||
byKey.put(tag.getKey(), tag.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return byKey;
|
||||
}
|
||||
|
||||
public synchronized void tagResource(String resourceArn, List<WorkGroupTag> tags) {
|
||||
if (tags == null || tags.isEmpty()) {
|
||||
throw new AwsException("InvalidRequestException", "Tags is required.", 400);
|
||||
|
||||
@@ -6,20 +6,23 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* What IAM asks Athena of the resources a request names: the workgroup and the data catalog its handlers use for a
|
||||
* request naming none, {@code primary} and {@code AwsDataCatalog}.
|
||||
* request naming none, {@code primary} and {@code AwsDataCatalog}, and the tags of a workgroup or a data catalog.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class AthenaStoredResourceArns implements StoredResourceArns {
|
||||
|
||||
private final RegionResolver regionResolver;
|
||||
private final AthenaService athena;
|
||||
|
||||
@Inject
|
||||
public AthenaStoredResourceArns(RegionResolver regionResolver) {
|
||||
public AthenaStoredResourceArns(RegionResolver regionResolver, AthenaService athena) {
|
||||
this.regionResolver = regionResolver;
|
||||
this.athena = athena;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,4 +44,9 @@ public class AthenaStoredResourceArns implements StoredResourceArns {
|
||||
default -> Optional.empty();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> storedTags(String arn) {
|
||||
return athena.storedTags(arn);
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class DataCatalog {
|
||||
private Map<String, String> parameters = new LinkedHashMap<>();
|
||||
|
||||
@JsonProperty("Tags")
|
||||
private List<WorkGroupTag> tags = new ArrayList<>();
|
||||
private volatile List<WorkGroupTag> tags = new ArrayList<>();
|
||||
|
||||
public DataCatalog() {}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public class WorkGroup {
|
||||
private Instant creationTime;
|
||||
|
||||
@JsonProperty("Tags")
|
||||
private List<WorkGroupTag> tags = new ArrayList<>();
|
||||
private volatile List<WorkGroupTag> tags = new ArrayList<>();
|
||||
|
||||
@JsonProperty("Configuration")
|
||||
private WorkGroupConfiguration configuration;
|
||||
|
||||
Reference in new issue
Block a user