mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(rds): resolve tags by ARN resource type, not only DB instances (#1649)
* fix(rds): resolve tags by ARN resource type, not only DB instances ListTagsForResource, AddTagsToResource and RemoveTagsFromResource unconditionally resolved every ResourceName to a DB instance, so any non-instance ARN (e.g. a DB subnet group) returned 404 DBInstanceNotFound. This broke tools such as the Crossplane Upbound AWS provider, which calls ListTagsForResource on every observe of a DB subnet group and never sees it become ready. Parse the ARN's resource-type segment and dispatch to the matching store (db, cluster, subgrp): return the resource's tags, the resource-specific NotFound fault when it is missing, and InvalidParameterValue for unsupported resource types. Add tag storage to DbCluster and DbSubnetGroup mirroring DbInstance. A bare (non-ARN) resource name still resolves to a DB instance for backwards compatibility. * fix(rds): return InvalidParameterValue for malformed or non-RDS tag ARNs Address PR review: only fall back to a DB-instance lookup for bare, non-ARN resource names. Strings that start with arn: are now parsed strictly and must be RDS ARNs; malformed ARNs and ARNs for other services return 400 InvalidParameterValue instead of a misleading DBInstanceNotFound/DBClusterNotFoundFault. * fix(rds): preserve subnet group tags across modifyDbSubnetGroup Address PR review: buildSubnetGroup constructs a fresh DbSubnetGroup with an empty tag map, so modifying a subnet group's subnets dropped any tags added via AddTagsToResource. Carry the existing group's tags onto the rebuilt object before persisting, matching AWS ModifyDBSubnetGroup. * fix(rds): reject type-less RDS ARNs in tag ops and clarify unsupported-type message Review feedback from #1649: - An RDS ARN whose resource part is not <type>:<id> now returns 400 InvalidParameterValue (matching real AWS) instead of falling back to a DB-instance lookup; bare non-ARN names keep resolving as DB instances. - The unsupported-resource-type message now states the Floci scope limitation instead of implying those types are untaggable on AWS.
This commit is contained in:
1 parent
c99dd75b87
commit
98464b4433
4 files changed
+166
-17
No files matched your search
@@ -280,6 +280,93 @@ class RdsServiceTest {
|
||||
assertTrue(rdsService.listDbSubnetGroups("sample-db-subnets").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dbSubnetGroupTagsRoundTripAndMutateByArn() {
|
||||
rdsService.createDbSubnetGroup(
|
||||
"sample-db-subnets", "test", java.util.List.of("subnet-default-a", "subnet-default-b"));
|
||||
String arn = "arn:aws:rds:us-east-1:123456789012:subgrp:sample-db-subnets";
|
||||
|
||||
// A subnet group with no tags must list cleanly — previously this threw DBInstanceNotFound (404)
|
||||
// because every ResourceName was resolved as a DB instance.
|
||||
assertEquals(java.util.Map.of(), rdsService.listTagsForResource(arn));
|
||||
|
||||
rdsService.addTagsToResource(arn, java.util.Map.of("Name", "sample-db-subnets"));
|
||||
assertEquals(java.util.Map.of("Name", "sample-db-subnets"),
|
||||
rdsService.listTagsForResource(arn));
|
||||
|
||||
rdsService.removeTagsFromResource(arn, java.util.List.of("Name"));
|
||||
assertEquals(java.util.Map.of(), rdsService.listTagsForResource(arn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void dbSubnetGroupTagsSurviveModify() {
|
||||
rdsService.createDbSubnetGroup(
|
||||
"sample-db-subnets", "test", java.util.List.of("subnet-default-a", "subnet-default-b"));
|
||||
String arn = "arn:aws:rds:us-east-1:123456789012:subgrp:sample-db-subnets";
|
||||
rdsService.addTagsToResource(arn, java.util.Map.of("Name", "sample-db-subnets"));
|
||||
|
||||
rdsService.modifyDbSubnetGroup("sample-db-subnets", java.util.List.of("subnet-default-a"));
|
||||
|
||||
assertEquals(java.util.Map.of("Name", "sample-db-subnets"),
|
||||
rdsService.listTagsForResource(arn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTagsForMissingSubnetGroupReturnsSubnetGroupNotFound() {
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
rdsService.listTagsForResource("arn:aws:rds:us-east-1:123456789012:subgrp:missing"));
|
||||
|
||||
assertEquals("DBSubnetGroupNotFoundFault", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dbClusterTagsRoundTripByArn() {
|
||||
DbCluster cluster = rdsService.createDbCluster("cluster1", "postgres", "13",
|
||||
"admin", "password", "dbname", false, null);
|
||||
|
||||
assertEquals(java.util.Map.of(), rdsService.listTagsForResource(cluster.getDbClusterArn()));
|
||||
|
||||
rdsService.addTagsToResource(cluster.getDbClusterArn(), java.util.Map.of("env", "test"));
|
||||
assertEquals(java.util.Map.of("env", "test"),
|
||||
rdsService.listTagsForResource(cluster.getDbClusterArn()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagOperationsRejectUnsupportedResourceArn() {
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
rdsService.listTagsForResource("arn:aws:rds:us-east-1:123456789012:og:some-option-group"));
|
||||
|
||||
assertEquals("InvalidParameterValue", exception.getErrorCode());
|
||||
// The type is valid on real AWS; the message must present this as a Floci limitation.
|
||||
assertTrue(exception.getMessage().contains("not yet implemented by Floci"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagOperationsRejectTypelessRdsArn() {
|
||||
// Real AWS rejects an RDS ARN whose resource part is not <type>:<id> with InvalidParameterValue;
|
||||
// previously this fell back to a DB-instance lookup and returned DBInstanceNotFound.
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
rdsService.listTagsForResource("arn:aws:rds:us-east-1:123456789012:mydb"));
|
||||
|
||||
assertEquals("InvalidParameterValue", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagOperationsRejectNonRdsArn() {
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
rdsService.listTagsForResource("arn:aws:s3:::some-bucket"));
|
||||
|
||||
assertEquals("InvalidParameterValue", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagOperationsRejectMalformedArn() {
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
rdsService.listTagsForResource("arn:aws:rds:incomplete"));
|
||||
|
||||
assertEquals("InvalidParameterValue", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstanceRejectsMissingDbSubnetGroupBeforeStartingRuntime() {
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
|
||||
Reference in new issue
Block a user