From 53ccdd6af3fc19da8ae3779a84fe57c8ddfa1f6d Mon Sep 17 00:00:00 2001 From: Julian Sommer <115516918+juliansommer@users.noreply.github.com> Date: Tue, 25 Aug 2026 09:55:51 +1000 Subject: [PATCH] chore: more rds simplifications --- spinifex/arn/ec2_test.go | 41 +++++++++++++------------- spinifex/daemon/cas_conflict_test.go | 4 +++ spinifex/gateway/conditionkeys_test.go | 4 +++ spinifex/handlers/rds/backup.go | 2 +- spinifex/handlers/rds/backup_sweep.go | 4 +-- spinifex/handlers/rds/backup_test.go | 2 +- spinifex/handlers/rds/store.go | 14 --------- spinifex/handlers/rds/subnetgroup.go | 2 +- 8 files changed, 34 insertions(+), 39 deletions(-) diff --git a/spinifex/arn/ec2_test.go b/spinifex/arn/ec2_test.go index 5d7158554..229fc63fd 100644 --- a/spinifex/arn/ec2_test.go +++ b/spinifex/arn/ec2_test.go @@ -1,32 +1,33 @@ -package arn +package arn_test import ( "testing" + "github.com/mulgadc/spinifex/spinifex/arn" "github.com/stretchr/testify/assert" ) func TestEC2TypeForID(t *testing.T) { tests := []struct { resourceID string - want EC2ResourceType + want arn.EC2ResourceType wantOK bool }{ - {"i-abc123", EC2Instance, true}, - {"vol-abc123", EC2Volume, true}, - {"ami-abc123", EC2Image, true}, - {"snap-abc123", EC2Snapshot, true}, - {"vpc-abc123", EC2VPC, true}, - {"subnet-abc123", EC2Subnet, true}, - {"sg-abc123", EC2SecurityGroup, true}, - {"rtb-abc123", EC2RouteTable, true}, - {"igw-abc123", EC2InternetGateway, true}, - {"eigw-abc123", EC2EgressOnlyInternetGateway, true}, - {"eni-abc123", EC2NetworkInterface, true}, - {"eipalloc-abc123", EC2ElasticIP, true}, - {"nat-abc123", EC2NATGateway, true}, - {"key-abc123", EC2KeyPair, true}, - {"pg-abc123", EC2PlacementGroup, true}, + {"i-abc123", arn.EC2Instance, true}, + {"vol-abc123", arn.EC2Volume, true}, + {"ami-abc123", arn.EC2Image, true}, + {"snap-abc123", arn.EC2Snapshot, true}, + {"vpc-abc123", arn.EC2VPC, true}, + {"subnet-abc123", arn.EC2Subnet, true}, + {"sg-abc123", arn.EC2SecurityGroup, true}, + {"rtb-abc123", arn.EC2RouteTable, true}, + {"igw-abc123", arn.EC2InternetGateway, true}, + {"eigw-abc123", arn.EC2EgressOnlyInternetGateway, true}, + {"eni-abc123", arn.EC2NetworkInterface, true}, + {"eipalloc-abc123", arn.EC2ElasticIP, true}, + {"nat-abc123", arn.EC2NATGateway, true}, + {"key-abc123", arn.EC2KeyPair, true}, + {"pg-abc123", arn.EC2PlacementGroup, true}, {"unknown-abc123", "", false}, {"", "", false}, {"i", "", false}, @@ -34,7 +35,7 @@ func TestEC2TypeForID(t *testing.T) { for _, tc := range tests { t.Run(tc.resourceID, func(t *testing.T) { - got, ok := EC2TypeForID(tc.resourceID) + got, ok := arn.EC2TypeForID(tc.resourceID) assert.Equal(t, tc.wantOK, ok) assert.Equal(t, tc.want, got) }) @@ -44,11 +45,11 @@ func TestEC2TypeForID(t *testing.T) { func TestFormatEC2(t *testing.T) { assert.Equal(t, "arn:aws:ec2:us-east-1:123456789012:subnet/subnet-abc", - FormatEC2(EC2Subnet, "us-east-1", "123456789012", "subnet-abc")) + arn.FormatEC2(arn.EC2Subnet, "us-east-1", "123456789012", "subnet-abc")) // A literal * is a value, not a pattern: it neither matches a scoped Deny // nor widens a grant. assert.Equal(t, "arn:aws:ec2:ap-southeast-2:123456789012:instance/*", - FormatEC2(EC2Instance, "ap-southeast-2", "123456789012", "*")) + arn.FormatEC2(arn.EC2Instance, "ap-southeast-2", "123456789012", "*")) } diff --git a/spinifex/daemon/cas_conflict_test.go b/spinifex/daemon/cas_conflict_test.go index 7643cbb04..7e89f607a 100644 --- a/spinifex/daemon/cas_conflict_test.go +++ b/spinifex/daemon/cas_conflict_test.go @@ -1,3 +1,7 @@ +//test:in-package — drives the unexported CAS primitives (casUpdate, casPut and +//the generic casClaim[T]) against maxCASRetries. A generic function cannot be +//re-exported through export_test.go without a wrapper per instantiation. + package daemon import ( diff --git a/spinifex/gateway/conditionkeys_test.go b/spinifex/gateway/conditionkeys_test.go index f3f27b875..f51a3f87c 100644 --- a/spinifex/gateway/conditionkeys_test.go +++ b/spinifex/gateway/conditionkeys_test.go @@ -1,3 +1,7 @@ +//test:in-package — requestConditionKeys, checkPolicyResources, principalContext +//and ctxAccountID are all unexported, and the file reuses the in-package +//policyMockIAMService and withTestIdentity doubles. + package gateway import ( diff --git a/spinifex/handlers/rds/backup.go b/spinifex/handlers/rds/backup.go index be967db6c..ac5e94bd2 100644 --- a/spinifex/handlers/rds/backup.go +++ b/spinifex/handlers/rds/backup.go @@ -430,7 +430,7 @@ func (s *Service) DescribeDBInstanceAutomatedBackups(ctx context.Context, if rec.BackupRetentionPeriod <= 0 { continue } - stamps, err := ListAutomatedBackupStamps(ctx, kv, id) + stamps, err := listNames(ctx, kv, AutomatedBackupsPrefix(id)) if err != nil { return nil, err } diff --git a/spinifex/handlers/rds/backup_sweep.go b/spinifex/handlers/rds/backup_sweep.go index eedee421f..15a07674e 100644 --- a/spinifex/handlers/rds/backup_sweep.go +++ b/spinifex/handlers/rds/backup_sweep.go @@ -292,7 +292,7 @@ func (s *Service) dropAutomatedBackupIndex(ctx context.Context, kv jetstream.Key // volume after the instance is gone. func (s *Service) purgeAutomatedBackups(ctx context.Context, kv jetstream.KeyValue, accountID, dbInstanceIdentifier string) error { - stamps, err := ListAutomatedBackupStamps(ctx, kv, dbInstanceIdentifier) + stamps, err := listNames(ctx, kv, AutomatedBackupsPrefix(dbInstanceIdentifier)) if err != nil { return err } @@ -314,7 +314,7 @@ func (s *Service) purgeAutomatedBackups(ctx context.Context, kv jetstream.KeyVal // for a crash between those two steps — which is precisely what a KV-health-gated // cluster-wide sweep is for. func (s *Service) reclaimOrphanedVolumes(ctx context.Context, kv jetstream.KeyValue) (int, error) { - ids, err := ListRetainedVolumeIDs(ctx, kv) + ids, err := listNames(ctx, kv, RetainedVolumesPrefix()) if err != nil { return 0, err } diff --git a/spinifex/handlers/rds/backup_test.go b/spinifex/handlers/rds/backup_test.go index b69b84c0c..89e56336c 100644 --- a/spinifex/handlers/rds/backup_test.go +++ b/spinifex/handlers/rds/backup_test.go @@ -86,7 +86,7 @@ func (h *snapshotHarness) automatedStamps(t *testing.T, id string) []string { t.Helper() kv, err := h.svc.bucket(t.Context(), testAccountID) require.NoError(t, err) - stamps, err := ListAutomatedBackupStamps(t.Context(), kv, id) + stamps, err := listNames(t.Context(), kv, AutomatedBackupsPrefix(id)) require.NoError(t, err) return stamps } diff --git a/spinifex/handlers/rds/store.go b/spinifex/handlers/rds/store.go index abe214e7b..1277e8b17 100644 --- a/spinifex/handlers/rds/store.go +++ b/spinifex/handlers/rds/store.go @@ -279,10 +279,6 @@ func ListDBSnapshotIDs(ctx context.Context, kv jetstream.KeyValue) ([]string, er return names, nil } -func ListDBSubnetGroupNames(ctx context.Context, kv jetstream.KeyValue) ([]string, error) { - return listNames(ctx, kv, DBSubnetGroupsPrefix()) -} - // Walks the .../meta keys, which is what makes a group's own record findable // among the per-parameter keys hanging off the same prefix. func ListDBParameterGroupNames(ctx context.Context, kv jetstream.KeyValue) ([]string, error) { @@ -347,12 +343,6 @@ func ListAutomatedBackups(ctx context.Context, kv jetstream.KeyValue) (map[strin return indexed, nil } -// One instance's automated-backup stamps, for the callers that already know -// which instance they are acting on. -func ListAutomatedBackupStamps(ctx context.Context, kv jetstream.KeyValue, dbInstanceIdentifier string) ([]string, error) { - return listNames(ctx, kv, AutomatedBackupsPrefix(dbInstanceIdentifier)) -} - // The DB instance and timestamp a backups/ key names. The instance identifier // cannot contain a slash, so anything shaped otherwise belongs to a key space // this does not own. @@ -372,10 +362,6 @@ func splitAutomatedBackupKey(key string) (string, string, bool) { return id, stamp, true } -func ListRetainedVolumeIDs(ctx context.Context, kv jetstream.KeyValue) ([]string, error) { - return listNames(ctx, kv, RetainedVolumesPrefix()) -} - // The leaf names directly under prefix. A nested key belongs to a sub-space and // is skipped rather than reported as a malformed name. func listNames(ctx context.Context, kv jetstream.KeyValue, prefix string) ([]string, error) { diff --git a/spinifex/handlers/rds/subnetgroup.go b/spinifex/handlers/rds/subnetgroup.go index 656648631..ce61a5087 100644 --- a/spinifex/handlers/rds/subnetgroup.go +++ b/spinifex/handlers/rds/subnetgroup.go @@ -105,7 +105,7 @@ func (s *Service) DescribeDBSubnetGroups(ctx context.Context, input *rds.Describ } } - names, err := ListDBSubnetGroupNames(ctx, kv) + names, err := listNames(ctx, kv, DBSubnetGroupsPrefix()) if err != nil { return nil, err }