From 874304b7dc3839163d341a9764d021ac03220dae Mon Sep 17 00:00:00 2001 From: Julian Sommer <115516918+juliansommer@users.noreply.github.com> Date: Tue, 25 Aug 2026 09:50:51 +1000 Subject: [PATCH] chore: delete one line wrapper function --- spinifex/gateway/rds/authz_test.go | 10 ++++----- spinifex/gateway/rds/handler_test.go | 6 ++--- spinifex/gateway/rds_test.go | 18 +++++++-------- spinifex/handlers/rds/arn.go | 23 +++----------------- spinifex/handlers/rds/arn_parse_test.go | 22 +++++++++---------- spinifex/handlers/rds/arn_test.go | 10 ++++----- spinifex/handlers/rds/backup.go | 2 +- spinifex/handlers/rds/backup_test.go | 2 +- spinifex/handlers/rds/create_test.go | 2 +- spinifex/handlers/rds/describe.go | 2 +- spinifex/handlers/rds/events.go | 4 ++-- spinifex/handlers/rds/events_test.go | 2 +- spinifex/handlers/rds/parametergroup.go | 2 +- spinifex/handlers/rds/parametergroup_test.go | 6 ++--- spinifex/handlers/rds/snapshot.go | 2 +- spinifex/handlers/rds/snapshot_test.go | 6 ++--- spinifex/handlers/rds/subnetgroup.go | 2 +- spinifex/handlers/rds/subnetgroup_test.go | 2 +- spinifex/handlers/rds/tags_test.go | 22 +++++++++---------- 19 files changed, 64 insertions(+), 81 deletions(-) diff --git a/spinifex/gateway/rds/authz_test.go b/spinifex/gateway/rds/authz_test.go index 4dc26076a..4df544f10 100644 --- a/spinifex/gateway/rds/authz_test.go +++ b/spinifex/gateway/rds/authz_test.go @@ -182,8 +182,8 @@ func TestResourceARN_UnscopedActions(t *testing.T) { // so a principal fenced off an instance could snapshot it, restore the copy // under a name the Deny does not cover, and set a master password of their own. func TestResourceARN_ResourceScopedDenyReachesTheSnapshotActions(t *testing.T) { - deniedInstance := handlers_rds.DBInstanceARN(testRegion, testAccountID, "prod-db") - deniedSnapshot := handlers_rds.DBSnapshotARN(testRegion, testAccountID, "prod-db-nightly") + deniedInstance := handlers_rds.FormatARN(handlers_rds.ResourceKindDBInstance, testRegion, testAccountID, "prod-db") + deniedSnapshot := handlers_rds.FormatARN(handlers_rds.ResourceKindDBSnapshot, testRegion, testAccountID, "prod-db-nightly") // The common shape: a blanket grant fenced by a resource-scoped deny. policies := []iampolicy.PolicyDocument{{ Version: "2012-10-17", @@ -231,7 +231,7 @@ func TestResourceARN_ResourceScopedDenyReachesTheSnapshotActions(t *testing.T) { // The tag actions name their resource by ARN, so the scope validates the ARN it // was given rather than rebuilding it from an identifier. func TestResourceARN_TagActionsUseTheSuppliedARN(t *testing.T) { - arn := handlers_rds.DBSnapshotARN(testRegion, testAccountID, "orders-db-pre-upgrade") + arn := handlers_rds.FormatARN(handlers_rds.ResourceKindDBSnapshot, testRegion, testAccountID, "orders-db-pre-upgrade") for _, action := range []string{"AddTagsToResource", "RemoveTagsFromResource", "ListTagsForResource"} { t.Run(action, func(t *testing.T) { got, err := ResourceARN(action, testRegion, testAccountID, map[string]string{"ResourceName": arn}) @@ -246,8 +246,8 @@ func TestResourceARN_RejectsUnusableARNs(t *testing.T) { name string resourceName string }{ - {"another account", handlers_rds.DBInstanceARN(testRegion, "999988887777", "orders-db")}, - {"another region", handlers_rds.DBInstanceARN("us-east-1", testAccountID, "orders-db")}, + {"another account", handlers_rds.FormatARN(handlers_rds.ResourceKindDBInstance, testRegion, "999988887777", "orders-db")}, + {"another region", handlers_rds.FormatARN(handlers_rds.ResourceKindDBInstance, "us-east-1", testAccountID, "orders-db")}, {"another service", "arn:aws:ec2:" + testRegion + ":" + testAccountID + ":instance/i-0abc123"}, {"not an ARN", "orders-db"}, {"unknown resource type", "arn:aws:rds:" + testRegion + ":" + testAccountID + ":cluster:orders"}, diff --git a/spinifex/gateway/rds/handler_test.go b/spinifex/gateway/rds/handler_test.go index afa2cb924..6f2f43097 100644 --- a/spinifex/gateway/rds/handler_test.go +++ b/spinifex/gateway/rds/handler_test.go @@ -298,7 +298,7 @@ func TestDispatch_DescribeDBInstancesReturnsEmptyResultSet(t *testing.T) { func TestDispatch_ListTagsForResourceRendersTheNestedTagList(t *testing.T) { body, err := Dispatch(t.Context(), "ListTagsForResource", map[string]string{ "Action": "ListTagsForResource", - "ResourceName": handlers_rds.DBInstanceARN("ap-southeast-2", testAccountID, "orders-db"), + "ResourceName": handlers_rds.FormatARN(handlers_rds.ResourceKindDBInstance, "ap-southeast-2", testAccountID, "orders-db"), }, newStubbedNATS(t), testCaller, testEnv) require.NoError(t, err) @@ -331,7 +331,7 @@ func TestDispatch_AddTagsToResourceParsesTheTagList(t *testing.T) { require.NoError(t, err) t.Cleanup(func() { _ = sub.Unsubscribe() }) - arn := handlers_rds.DBInstanceARN("ap-southeast-2", testAccountID, "orders-db") + arn := handlers_rds.FormatARN(handlers_rds.ResourceKindDBInstance, "ap-southeast-2", testAccountID, "orders-db") _, err = Dispatch(t.Context(), "AddTagsToResource", map[string]string{ "Action": "AddTagsToResource", "ResourceName": arn, @@ -370,7 +370,7 @@ func TestDispatch_RemoveTagsFromResourceParsesMemberTagKeys(t *testing.T) { _, err = Dispatch(t.Context(), "RemoveTagsFromResource", map[string]string{ "Action": "RemoveTagsFromResource", - "ResourceName": handlers_rds.DBInstanceARN("ap-southeast-2", testAccountID, "orders-db"), + "ResourceName": handlers_rds.FormatARN(handlers_rds.ResourceKindDBInstance, "ap-southeast-2", testAccountID, "orders-db"), "TagKeys.member.1": "env", "TagKeys.member.2": "team", }, nc, testCaller, testEnv) diff --git a/spinifex/gateway/rds_test.go b/spinifex/gateway/rds_test.go index 69bab1982..fc96c225c 100644 --- a/spinifex/gateway/rds_test.go +++ b/spinifex/gateway/rds_test.go @@ -205,8 +205,8 @@ func TestRDSRequest_SnapshotActionsAuthorizeSourceAndTarget(t *testing.T) { query: "Action=CreateDBSnapshot&DBInstanceIdentifier=orders-db" + "&DBSnapshotIdentifier=orders-db-nightly", resources: handlers_iam.StringOrArr{ - handlers_rds.DBInstanceARN("ap-southeast-2", rdsTestAccountID, "orders-db"), - handlers_rds.DBSnapshotARN("ap-southeast-2", rdsTestAccountID, "orders-db-nightly"), + handlers_rds.FormatARN(handlers_rds.ResourceKindDBInstance, "ap-southeast-2", rdsTestAccountID, "orders-db"), + handlers_rds.FormatARN(handlers_rds.ResourceKindDBSnapshot, "ap-southeast-2", rdsTestAccountID, "orders-db-nightly"), }, }, { @@ -215,8 +215,8 @@ func TestRDSRequest_SnapshotActionsAuthorizeSourceAndTarget(t *testing.T) { query: "Action=RestoreDBInstanceFromDBSnapshot&DBSnapshotIdentifier=orders-db-nightly" + "&DBInstanceIdentifier=orders-db-restored", resources: handlers_iam.StringOrArr{ - handlers_rds.DBSnapshotARN("ap-southeast-2", rdsTestAccountID, "orders-db-nightly"), - handlers_rds.DBInstanceARN("ap-southeast-2", rdsTestAccountID, "orders-db-restored"), + handlers_rds.FormatARN(handlers_rds.ResourceKindDBSnapshot, "ap-southeast-2", rdsTestAccountID, "orders-db-nightly"), + handlers_rds.FormatARN(handlers_rds.ResourceKindDBInstance, "ap-southeast-2", rdsTestAccountID, "orders-db-restored"), }, }, } @@ -238,8 +238,8 @@ func TestRDSRequest_SnapshotActionsAuthorizeSourceAndTarget(t *testing.T) { } func TestRDSRequest_SnapshotActionsUseOnePolicySnapshot(t *testing.T) { - source := handlers_rds.DBInstanceARN("ap-southeast-2", rdsTestAccountID, "orders-db") - target := handlers_rds.DBSnapshotARN("ap-southeast-2", rdsTestAccountID, "orders-db-nightly") + source := handlers_rds.FormatARN(handlers_rds.ResourceKindDBInstance, "ap-southeast-2", rdsTestAccountID, "orders-db") + target := handlers_rds.FormatARN(handlers_rds.ResourceKindDBSnapshot, "ap-southeast-2", rdsTestAccountID, "orders-db-nightly") resolution := 0 gw, probe := newRDSGatewayWithResolver(func(_, _ string) ([]handlers_iam.PolicyDocument, error) { resolution++ @@ -269,13 +269,13 @@ func TestRDSRequest_SnapshotActionsHonorTargetDeny(t *testing.T) { name: "create snapshot", action: "rds:CreateDBSnapshot", query: "Action=CreateDBSnapshot&DBInstanceIdentifier=orders-db" + "&DBSnapshotIdentifier=orders-db-nightly", - target: handlers_rds.DBSnapshotARN("ap-southeast-2", rdsTestAccountID, "orders-db-nightly"), + target: handlers_rds.FormatARN(handlers_rds.ResourceKindDBSnapshot, "ap-southeast-2", rdsTestAccountID, "orders-db-nightly"), }, { name: "restore snapshot", action: "rds:RestoreDBInstanceFromDBSnapshot", query: "Action=RestoreDBInstanceFromDBSnapshot&DBSnapshotIdentifier=orders-db-nightly" + "&DBInstanceIdentifier=orders-db-restored", - target: handlers_rds.DBInstanceARN("ap-southeast-2", rdsTestAccountID, "orders-db-restored"), + target: handlers_rds.FormatARN(handlers_rds.ResourceKindDBInstance, "ap-southeast-2", rdsTestAccountID, "orders-db-restored"), }, } for _, tt := range tests { @@ -314,7 +314,7 @@ func TestRDSRequest_CrossAccountARNIsRejectedNotEvaluated(t *testing.T) { t.Error("a cross-account ARN must never reach policy evaluation") return nil, nil }) - foreign := handlers_rds.DBInstanceARN("ap-southeast-2", "999988887777", "orders-db") + foreign := handlers_rds.FormatARN(handlers_rds.ResourceKindDBInstance, "ap-southeast-2", "999988887777", "orders-db") err := gw.RDS_Request(httptest.NewRecorder(), setupRDSUserRequest("Action=ListTagsForResource&ResourceName="+foreign, rdsTestAccountID)) require.Error(t, err) diff --git a/spinifex/handlers/rds/arn.go b/spinifex/handlers/rds/arn.go index 61e9fbb77..39da7171f 100644 --- a/spinifex/handlers/rds/arn.go +++ b/spinifex/handlers/rds/arn.go @@ -11,25 +11,7 @@ import ( // ECS/EKS ARNs, so resource-scoped IAM policies and Terraform state round-trip // against the real service. -func DBInstanceARN(region, accountID, dbInstanceIdentifier string) string { - return FormatARN(ResourceKindDBInstance, region, accountID, dbInstanceIdentifier) -} - -// Manual and automated snapshots share the one resource type. -func DBSnapshotARN(region, accountID, dbSnapshotIdentifier string) string { - return FormatARN(ResourceKindDBSnapshot, region, accountID, dbSnapshotIdentifier) -} - -func DBSubnetGroupARN(region, accountID, name string) string { - return FormatARN(ResourceKindDBSubnetGroup, region, accountID, name) -} - -func DBParameterGroupARN(region, accountID, name string) string { - return FormatARN(ResourceKindDBParameterGroup, region, accountID, name) -} - -// The one place the ARN shape is written, for callers that already hold a kind -// rather than a resource type of their own. +// The one place the ARN shape is written. func FormatARN(kind ResourceKind, region, accountID, identifier string) string { return fmt.Sprintf("arn:aws:rds:%s:%s:%s:%s", region, accountID, kind, identifier) } @@ -39,7 +21,8 @@ func FormatARN(kind ResourceKind, region, accountID, identifier string) string { type ResourceKind string const ( - ResourceKindDBInstance ResourceKind = "db" + ResourceKindDBInstance ResourceKind = "db" + // Manual and automated snapshots share the one resource type. ResourceKindDBSnapshot ResourceKind = "snapshot" ResourceKindDBSubnetGroup ResourceKind = "subgrp" ResourceKindDBParameterGroup ResourceKind = "pg" diff --git a/spinifex/handlers/rds/arn_parse_test.go b/spinifex/handlers/rds/arn_parse_test.go index b249c5b24..e988980f9 100644 --- a/spinifex/handlers/rds/arn_parse_test.go +++ b/spinifex/handlers/rds/arn_parse_test.go @@ -19,11 +19,11 @@ func TestParseARN_RoundTripsEveryResourceType(t *testing.T) { identifier string arn string }{ - {"instance", ResourceKindDBInstance, "orders-db", DBInstanceARN(testRegion, testAccountID, "orders-db")}, - {"manual snapshot", ResourceKindDBSnapshot, "orders-db-2026-07-24", DBSnapshotARN(testRegion, testAccountID, "orders-db-2026-07-24")}, - {"automated snapshot", ResourceKindDBSnapshot, automated, DBSnapshotARN(testRegion, testAccountID, automated)}, - {"subnet group", ResourceKindDBSubnetGroup, "prod-db-subnets", DBSubnetGroupARN(testRegion, testAccountID, "prod-db-subnets")}, - {"parameter group", ResourceKindDBParameterGroup, "postgres16-tuned", DBParameterGroupARN(testRegion, testAccountID, "postgres16-tuned")}, + {"instance", ResourceKindDBInstance, "orders-db", FormatARN(ResourceKindDBInstance, testRegion, testAccountID, "orders-db")}, + {"manual snapshot", ResourceKindDBSnapshot, "orders-db-2026-07-24", FormatARN(ResourceKindDBSnapshot, testRegion, testAccountID, "orders-db-2026-07-24")}, + {"automated snapshot", ResourceKindDBSnapshot, automated, FormatARN(ResourceKindDBSnapshot, testRegion, testAccountID, automated)}, + {"subnet group", ResourceKindDBSubnetGroup, "prod-db-subnets", FormatARN(ResourceKindDBSubnetGroup, testRegion, testAccountID, "prod-db-subnets")}, + {"parameter group", ResourceKindDBParameterGroup, "postgres16-tuned", FormatARN(ResourceKindDBParameterGroup, testRegion, testAccountID, "postgres16-tuned")}, } for _, tc := range cases { @@ -47,18 +47,18 @@ func TestParseARN_RejectsMalformedAndForeignARNs(t *testing.T) { // "db/orders-db" as the resource type. {"slash delimited", "arn:aws:rds:" + testRegion + ":" + testAccountID + ":db/orders-db"}, {"truncated", "arn:aws:rds:" + testRegion + ":" + testAccountID + ":db"}, - {"extra segment", DBInstanceARN(testRegion, testAccountID, "orders-db") + ":extra"}, - {"snapshot with a foreign namespace", DBSnapshotARN(testRegion, testAccountID, "other:orders-db")}, - {"snapshot with two embedded colons", DBSnapshotARN(testRegion, testAccountID, "rds:orders-db:extra")}, - {"snapshot with a slash", DBSnapshotARN(testRegion, testAccountID, "rds:orders/db")}, + {"extra segment", FormatARN(ResourceKindDBInstance, testRegion, testAccountID, "orders-db") + ":extra"}, + {"snapshot with a foreign namespace", FormatARN(ResourceKindDBSnapshot, testRegion, testAccountID, "other:orders-db")}, + {"snapshot with two embedded colons", FormatARN(ResourceKindDBSnapshot, testRegion, testAccountID, "rds:orders-db:extra")}, + {"snapshot with a slash", FormatARN(ResourceKindDBSnapshot, testRegion, testAccountID, "rds:orders/db")}, {"empty identifier", "arn:aws:rds:" + testRegion + ":" + testAccountID + ":db:"}, {"another service", "arn:aws:ec2:" + testRegion + ":" + testAccountID + ":db:orders-db"}, {"another partition", "arn:aws-cn:rds:" + testRegion + ":" + testAccountID + ":db:orders-db"}, {"unknown resource type", "arn:aws:rds:" + testRegion + ":" + testAccountID + ":cluster:orders"}, // Rejected at the ARN rather than at policy evaluation, so a foreign // reference never reaches the evaluator at all. - {"foreign account", DBInstanceARN(testRegion, "210987654321", "orders-db")}, - {"foreign region", DBInstanceARN("us-east-1", testAccountID, "orders-db")}, + {"foreign account", FormatARN(ResourceKindDBInstance, testRegion, "210987654321", "orders-db")}, + {"foreign region", FormatARN(ResourceKindDBInstance, "us-east-1", testAccountID, "orders-db")}, {"empty", ""}, } diff --git a/spinifex/handlers/rds/arn_test.go b/spinifex/handlers/rds/arn_test.go index 1239eb826..9054304b2 100644 --- a/spinifex/handlers/rds/arn_test.go +++ b/spinifex/handlers/rds/arn_test.go @@ -11,14 +11,14 @@ const ( testAccountID = "123456789012" ) -func TestARNBuilders(t *testing.T) { +func TestFormatARN(t *testing.T) { t.Parallel() assert.Equal(t, "arn:aws:rds:ap-southeast-2:123456789012:db:orders-db", - DBInstanceARN(testRegion, testAccountID, "orders-db")) + FormatARN(ResourceKindDBInstance, testRegion, testAccountID, "orders-db")) assert.Equal(t, "arn:aws:rds:ap-southeast-2:123456789012:snapshot:orders-db-2026-07-24", - DBSnapshotARN(testRegion, testAccountID, "orders-db-2026-07-24")) + FormatARN(ResourceKindDBSnapshot, testRegion, testAccountID, "orders-db-2026-07-24")) assert.Equal(t, "arn:aws:rds:ap-southeast-2:123456789012:subgrp:prod-db-subnets", - DBSubnetGroupARN(testRegion, testAccountID, "prod-db-subnets")) + FormatARN(ResourceKindDBSubnetGroup, testRegion, testAccountID, "prod-db-subnets")) assert.Equal(t, "arn:aws:rds:ap-southeast-2:123456789012:pg:postgres16-tuned", - DBParameterGroupARN(testRegion, testAccountID, "postgres16-tuned")) + FormatARN(ResourceKindDBParameterGroup, testRegion, testAccountID, "postgres16-tuned")) } diff --git a/spinifex/handlers/rds/backup.go b/spinifex/handlers/rds/backup.go index 5d79b3141..be967db6c 100644 --- a/spinifex/handlers/rds/backup.go +++ b/spinifex/handlers/rds/backup.go @@ -472,7 +472,7 @@ func (s *Service) projectAutomatedBackup(rec *DBInstanceRecord, snapshots int) * } out := &rds.DBInstanceAutomatedBackup{ DBInstanceIdentifier: aws.String(rec.DBInstanceIdentifier), - DBInstanceArn: aws.String(DBInstanceARN(s.region, rec.AccountID, rec.DBInstanceIdentifier)), + DBInstanceArn: aws.String(FormatARN(ResourceKindDBInstance, s.region, rec.AccountID, rec.DBInstanceIdentifier)), Region: aws.String(s.region), Status: aws.String(status), Engine: aws.String(rec.Engine), diff --git a/spinifex/handlers/rds/backup_test.go b/spinifex/handlers/rds/backup_test.go index eeb401c7a..b69b84c0c 100644 --- a/spinifex/handlers/rds/backup_test.go +++ b/spinifex/handlers/rds/backup_test.go @@ -734,7 +734,7 @@ func TestDescribeDBInstanceAutomatedBackups_ReportsTheBackupSet(t *testing.T) { backup := out.DBInstanceAutomatedBackups[0] assert.Equal(t, "active", aws.StringValue(backup.Status)) assert.Equal(t, testDBID, aws.StringValue(backup.DBInstanceIdentifier)) - assert.Equal(t, DBInstanceARN(testRegion, testAccountID, testDBID), aws.StringValue(backup.DBInstanceArn)) + assert.Equal(t, FormatARN(ResourceKindDBInstance, testRegion, testAccountID, testDBID), aws.StringValue(backup.DBInstanceArn)) assert.Equal(t, int64(7), aws.Int64Value(backup.BackupRetentionPeriod)) assert.Equal(t, testRegion, aws.StringValue(backup.Region)) diff --git a/spinifex/handlers/rds/create_test.go b/spinifex/handlers/rds/create_test.go index ecb1744fe..a0018a63e 100644 --- a/spinifex/handlers/rds/create_test.go +++ b/spinifex/handlers/rds/create_test.go @@ -252,7 +252,7 @@ func TestCreateDBInstance_ProvisionsAndRecordsTheInstance(t *testing.T) { require.NotNil(t, out.DBInstance) assert.Equal(t, string(StatusCreating), aws.StringValue(out.DBInstance.DBInstanceStatus)) assert.Equal(t, "postgres", aws.StringValue(out.DBInstance.Engine)) - assert.Equal(t, DBInstanceARN(testRegion, testAccountID, testDBInstanceID), + assert.Equal(t, FormatARN(ResourceKindDBInstance, testRegion, testAccountID, testDBInstanceID), aws.StringValue(out.DBInstance.DBInstanceArn)) require.NotNil(t, out.DBInstance.Endpoint) assert.Equal(t, testDBInstanceID+"."+testAccountID+"."+testRegion+".rds."+testBaseDomain, diff --git a/spinifex/handlers/rds/describe.go b/spinifex/handlers/rds/describe.go index 6dab74bd6..63f3959d5 100644 --- a/spinifex/handlers/rds/describe.go +++ b/spinifex/handlers/rds/describe.go @@ -136,7 +136,7 @@ func (s *Service) projectDBInstance(rec *DBInstanceRecord) *rds.DBInstance { } out := &rds.DBInstance{ DBInstanceIdentifier: aws.String(rec.DBInstanceIdentifier), - DBInstanceArn: aws.String(DBInstanceARN(s.region, rec.AccountID, rec.DBInstanceIdentifier)), + DBInstanceArn: aws.String(FormatARN(ResourceKindDBInstance, s.region, rec.AccountID, rec.DBInstanceIdentifier)), DBInstanceStatus: aws.String(string(rec.Status)), Engine: aws.String(rec.Engine), EngineVersion: aws.String(rec.EngineVersion), diff --git a/spinifex/handlers/rds/events.go b/spinifex/handlers/rds/events.go index 91986e88a..35b5e42d2 100644 --- a/spinifex/handlers/rds/events.go +++ b/spinifex/handlers/rds/events.go @@ -235,9 +235,9 @@ func (s *Service) projectEvent(accountID string, event Event) *rds.Event { } switch event.SourceType { case EventSourceTypeDBInstance: - out.SourceArn = aws.String(DBInstanceARN(s.region, accountID, event.SourceIdentifier)) + out.SourceArn = aws.String(FormatARN(ResourceKindDBInstance, s.region, accountID, event.SourceIdentifier)) case EventSourceTypeDBSnapshot: - out.SourceArn = aws.String(DBSnapshotARN(s.region, accountID, event.SourceIdentifier)) + out.SourceArn = aws.String(FormatARN(ResourceKindDBSnapshot, s.region, accountID, event.SourceIdentifier)) } return out } diff --git a/spinifex/handlers/rds/events_test.go b/spinifex/handlers/rds/events_test.go index 0d7438d2e..2094b4e23 100644 --- a/spinifex/handlers/rds/events_test.go +++ b/spinifex/handlers/rds/events_test.go @@ -52,7 +52,7 @@ func TestDescribeEvents_ReturnsARecordedEventWithItsSourceARN(t *testing.T) { assert.Equal(t, EventSourceTypeDBInstance, aws.StringValue(events[0].SourceType)) assert.Equal(t, "DB instance stopped.", aws.StringValue(events[0].Message)) assert.Equal(t, []string{EventCategoryAvailability}, aws.StringValueSlice(events[0].EventCategories)) - assert.Equal(t, DBInstanceARN(testRegion, testAccountID, testDBID), aws.StringValue(events[0].SourceArn)) + assert.Equal(t, FormatARN(ResourceKindDBInstance, testRegion, testAccountID, testDBID), aws.StringValue(events[0].SourceArn)) } // AWS's default window is one hour, so an event outside it is not returned even diff --git a/spinifex/handlers/rds/parametergroup.go b/spinifex/handlers/rds/parametergroup.go index c812cd8ca..ca615d067 100644 --- a/spinifex/handlers/rds/parametergroup.go +++ b/spinifex/handlers/rds/parametergroup.go @@ -500,7 +500,7 @@ func (s *Service) projectParameterGroupRecord(rec *DBParameterGroupRecord) *rds. return &rds.DBParameterGroup{ DBParameterGroupName: aws.String(rec.Name), DBParameterGroupFamily: aws.String(rec.Family), - DBParameterGroupArn: aws.String(DBParameterGroupARN(s.region, rec.AccountID, rec.Name)), + DBParameterGroupArn: aws.String(FormatARN(ResourceKindDBParameterGroup, s.region, rec.AccountID, rec.Name)), Description: aws.String(rec.Description), } } diff --git a/spinifex/handlers/rds/parametergroup_test.go b/spinifex/handlers/rds/parametergroup_test.go index 15c3954a8..322bafede 100644 --- a/spinifex/handlers/rds/parametergroup_test.go +++ b/spinifex/handlers/rds/parametergroup_test.go @@ -77,7 +77,7 @@ func TestCreateDBParameterGroup_StoresAnEmptyGroup(t *testing.T) { require.NotNil(t, group) assert.Equal(t, testParameterGroup, aws.StringValue(group.DBParameterGroupName)) assert.Equal(t, "postgres18", aws.StringValue(group.DBParameterGroupFamily)) - assert.Equal(t, DBParameterGroupARN(testRegion, testAccountID, testParameterGroup), + assert.Equal(t, FormatARN(ResourceKindDBParameterGroup, testRegion, testAccountID, testParameterGroup), aws.StringValue(group.DBParameterGroupArn)) // A fresh group and the default group resolve to the same effective set, @@ -737,8 +737,8 @@ func TestTagActions_ReachBothGroupTypes(t *testing.T) { require.NoError(t, err) for _, arn := range []string{ - DBSubnetGroupARN(testRegion, testAccountID, testSubnetGroup), - DBParameterGroupARN(testRegion, testAccountID, testParameterGroup), + FormatARN(ResourceKindDBSubnetGroup, testRegion, testAccountID, testSubnetGroup), + FormatARN(ResourceKindDBParameterGroup, testRegion, testAccountID, testParameterGroup), } { _, err := h.svc.AddTagsToResource(t.Context(), &rds.AddTagsToResourceInput{ ResourceName: aws.String(arn), diff --git a/spinifex/handlers/rds/snapshot.go b/spinifex/handlers/rds/snapshot.go index d500298a2..c00dc28b9 100644 --- a/spinifex/handlers/rds/snapshot.go +++ b/spinifex/handlers/rds/snapshot.go @@ -686,7 +686,7 @@ func (s *Service) projectDBSnapshot(rec *DBSnapshotRecord) *rds.DBSnapshot { } out := &rds.DBSnapshot{ DBSnapshotIdentifier: aws.String(rec.DBSnapshotIdentifier), - DBSnapshotArn: aws.String(DBSnapshotARN(s.region, rec.AccountID, rec.DBSnapshotIdentifier)), + DBSnapshotArn: aws.String(FormatARN(ResourceKindDBSnapshot, s.region, rec.AccountID, rec.DBSnapshotIdentifier)), DBInstanceIdentifier: aws.String(rec.DBInstanceIdentifier), SnapshotType: aws.String(rec.SnapshotType), Status: aws.String(rec.Status), diff --git a/spinifex/handlers/rds/snapshot_test.go b/spinifex/handlers/rds/snapshot_test.go index 761915381..f91731a2f 100644 --- a/spinifex/handlers/rds/snapshot_test.go +++ b/spinifex/handlers/rds/snapshot_test.go @@ -142,7 +142,7 @@ func TestCreateDBSnapshot_QuiescesTheEngineAndRecordsTheSnapshot(t *testing.T) { assert.Equal(t, testSnapshotID, aws.StringValue(out.DBSnapshot.DBSnapshotIdentifier)) assert.Equal(t, SnapshotStatusAvailable, aws.StringValue(out.DBSnapshot.Status)) assert.Equal(t, SnapshotTypeManual, aws.StringValue(out.DBSnapshot.SnapshotType)) - assert.Equal(t, DBSnapshotARN(testRegion, testAccountID, testSnapshotID), + assert.Equal(t, FormatARN(ResourceKindDBSnapshot, testRegion, testAccountID, testSnapshotID), aws.StringValue(out.DBSnapshot.DBSnapshotArn)) // The engine is held at a checkpoint for the length of the EC2 call and let @@ -818,14 +818,14 @@ func TestDBSnapshotTags_ReadBackThroughBothPaths(t *testing.T) { require.Len(t, out.DBSnapshot.TagList, 1) listed, err := h.svc.ListTagsForResource(t.Context(), &rds.ListTagsForResourceInput{ - ResourceName: aws.String(DBSnapshotARN(testRegion, testAccountID, testSnapshotID)), + ResourceName: aws.String(FormatARN(ResourceKindDBSnapshot, testRegion, testAccountID, testSnapshotID)), }, testAccountID) require.NoError(t, err) require.Len(t, listed.TagList, 1) assert.Equal(t, "prod", aws.StringValue(listed.TagList[0].Value)) _, err = h.svc.AddTagsToResource(t.Context(), &rds.AddTagsToResourceInput{ - ResourceName: aws.String(DBSnapshotARN(testRegion, testAccountID, testSnapshotID)), + ResourceName: aws.String(FormatARN(ResourceKindDBSnapshot, testRegion, testAccountID, testSnapshotID)), Tags: []*rds.Tag{{Key: aws.String("team"), Value: aws.String("payments")}}, }, testAccountID) require.NoError(t, err) diff --git a/spinifex/handlers/rds/subnetgroup.go b/spinifex/handlers/rds/subnetgroup.go index 18728cfbf..656648631 100644 --- a/spinifex/handlers/rds/subnetgroup.go +++ b/spinifex/handlers/rds/subnetgroup.go @@ -277,7 +277,7 @@ func (s *Service) projectSubnetGroup(rec *DBSubnetGroupRecord) *rds.DBSubnetGrou out := &rds.DBSubnetGroup{ DBSubnetGroupName: aws.String(rec.Name), DBSubnetGroupDescription: aws.String(rec.Description), - DBSubnetGroupArn: aws.String(DBSubnetGroupARN(s.region, rec.AccountID, rec.Name)), + DBSubnetGroupArn: aws.String(FormatARN(ResourceKindDBSubnetGroup, s.region, rec.AccountID, rec.Name)), SubnetGroupStatus: aws.String(subnetGroupStatusComplete), VpcId: aws.String(rec.VpcID), } diff --git a/spinifex/handlers/rds/subnetgroup_test.go b/spinifex/handlers/rds/subnetgroup_test.go index f344dd773..da3b9afb1 100644 --- a/spinifex/handlers/rds/subnetgroup_test.go +++ b/spinifex/handlers/rds/subnetgroup_test.go @@ -34,7 +34,7 @@ func TestCreateDBSubnetGroup_AcceptsASingleSubnet(t *testing.T) { group := out.DBSubnetGroup require.NotNil(t, group) assert.Equal(t, testSubnetGroup, aws.StringValue(group.DBSubnetGroupName)) - assert.Equal(t, DBSubnetGroupARN(testRegion, testAccountID, testSubnetGroup), + assert.Equal(t, FormatARN(ResourceKindDBSubnetGroup, testRegion, testAccountID, testSubnetGroup), aws.StringValue(group.DBSubnetGroupArn)) assert.Equal(t, testDefaultVPC, aws.StringValue(group.VpcId)) require.Len(t, group.Subnets, 1) diff --git a/spinifex/handlers/rds/tags_test.go b/spinifex/handlers/rds/tags_test.go index 046709724..7c58d342f 100644 --- a/spinifex/handlers/rds/tags_test.go +++ b/spinifex/handlers/rds/tags_test.go @@ -27,7 +27,7 @@ func awsTags(kv ...string) []*rds.Tag { func listTags(t *testing.T, h *createHarness, id string) map[string]string { t.Helper() out, err := h.svc.ListTagsForResource(t.Context(), &rds.ListTagsForResourceInput{ - ResourceName: aws.String(DBInstanceARN(testRegion, testAccountID, id)), + ResourceName: aws.String(FormatARN(ResourceKindDBInstance, testRegion, testAccountID, id)), }, testAccountID) require.NoError(t, err) got := make(map[string]string, len(out.TagList)) @@ -88,7 +88,7 @@ func TestAddTagsToResource_MergesAndOverwrites(t *testing.T) { t.Parallel() h := newCreateHarness(t, "") seedCreated(t, h, testDBInstanceID) - arn := aws.String(DBInstanceARN(testRegion, testAccountID, testDBInstanceID)) + arn := aws.String(FormatARN(ResourceKindDBInstance, testRegion, testAccountID, testDBInstanceID)) _, err := h.svc.AddTagsToResource(t.Context(), &rds.AddTagsToResourceInput{ ResourceName: arn, Tags: awsTags("env", "staging", "team", "platform"), @@ -111,7 +111,7 @@ func TestAddTagsToResource_DuplicateKeyInOneRequestKeepsTheLastValue(t *testing. seedCreated(t, h, testDBInstanceID) _, err := h.svc.AddTagsToResource(t.Context(), &rds.AddTagsToResourceInput{ - ResourceName: aws.String(DBInstanceARN(testRegion, testAccountID, testDBInstanceID)), + ResourceName: aws.String(FormatARN(ResourceKindDBInstance, testRegion, testAccountID, testDBInstanceID)), Tags: awsTags("env", "staging", "env", "prod"), }, testAccountID) require.NoError(t, err) @@ -123,7 +123,7 @@ func TestRemoveTagsFromResource_RemovesNamedKeysAndIgnoresAbsentOnes(t *testing. t.Parallel() h := newCreateHarness(t, "") seedCreated(t, h, testDBInstanceID) - arn := aws.String(DBInstanceARN(testRegion, testAccountID, testDBInstanceID)) + arn := aws.String(FormatARN(ResourceKindDBInstance, testRegion, testAccountID, testDBInstanceID)) _, err := h.svc.AddTagsToResource(t.Context(), &rds.AddTagsToResourceInput{ ResourceName: arn, Tags: awsTags("env", "prod", "team", "platform"), @@ -164,7 +164,7 @@ func TestTagActions_RejectInvalidTags(t *testing.T) { seedCreated(t, h, testDBInstanceID) _, err := h.svc.AddTagsToResource(t.Context(), &rds.AddTagsToResourceInput{ - ResourceName: aws.String(DBInstanceARN(testRegion, testAccountID, testDBInstanceID)), + ResourceName: aws.String(FormatARN(ResourceKindDBInstance, testRegion, testAccountID, testDBInstanceID)), Tags: tc.tags, }, testAccountID) require.Error(t, err) @@ -180,7 +180,7 @@ func TestAddTagsToResource_LimitAppliesToTheMergedResult(t *testing.T) { t.Parallel() h := newCreateHarness(t, "") seedCreated(t, h, testDBInstanceID) - arn := aws.String(DBInstanceARN(testRegion, testAccountID, testDBInstanceID)) + arn := aws.String(FormatARN(ResourceKindDBInstance, testRegion, testAccountID, testDBInstanceID)) half := make([]string, 0, maxTagsPerResource) for i := range maxTagsPerResource / 2 { @@ -209,7 +209,7 @@ func TestAddTagsToResource_LimitAppliesToTheMergedResult(t *testing.T) { func TestTagActions_MissingResourceIsTheResourcesOwnFault(t *testing.T) { t.Parallel() h := newCreateHarness(t, "") - arn := aws.String(DBInstanceARN(testRegion, testAccountID, "no-such-db")) + arn := aws.String(FormatARN(ResourceKindDBInstance, testRegion, testAccountID, "no-such-db")) _, err := h.svc.ListTagsForResource(t.Context(), &rds.ListTagsForResourceInput{ResourceName: arn}, testAccountID) require.Error(t, err) @@ -235,7 +235,7 @@ func TestTagActions_MissingSnapshotIsRejected(t *testing.T) { h := newCreateHarness(t, "") _, err := h.svc.ListTagsForResource(t.Context(), &rds.ListTagsForResourceInput{ - ResourceName: aws.String(DBSnapshotARN(testRegion, testAccountID, "orders-db-snap")), + ResourceName: aws.String(FormatARN(ResourceKindDBSnapshot, testRegion, testAccountID, "orders-db-snap")), }, testAccountID) require.Error(t, err) assert.Contains(t, err.Error(), awserrors.ErrorDBSnapshotNotFound) @@ -254,7 +254,7 @@ func TestListTagsForResource_AcceptsAnAutomatedSnapshotARN(t *testing.T) { })) out, err := h.svc.ListTagsForResource(t.Context(), &rds.ListTagsForResourceInput{ - ResourceName: aws.String(DBSnapshotARN(testRegion, testAccountID, id)), + ResourceName: aws.String(FormatARN(ResourceKindDBSnapshot, testRegion, testAccountID, id)), }, testAccountID) require.NoError(t, err) assert.Equal(t, awsTags("retention", "automated"), out.TagList) @@ -266,7 +266,7 @@ func TestTagActions_ForeignAccountARNIsRejected(t *testing.T) { seedCreated(t, h, testDBInstanceID) _, err := h.svc.ListTagsForResource(t.Context(), &rds.ListTagsForResourceInput{ - ResourceName: aws.String(DBInstanceARN(testRegion, "210987654321", testDBInstanceID)), + ResourceName: aws.String(FormatARN(ResourceKindDBInstance, testRegion, "210987654321", testDBInstanceID)), }, testAccountID) require.Error(t, err) assert.Contains(t, err.Error(), awserrors.ErrorInvalidParameterValue) @@ -278,7 +278,7 @@ func TestTagWrites_ConcurrentAddsAndRemovesDoNotLoseEachOther(t *testing.T) { t.Parallel() h := newCreateHarness(t, "") seedCreated(t, h, testDBInstanceID) - arn := aws.String(DBInstanceARN(testRegion, testAccountID, testDBInstanceID)) + arn := aws.String(FormatARN(ResourceKindDBInstance, testRegion, testAccountID, testDBInstanceID)) // Seeded first so the concurrent removes have something to take away. const writers = 4