mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(memorydb): keep user and ACL tags and let them be tagged (#8082)
CreateUser and CreateACL never read their Tags member, and ListTags, TagResource and UntagResource resolved every ARN as a cluster, so a user or ACL ARN answered ClusterNotFoundFault and neither resource could be tagged at all. User and Acl now keep a tag map, set from Tags on create as CreateCluster already does. The three tag operations pick the resource from the ARN: user/ and acl/ look the name up in the current Region and require the stored ARN to match, answering UserNotFoundFault or ACLNotFoundFault, and any other ARN goes through clusterByArn as before. The built-in default user and open-access ACL are not stored, so they still answer the not-found fault. Users and ACLs saved before this change have no tags field and load with an empty map. Fixes #7956
This commit is contained in:
1 parent
f6b95fda16
commit
33968bca39
7 files changed
+111
-12
No files matched your search
@@ -122,6 +122,7 @@ public class MemoryDbHandler {
|
||||
JsonNode authNode = request.path("AuthenticationMode");
|
||||
spec.setAuthMode(parseAuthMode(authNode));
|
||||
spec.setPasswords(parsePasswords(authNode.path("Passwords")));
|
||||
spec.setTags(parseTags(request.path("Tags")));
|
||||
User created = service.createUser(spec, region);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("User", userNode(created));
|
||||
@@ -148,6 +149,7 @@ public class MemoryDbHandler {
|
||||
Acl spec = new Acl();
|
||||
spec.setName(text(request, "ACLName"));
|
||||
spec.setUserNames(parseStringList(request.path("UserNames")));
|
||||
spec.setTags(parseTags(request.path("Tags")));
|
||||
Acl created = service.createAcl(spec, region);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("ACL", aclNode(created));
|
||||
|
||||
@@ -556,6 +556,7 @@ public class MemoryDbService {
|
||||
user.setMinimumEngineVersion(DEFAULT_ENGINE_VERSION);
|
||||
user.setArn(buildArn(region, "user", name));
|
||||
user.setCreatedAt(Instant.now());
|
||||
user.setTags(spec.getTags());
|
||||
|
||||
users.put(resourceKey, user);
|
||||
LOG.infov("MemoryDB user {0} created with authMode={1}", name, user.getAuthMode());
|
||||
@@ -631,6 +632,7 @@ public class MemoryDbService {
|
||||
acl.setMinimumEngineVersion(DEFAULT_ENGINE_VERSION);
|
||||
acl.setArn(buildArn(region, "acl", name));
|
||||
acl.setCreatedAt(Instant.now());
|
||||
acl.setTags(spec.getTags());
|
||||
|
||||
acls.put(resourceKey, acl);
|
||||
LOG.infov("MemoryDB ACL {0} created with users={1}", name, acl.getUserNames());
|
||||
@@ -707,21 +709,21 @@ public class MemoryDbService {
|
||||
// ──────────────────────────── Tags ────────────────────────────
|
||||
|
||||
public Map<String, String> listTags(String resourceArn) {
|
||||
return clusterByArn(resourceArn).getTags();
|
||||
return taggedResource(resourceArn).tags();
|
||||
}
|
||||
|
||||
public Map<String, String> tagResource(String resourceArn, Map<String, String> tags) {
|
||||
Cluster cluster = clusterByArn(resourceArn);
|
||||
cluster.getTags().putAll(tags);
|
||||
clusters.put(key(cluster.getRegion(), cluster.getName()), cluster);
|
||||
return cluster.getTags();
|
||||
TaggedResource resource = taggedResource(resourceArn);
|
||||
resource.tags().putAll(tags);
|
||||
resource.save().run();
|
||||
return resource.tags();
|
||||
}
|
||||
|
||||
public Map<String, String> untagResource(String resourceArn, List<String> tagKeys) {
|
||||
Cluster cluster = clusterByArn(resourceArn);
|
||||
tagKeys.forEach(cluster.getTags()::remove);
|
||||
clusters.put(key(cluster.getRegion(), cluster.getName()), cluster);
|
||||
return cluster.getTags();
|
||||
TaggedResource resource = taggedResource(resourceArn);
|
||||
tagKeys.forEach(resource.tags()::remove);
|
||||
resource.save().run();
|
||||
return resource.tags();
|
||||
}
|
||||
|
||||
// ──────────────────────────── Authentication ────────────────────────────
|
||||
@@ -841,6 +843,28 @@ public class MemoryDbService {
|
||||
|
||||
// ──────────────────────────── Internals ────────────────────────────
|
||||
|
||||
private record TaggedResource(Map<String, String> tags, Runnable save) {}
|
||||
|
||||
private TaggedResource taggedResource(String resourceArn) {
|
||||
String resource = AwsArnUtils.resourceIfArnFor(resourceArn, "memorydb").orElse("");
|
||||
String region = currentRegion();
|
||||
if (resource.startsWith("user/")) {
|
||||
User user = resourceGet(users, resource.substring("user/".length()), region)
|
||||
.filter(u -> resourceArn.equals(u.getArn()))
|
||||
.orElseThrow(() -> new AwsException("UserNotFoundFault", "User not found.", 404));
|
||||
return new TaggedResource(user.getTags(), () -> users.put(key(region, user.getName()), user));
|
||||
}
|
||||
if (resource.startsWith("acl/")) {
|
||||
Acl acl = resourceGet(acls, resource.substring("acl/".length()), region)
|
||||
.filter(a -> resourceArn.equals(a.getArn()))
|
||||
.orElseThrow(() -> new AwsException("ACLNotFoundFault", "ACL not found.", 404));
|
||||
return new TaggedResource(acl.getTags(), () -> acls.put(key(region, acl.getName()), acl));
|
||||
}
|
||||
Cluster cluster = clusterByArn(resourceArn);
|
||||
return new TaggedResource(cluster.getTags(),
|
||||
() -> clusters.put(key(cluster.getRegion(), cluster.getName()), cluster));
|
||||
}
|
||||
|
||||
private Cluster clusterByArn(String resourceArn) {
|
||||
if (resourceArn == null) {
|
||||
throw new AwsException("InvalidParameterValueException", "ResourceArn is required.", 400);
|
||||
|
||||
@@ -5,7 +5,9 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A MemoryDB Access Control List (ACL): a named collection of {@link User}s that a
|
||||
@@ -26,6 +28,7 @@ public class Acl {
|
||||
private String minimumEngineVersion;
|
||||
private String arn;
|
||||
private Instant createdAt;
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
|
||||
public Acl() {}
|
||||
|
||||
@@ -56,4 +59,9 @@ public class Acl {
|
||||
|
||||
public Instant getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) {
|
||||
this.tags = tags != null ? tags : new LinkedHashMap<>();
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,9 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A MemoryDB user. Users authenticate either with one or more passwords or with IAM,
|
||||
@@ -26,6 +28,7 @@ public class User {
|
||||
private String minimumEngineVersion;
|
||||
private String arn;
|
||||
private Instant createdAt;
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
|
||||
public User() {}
|
||||
|
||||
@@ -62,4 +65,9 @@ public class User {
|
||||
|
||||
public Instant getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) {
|
||||
this.tags = tags != null ? tags : new LinkedHashMap<>();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user