mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(datasync): give resource-tag conditions the tags of the agent, location or task a request names (#8844)
The generated request resources give DataSync's agent, location and task types the aws:ResourceTag/ key, but no service answered the datasync namespace's stored tags, so a condition on their tags saw none. DataSyncService now answers it: storedTags reads the resource stored under the ARN itself, in the request's account, in place, as the tag handlers find it. TagResource and UntagResource changed the tag map in place with no lock; they now give the resource a new map one call at a time, and the tags fields are volatile.
This commit is contained in:
1 parent
933b617961
commit
1863f7f4bb
8 files changed
+139
-17
No files matched your search
@@ -50,9 +50,10 @@ import java.util.Optional;
|
||||
* the tags of an application; S3 Vectors, for the tags of a vector bucket or an index; Timestream for InfluxDB, for the
|
||||
* tags of a DB instance, a DB cluster, a parameter group or a backup; CloudTrail, for the tags of a trail; Budgets, for
|
||||
* the tags of a budget or a budget action; AWS FIS, for the tags of an experiment template, an experiment or an action;
|
||||
* CodePipeline, for the tags of a pipeline, a webhook or a custom action type); 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>
|
||||
* CodePipeline, for the tags of a pipeline, a webhook or a custom action type; DataSync, for the tags of an agent, a
|
||||
* location or a task); 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
|
||||
|
||||
@@ -7,6 +7,8 @@ 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.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.StorageBackend;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
import io.floci.aws.services.datasync.model.DataSyncAgent;
|
||||
@@ -27,6 +29,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -42,7 +45,7 @@ import java.util.function.Function;
|
||||
* back.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class DataSyncService {
|
||||
public class DataSyncService implements StoredResourceArns {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(DataSyncService.class);
|
||||
|
||||
@@ -319,18 +322,61 @@ public class DataSyncService {
|
||||
return new LinkedHashMap<>(findTaggable(resourceArn).getTags());
|
||||
}
|
||||
|
||||
public void tagResource(String resourceArn, Map<String, String> tags) {
|
||||
/**
|
||||
* Gives the resource a new map holding its tags and {@code tags}. Tag calls run one at a time, so two of them never
|
||||
* lose one's tags, and a lookup reads one whole set.
|
||||
*/
|
||||
public synchronized void tagResource(String resourceArn, Map<String, String> tags) {
|
||||
DataSyncTaggable resource = findTaggable(resourceArn);
|
||||
resource.getTags().putAll(tags);
|
||||
Map<String, String> merged = new LinkedHashMap<>(resource.getTags());
|
||||
merged.putAll(tags);
|
||||
resource.setTags(merged);
|
||||
persist(resourceArn, resource);
|
||||
}
|
||||
|
||||
public void untagResource(String resourceArn, List<String> tagKeys) {
|
||||
/** Gives the resource a new map without {@code tagKeys}, one tag call at a time, as {@link #tagResource}. */
|
||||
public synchronized void untagResource(String resourceArn, List<String> tagKeys) {
|
||||
DataSyncTaggable resource = findTaggable(resourceArn);
|
||||
tagKeys.forEach(resource.getTags()::remove);
|
||||
Map<String, String> remaining = new LinkedHashMap<>(resource.getTags());
|
||||
tagKeys.forEach(remaining::remove);
|
||||
resource.setTags(remaining);
|
||||
persist(resourceArn, resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String namespace() {
|
||||
return "datasync";
|
||||
}
|
||||
|
||||
/** A request names an agent, a location or a task by its ARN: nothing to find. */
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags of the agent, the location or the task whose ARN is {@code arn}, in the request's account, where the tag
|
||||
* handlers read: an ARN of another account names none. Read in place under the ARN itself, which each is stored
|
||||
* under, an agent, a location or a task stored before storage was account-aware included. A task execution's ARN
|
||||
* reads nothing, Floci holding no tags of its own for it. Tag calls give the resource a new map, so the read is of
|
||||
* one whole set.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> storedTags(String arn) {
|
||||
if (!AwsArnUtils.isArnFor(arn, "datasync")) {
|
||||
return Map.of();
|
||||
}
|
||||
String account = regionResolver.getAccountId();
|
||||
if (!AwsArnUtils.parse(arn).accountId().equals(account)) {
|
||||
return Map.of();
|
||||
}
|
||||
Optional<DataSyncTaggable> resource = AccountAwareStorageBackend.readInAccount(agents, account, arn)
|
||||
.<DataSyncTaggable>map(agent -> agent)
|
||||
.or(() -> AccountAwareStorageBackend.readInAccount(locations, account, arn).map(location -> location))
|
||||
.or(() -> AccountAwareStorageBackend.readInAccount(tasks, account, arn).map(task -> task));
|
||||
return new LinkedHashMap<>(resource.map(DataSyncTaggable::getTags).orElse(Map.of()));
|
||||
}
|
||||
|
||||
private DataSyncTaggable findTaggable(String resourceArn) {
|
||||
requireArn(resourceArn, "ResourceArn");
|
||||
return agents.get(resourceArn).<DataSyncTaggable>map(agent -> agent)
|
||||
|
||||
@@ -22,7 +22,7 @@ public class DataSyncAgent implements DataSyncTaggable {
|
||||
private String platformVersion;
|
||||
private Instant creationTime;
|
||||
private Instant lastConnectionTime;
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private volatile Map<String, String> tags = new LinkedHashMap<>();
|
||||
|
||||
public String getAgentArn() {
|
||||
return agentArn;
|
||||
|
||||
@@ -21,7 +21,7 @@ public class DataSyncLocation implements DataSyncTaggable {
|
||||
private String region;
|
||||
private JsonNode configuration;
|
||||
private Instant creationTime;
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private volatile Map<String, String> tags = new LinkedHashMap<>();
|
||||
|
||||
public String getLocationArn() {
|
||||
return locationArn;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class DataSyncTask implements DataSyncTaggable {
|
||||
private JsonNode manifestConfig;
|
||||
private JsonNode taskReportConfig;
|
||||
private Instant creationTime;
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private volatile Map<String, String> tags = new LinkedHashMap<>();
|
||||
|
||||
public String getTaskArn() {
|
||||
return taskArn;
|
||||
|
||||
Reference in new issue
Block a user