From e630703d7558f8d2b74ac500586234d2afcc5f6d Mon Sep 17 00:00:00 2001 From: joshsiv-mulga Date: Wed, 7 Oct 2026 14:23:04 +1000 Subject: [PATCH] refactor: move EC2 key action adapters to domains/ec2/awsapi --- spinifex/accountteardown/reapers_ec2.go | 6 +++--- .../ec2 => domains/ec2/awsapi}/key/CreateKeyPair.go | 2 +- .../ec2/awsapi}/key/CreateKeyPair_test.go | 2 +- .../ec2 => domains/ec2/awsapi}/key/DeleteKeyPair.go | 2 +- .../ec2/awsapi}/key/DeleteKeyPair_test.go | 2 +- .../ec2 => domains/ec2/awsapi}/key/DescribeKeyPairs.go | 2 +- .../ec2 => domains/ec2/awsapi}/key/ImportKeyPair.go | 2 +- .../ec2/awsapi}/key/ImportKeyPair_test.go | 2 +- .../ec2 => domains/ec2/awsapi}/key/handler_test.go | 2 +- spinifex/gateway/ec2.go | 10 +++++----- 10 files changed, 16 insertions(+), 16 deletions(-) rename spinifex/{gateway/ec2 => domains/ec2/awsapi}/key/CreateKeyPair.go (97%) rename spinifex/{gateway/ec2 => domains/ec2/awsapi}/key/CreateKeyPair_test.go (98%) rename spinifex/{gateway/ec2 => domains/ec2/awsapi}/key/DeleteKeyPair.go (97%) rename spinifex/{gateway/ec2 => domains/ec2/awsapi}/key/DeleteKeyPair_test.go (98%) rename spinifex/{gateway/ec2 => domains/ec2/awsapi}/key/DescribeKeyPairs.go (95%) rename spinifex/{gateway/ec2 => domains/ec2/awsapi}/key/ImportKeyPair.go (97%) rename spinifex/{gateway/ec2 => domains/ec2/awsapi}/key/ImportKeyPair_test.go (98%) rename spinifex/{gateway/ec2 => domains/ec2/awsapi}/key/handler_test.go (98%) diff --git a/spinifex/accountteardown/reapers_ec2.go b/spinifex/accountteardown/reapers_ec2.go index c93828545..73ee383bf 100644 --- a/spinifex/accountteardown/reapers_ec2.go +++ b/spinifex/accountteardown/reapers_ec2.go @@ -11,12 +11,12 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/s3" + ec2keyapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/key" "github.com/mulgadc/spinifex/spinifex/foundation/aws/errors" gateway_ec2_eip "github.com/mulgadc/spinifex/spinifex/gateway/ec2/eip" gateway_ec2_igw "github.com/mulgadc/spinifex/spinifex/gateway/ec2/igw" gateway_ec2_image "github.com/mulgadc/spinifex/spinifex/gateway/ec2/image" gateway_ec2_instance "github.com/mulgadc/spinifex/spinifex/gateway/ec2/instance" - gateway_ec2_key "github.com/mulgadc/spinifex/spinifex/gateway/ec2/key" gateway_ec2_launchtemplate "github.com/mulgadc/spinifex/spinifex/gateway/ec2/launchtemplate" gateway_ec2_placementgroup "github.com/mulgadc/spinifex/spinifex/gateway/ec2/placementgroup" gateway_ec2_routetable "github.com/mulgadc/spinifex/spinifex/gateway/ec2/routetable" @@ -568,7 +568,7 @@ func (r *keyPairReaper) Kind() string { return "key-pair" } func (r *keyPairReaper) Stage() Stage { return StagePlatform } func (r *keyPairReaper) List(ctx context.Context, accountID string) ([]Resource, error) { - out, err := gateway_ec2_key.DescribeKeyPairs(ctx, &ec2.DescribeKeyPairsInput{}, r.nc, accountID) + out, err := ec2keyapi.DescribeKeyPairs(ctx, &ec2.DescribeKeyPairsInput{}, r.nc, accountID) if err != nil { return nil, err } @@ -584,7 +584,7 @@ func (r *keyPairReaper) List(ctx context.Context, accountID string) ([]Resource, } func (r *keyPairReaper) Delete(ctx context.Context, accountID string, resource Resource, _ bool) error { - _, err := gateway_ec2_key.DeleteKeyPair(ctx, &ec2.DeleteKeyPairInput{ + _, err := ec2keyapi.DeleteKeyPair(ctx, &ec2.DeleteKeyPairInput{ KeyName: aws.String(resource.ID), }, r.nc, accountID) return ignoreAlreadyGone(err) diff --git a/spinifex/gateway/ec2/key/CreateKeyPair.go b/spinifex/domains/ec2/awsapi/key/CreateKeyPair.go similarity index 97% rename from spinifex/gateway/ec2/key/CreateKeyPair.go rename to spinifex/domains/ec2/awsapi/key/CreateKeyPair.go index 667af9f2b..c4d869baf 100644 --- a/spinifex/gateway/ec2/key/CreateKeyPair.go +++ b/spinifex/domains/ec2/awsapi/key/CreateKeyPair.go @@ -1,4 +1,4 @@ -package gateway_ec2_key +package key import ( "context" diff --git a/spinifex/gateway/ec2/key/CreateKeyPair_test.go b/spinifex/domains/ec2/awsapi/key/CreateKeyPair_test.go similarity index 98% rename from spinifex/gateway/ec2/key/CreateKeyPair_test.go rename to spinifex/domains/ec2/awsapi/key/CreateKeyPair_test.go index bac2a4423..e681761c3 100644 --- a/spinifex/gateway/ec2/key/CreateKeyPair_test.go +++ b/spinifex/domains/ec2/awsapi/key/CreateKeyPair_test.go @@ -1,4 +1,4 @@ -package gateway_ec2_key +package key import ( "testing" diff --git a/spinifex/gateway/ec2/key/DeleteKeyPair.go b/spinifex/domains/ec2/awsapi/key/DeleteKeyPair.go similarity index 97% rename from spinifex/gateway/ec2/key/DeleteKeyPair.go rename to spinifex/domains/ec2/awsapi/key/DeleteKeyPair.go index 5b97d2440..74a7af0c6 100644 --- a/spinifex/gateway/ec2/key/DeleteKeyPair.go +++ b/spinifex/domains/ec2/awsapi/key/DeleteKeyPair.go @@ -1,4 +1,4 @@ -package gateway_ec2_key +package key import ( "context" diff --git a/spinifex/gateway/ec2/key/DeleteKeyPair_test.go b/spinifex/domains/ec2/awsapi/key/DeleteKeyPair_test.go similarity index 98% rename from spinifex/gateway/ec2/key/DeleteKeyPair_test.go rename to spinifex/domains/ec2/awsapi/key/DeleteKeyPair_test.go index 360199a16..5d7aa5144 100644 --- a/spinifex/gateway/ec2/key/DeleteKeyPair_test.go +++ b/spinifex/domains/ec2/awsapi/key/DeleteKeyPair_test.go @@ -1,4 +1,4 @@ -package gateway_ec2_key +package key import ( "testing" diff --git a/spinifex/gateway/ec2/key/DescribeKeyPairs.go b/spinifex/domains/ec2/awsapi/key/DescribeKeyPairs.go similarity index 95% rename from spinifex/gateway/ec2/key/DescribeKeyPairs.go rename to spinifex/domains/ec2/awsapi/key/DescribeKeyPairs.go index 4b547e729..c9f937205 100644 --- a/spinifex/gateway/ec2/key/DescribeKeyPairs.go +++ b/spinifex/domains/ec2/awsapi/key/DescribeKeyPairs.go @@ -1,4 +1,4 @@ -package gateway_ec2_key +package key import ( "context" diff --git a/spinifex/gateway/ec2/key/ImportKeyPair.go b/spinifex/domains/ec2/awsapi/key/ImportKeyPair.go similarity index 97% rename from spinifex/gateway/ec2/key/ImportKeyPair.go rename to spinifex/domains/ec2/awsapi/key/ImportKeyPair.go index 50b27b508..70d877f57 100644 --- a/spinifex/gateway/ec2/key/ImportKeyPair.go +++ b/spinifex/domains/ec2/awsapi/key/ImportKeyPair.go @@ -1,4 +1,4 @@ -package gateway_ec2_key +package key import ( "context" diff --git a/spinifex/gateway/ec2/key/ImportKeyPair_test.go b/spinifex/domains/ec2/awsapi/key/ImportKeyPair_test.go similarity index 98% rename from spinifex/gateway/ec2/key/ImportKeyPair_test.go rename to spinifex/domains/ec2/awsapi/key/ImportKeyPair_test.go index 12bd267bc..779103619 100644 --- a/spinifex/gateway/ec2/key/ImportKeyPair_test.go +++ b/spinifex/domains/ec2/awsapi/key/ImportKeyPair_test.go @@ -1,4 +1,4 @@ -package gateway_ec2_key +package key import ( "errors" diff --git a/spinifex/gateway/ec2/key/handler_test.go b/spinifex/domains/ec2/awsapi/key/handler_test.go similarity index 98% rename from spinifex/gateway/ec2/key/handler_test.go rename to spinifex/domains/ec2/awsapi/key/handler_test.go index 50b5facdf..1919841b2 100644 --- a/spinifex/gateway/ec2/key/handler_test.go +++ b/spinifex/domains/ec2/awsapi/key/handler_test.go @@ -1,4 +1,4 @@ -package gateway_ec2_key +package key import ( "context" diff --git a/spinifex/gateway/ec2.go b/spinifex/gateway/ec2.go index 6c9447b73..f897608e4 100644 --- a/spinifex/gateway/ec2.go +++ b/spinifex/gateway/ec2.go @@ -15,6 +15,7 @@ import ( "github.com/aws/aws-sdk-go/service/ec2" ec2accountapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/account" ec2capacityreservationapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/capacityreservation" + ec2keyapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/key" "github.com/mulgadc/spinifex/spinifex/foundation/aws/errors" awsxml "github.com/mulgadc/spinifex/spinifex/foundation/aws/xml" "github.com/mulgadc/spinifex/spinifex/foundation/lifecycle/idempotency" @@ -24,7 +25,6 @@ import ( gateway_ec2_igw "github.com/mulgadc/spinifex/spinifex/gateway/ec2/igw" gateway_ec2_image "github.com/mulgadc/spinifex/spinifex/gateway/ec2/image" gateway_ec2_instance "github.com/mulgadc/spinifex/spinifex/gateway/ec2/instance" - gateway_ec2_key "github.com/mulgadc/spinifex/spinifex/gateway/ec2/key" gateway_ec2_launchtemplate "github.com/mulgadc/spinifex/spinifex/gateway/ec2/launchtemplate" gateway_ec2_natgw "github.com/mulgadc/spinifex/spinifex/gateway/ec2/natgw" gateway_ec2_placementgroup "github.com/mulgadc/spinifex/spinifex/gateway/ec2/placementgroup" @@ -289,16 +289,16 @@ var ec2Actions = map[string]ec2Action{ return gateway_ec2_instance.DescribeInstanceCreditSpecifications(input) }), "CreateKeyPair": ec2Handler(func(ctx context.Context, input *ec2.CreateKeyPairInput, gw *GatewayConfig, accountID string) (any, error) { - return gateway_ec2_key.CreateKeyPair(ctx, input, gw.NATSConn, accountID) + return ec2keyapi.CreateKeyPair(ctx, input, gw.NATSConn, accountID) }), "DeleteKeyPair": ec2Handler(func(ctx context.Context, input *ec2.DeleteKeyPairInput, gw *GatewayConfig, accountID string) (any, error) { - return gateway_ec2_key.DeleteKeyPair(ctx, input, gw.NATSConn, accountID) + return ec2keyapi.DeleteKeyPair(ctx, input, gw.NATSConn, accountID) }), "DescribeKeyPairs": ec2Handler(func(ctx context.Context, input *ec2.DescribeKeyPairsInput, gw *GatewayConfig, accountID string) (any, error) { - return gateway_ec2_key.DescribeKeyPairs(ctx, input, gw.NATSConn, accountID) + return ec2keyapi.DescribeKeyPairs(ctx, input, gw.NATSConn, accountID) }), "ImportKeyPair": ec2Handler(func(ctx context.Context, input *ec2.ImportKeyPairInput, gw *GatewayConfig, accountID string) (any, error) { - return gateway_ec2_key.ImportKeyPair(ctx, input, gw.NATSConn, accountID) + return ec2keyapi.ImportKeyPair(ctx, input, gw.NATSConn, accountID) }).withQueryPreprocessor(func(q map[string]string) { // Parser leaves Base64 padding URL-encoded; decode it before dispatch. if strings.HasSuffix(q["PublicKeyMaterial"], "%3D%3D") {