mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudwatch): mint the regionless dashboard ARN AWS uses (#5135)
A dashboard's ARN carried the Region of the request (arn:aws:cloudwatch:us-east-1:<account>:dashboard/<name>), while AWS's has none: arn:<partition>:cloudwatch::<account>:dashboard/<name>. Floci now mints that form, in the partition of the Region the dashboard was put through, and a dashboard stored with the old ARN reads back with the new one. The region-ful ARNs Floci handed out before still resolve for tagging, for the dashboard's own Region only. Storage stays per Region.
This commit is contained in:
1 parent
22ff93365e
commit
c81290823b
3 files changed
+79
-46
No files matched your search
+4
-4
@@ -192,10 +192,10 @@ class CloudWatchTagUnknownResourceIntegrationTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* The dashboard ARN AWS documents carries no region, and the one Floci mints does. A
|
||||
* caller sending the documented form for a dashboard that exists must not be told the
|
||||
* dashboard does not exist, which is what raising on a miss would otherwise have made of
|
||||
* a shape that used to fall through to an empty tag map.
|
||||
* The dashboard ARN AWS documents carries no region, and it is the one Floci mints. A
|
||||
* caller sending it for a dashboard that exists must not be told the dashboard does not
|
||||
* exist, which is what raising on a miss would otherwise have made of a shape that used to
|
||||
* fall through to an empty tag map.
|
||||
*/
|
||||
@Test
|
||||
void theRegionlessDashboardArnAwsDocumentsAlsoResolves() {
|
||||
|
||||
+38
-15
@@ -34,8 +34,32 @@ class CloudWatchDashboardsServiceTest {
|
||||
Dashboard dashboard = service.getDashboard("ops", REGION);
|
||||
assertEquals(BODY, dashboard.getDashboardBody());
|
||||
assertEquals("ops", dashboard.getDashboardName());
|
||||
assertEquals("arn:aws:cloudwatch:us-east-1:000000000000:dashboard/ops",
|
||||
dashboard.getDashboardArn());
|
||||
assertEquals("arn:aws:cloudwatch::000000000000:dashboard/ops", dashboard.getDashboardArn());
|
||||
}
|
||||
|
||||
// Catches: a dashboard ARN minted with the request's Region; AWS's has none, in every partition.
|
||||
@Test
|
||||
void theDashboardArnIsRegionlessInTheRegionsPartition() {
|
||||
service.putDashboard("ops", BODY, "cn-north-1");
|
||||
|
||||
assertEquals("arn:aws-cn:cloudwatch::000000000000:dashboard/ops",
|
||||
service.getDashboard("ops", "cn-north-1").getDashboardArn());
|
||||
}
|
||||
|
||||
// Catches: a dashboard persisted before the change reading back with its old region-ful ARN.
|
||||
@Test
|
||||
void aDashboardStoredWithTheOldRegionfulArnReadsBackRegionless() {
|
||||
InMemoryStorage<String, Dashboard> store = new InMemoryStorage<>();
|
||||
store.put(REGION + "::legacy", new Dashboard("legacy",
|
||||
"arn:aws:cloudwatch:us-east-1:000000000000:dashboard/legacy", BODY));
|
||||
CloudWatchDashboardsService legacy = new CloudWatchDashboardsService(store,
|
||||
new RegionResolver(REGION, "000000000000"));
|
||||
|
||||
String regionless = "arn:aws:cloudwatch::000000000000:dashboard/legacy";
|
||||
assertEquals(regionless, legacy.getDashboard("legacy", REGION).getDashboardArn());
|
||||
assertEquals(regionless, legacy.listDashboards(null, REGION).get(0).getDashboardArn());
|
||||
legacy.tagResource(regionless, Map.of("env", "dev"), REGION);
|
||||
assertEquals(Map.of("env", "dev"), legacy.listTagsForResource(regionless, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,31 +175,30 @@ class CloudWatchDashboardsServiceTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* AWS documents the dashboard ARN without a region and Floci mints one with a region, so
|
||||
* both forms have to resolve. Before the tag operations raised on a miss this divergence
|
||||
* was invisible here: the documented ARN matched nothing and got an empty tag map back.
|
||||
* Floci mints the regionless ARN AWS uses, and used to mint one with the request's Region.
|
||||
* Callers may still hold the old form, so both resolve to the same dashboard.
|
||||
*/
|
||||
@Test
|
||||
void bothTheRegionlessAndTheRegionfulDashboardArnResolve() {
|
||||
void bothTheRegionlessAndTheOldRegionfulDashboardArnResolve() {
|
||||
service.putDashboard("ops", BODY, REGION);
|
||||
String regionful = service.getDashboard("ops", REGION).getDashboardArn();
|
||||
String regionless = "arn:aws:cloudwatch::000000000000:dashboard/ops";
|
||||
String regionless = service.getDashboard("ops", REGION).getDashboardArn();
|
||||
String regionful = "arn:aws:cloudwatch:us-east-1:000000000000:dashboard/ops";
|
||||
|
||||
assertEquals("arn:aws:cloudwatch:us-east-1:000000000000:dashboard/ops", regionful);
|
||||
assertEquals("arn:aws:cloudwatch::000000000000:dashboard/ops", regionless);
|
||||
assertTrue(CloudWatchDashboardsService.isDashboardArn(regionless));
|
||||
|
||||
service.tagResource(regionless, Map.of("env", "dev"), REGION);
|
||||
service.tagResource(regionful, Map.of("env", "dev"), REGION);
|
||||
// Read back through the other form: one dashboard, reachable either way.
|
||||
assertEquals(Map.of("env", "dev"), service.listTagsForResource(regionful, REGION));
|
||||
assertEquals(Map.of("env", "dev"), service.listTagsForResource(regionless, REGION));
|
||||
assertEquals(Map.of("env", "dev"), service.listTagsForResource(regionful, REGION));
|
||||
|
||||
service.untagResource(regionless, List.of("env"), REGION);
|
||||
assertEquals(Map.of(), service.listTagsForResource(regionful, REGION));
|
||||
service.untagResource(regionful, List.of("env"), REGION);
|
||||
assertEquals(Map.of(), service.listTagsForResource(regionless, REGION));
|
||||
}
|
||||
|
||||
/**
|
||||
* Only an absent region stands in for the dashboard's own. An ARN naming a different
|
||||
* region must not resolve to the same-named dashboard in this one.
|
||||
* The old region-ful form resolves only for the Region the dashboard was put through. An
|
||||
* ARN naming a different Region must not resolve to the same-named dashboard in this one.
|
||||
*/
|
||||
@Test
|
||||
void anArnNamingAnotherRegionDoesNotResolve() {
|
||||
|
||||
Reference in new issue
Block a user