mirror of
https://github.com/mulgadc/spinifex.git
synced 2026-10-15 09:01:31 +00:00
chore: more rds simplifications
This commit is contained in:
+21
-20
@@ -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", "*"))
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user