From f5068721053dbb39a2acba491bf4190ef58fadb9 Mon Sep 17 00:00:00 2001 From: joshsiv-mulga Date: Wed, 7 Oct 2026 14:31:20 +1000 Subject: [PATCH] refactor: move EC2 igw action adapters to domains/ec2/awsapi --- spinifex/accountteardown/reapers_ec2.go | 8 ++++---- .../ec2/awsapi}/igw/AttachInternetGateway.go | 2 +- .../ec2/awsapi}/igw/CreateInternetGateway.go | 2 +- .../ec2/awsapi}/igw/DeleteInternetGateway.go | 2 +- .../ec2/awsapi}/igw/DescribeInternetGateways.go | 2 +- .../ec2/awsapi}/igw/DetachInternetGateway.go | 2 +- .../ec2 => domains/ec2/awsapi}/igw/igw_test.go | 2 +- spinifex/gateway/ec2.go | 12 ++++++------ 8 files changed, 16 insertions(+), 16 deletions(-) rename spinifex/{gateway/ec2 => domains/ec2/awsapi}/igw/AttachInternetGateway.go (98%) rename spinifex/{gateway/ec2 => domains/ec2/awsapi}/igw/CreateInternetGateway.go (97%) rename spinifex/{gateway/ec2 => domains/ec2/awsapi}/igw/DeleteInternetGateway.go (97%) rename spinifex/{gateway/ec2 => domains/ec2/awsapi}/igw/DescribeInternetGateways.go (97%) rename spinifex/{gateway/ec2 => domains/ec2/awsapi}/igw/DetachInternetGateway.go (98%) rename spinifex/{gateway/ec2 => domains/ec2/awsapi}/igw/igw_test.go (99%) diff --git a/spinifex/accountteardown/reapers_ec2.go b/spinifex/accountteardown/reapers_ec2.go index 20ee04b6a..e9a11039d 100644 --- a/spinifex/accountteardown/reapers_ec2.go +++ b/spinifex/accountteardown/reapers_ec2.go @@ -12,12 +12,12 @@ import ( "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/s3" ec2eipapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/eip" + ec2igwapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/igw" ec2keyapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/key" ec2launchtemplateapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/launchtemplate" ec2placementgroupapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/placementgroup" ec2vpcapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/vpc" "github.com/mulgadc/spinifex/spinifex/foundation/aws/errors" - 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_routetable "github.com/mulgadc/spinifex/spinifex/gateway/ec2/routetable" @@ -364,7 +364,7 @@ func (r *igwReaper) Kind() string { return "internet-gateway" } func (r *igwReaper) Stage() Stage { return StageNetwork } func (r *igwReaper) List(ctx context.Context, accountID string) ([]Resource, error) { - out, err := gateway_ec2_igw.DescribeInternetGateways(ctx, &ec2.DescribeInternetGatewaysInput{}, r.nc, accountID) + out, err := ec2igwapi.DescribeInternetGateways(ctx, &ec2.DescribeInternetGatewaysInput{}, r.nc, accountID) if err != nil { return nil, err } @@ -390,7 +390,7 @@ func (r *igwReaper) List(ctx context.Context, accountID string) ([]Resource, err // cannot be deleted while it is attached. func (r *igwReaper) Delete(ctx context.Context, accountID string, resource Resource, _ bool) error { if resource.Detail != "" { - if _, err := gateway_ec2_igw.DetachInternetGateway(ctx, &ec2.DetachInternetGatewayInput{ + if _, err := ec2igwapi.DetachInternetGateway(ctx, &ec2.DetachInternetGatewayInput{ InternetGatewayId: aws.String(resource.ID), VpcId: aws.String(resource.Detail), }, r.nc, accountID); err != nil && !isAlreadyGone(err) { @@ -401,7 +401,7 @@ func (r *igwReaper) Delete(ctx context.Context, accountID string, resource Resou // Detail is empty and the delete is refused. DeleteVpc rejects while the // gateway is attached, so the VPC survives and the next sweep, once the // attachment is confirmed, takes the branch above. - _, err := gateway_ec2_igw.DeleteInternetGateway(ctx, &ec2.DeleteInternetGatewayInput{ + _, err := ec2igwapi.DeleteInternetGateway(ctx, &ec2.DeleteInternetGatewayInput{ InternetGatewayId: aws.String(resource.ID), }, r.nc, accountID) return ignoreAlreadyGone(err) diff --git a/spinifex/gateway/ec2/igw/AttachInternetGateway.go b/spinifex/domains/ec2/awsapi/igw/AttachInternetGateway.go similarity index 98% rename from spinifex/gateway/ec2/igw/AttachInternetGateway.go rename to spinifex/domains/ec2/awsapi/igw/AttachInternetGateway.go index 7bc10bcd5..9a636ac53 100644 --- a/spinifex/gateway/ec2/igw/AttachInternetGateway.go +++ b/spinifex/domains/ec2/awsapi/igw/AttachInternetGateway.go @@ -1,4 +1,4 @@ -package gateway_ec2_igw +package igw import ( "context" diff --git a/spinifex/gateway/ec2/igw/CreateInternetGateway.go b/spinifex/domains/ec2/awsapi/igw/CreateInternetGateway.go similarity index 97% rename from spinifex/gateway/ec2/igw/CreateInternetGateway.go rename to spinifex/domains/ec2/awsapi/igw/CreateInternetGateway.go index dee826d4c..0f0f7aa18 100644 --- a/spinifex/gateway/ec2/igw/CreateInternetGateway.go +++ b/spinifex/domains/ec2/awsapi/igw/CreateInternetGateway.go @@ -1,4 +1,4 @@ -package gateway_ec2_igw +package igw import ( "context" diff --git a/spinifex/gateway/ec2/igw/DeleteInternetGateway.go b/spinifex/domains/ec2/awsapi/igw/DeleteInternetGateway.go similarity index 97% rename from spinifex/gateway/ec2/igw/DeleteInternetGateway.go rename to spinifex/domains/ec2/awsapi/igw/DeleteInternetGateway.go index f075f4e72..8b5ff928c 100644 --- a/spinifex/gateway/ec2/igw/DeleteInternetGateway.go +++ b/spinifex/domains/ec2/awsapi/igw/DeleteInternetGateway.go @@ -1,4 +1,4 @@ -package gateway_ec2_igw +package igw import ( "context" diff --git a/spinifex/gateway/ec2/igw/DescribeInternetGateways.go b/spinifex/domains/ec2/awsapi/igw/DescribeInternetGateways.go similarity index 97% rename from spinifex/gateway/ec2/igw/DescribeInternetGateways.go rename to spinifex/domains/ec2/awsapi/igw/DescribeInternetGateways.go index 9406b15f4..2cb43f7b0 100644 --- a/spinifex/gateway/ec2/igw/DescribeInternetGateways.go +++ b/spinifex/domains/ec2/awsapi/igw/DescribeInternetGateways.go @@ -1,4 +1,4 @@ -package gateway_ec2_igw +package igw import ( "context" diff --git a/spinifex/gateway/ec2/igw/DetachInternetGateway.go b/spinifex/domains/ec2/awsapi/igw/DetachInternetGateway.go similarity index 98% rename from spinifex/gateway/ec2/igw/DetachInternetGateway.go rename to spinifex/domains/ec2/awsapi/igw/DetachInternetGateway.go index 79db700a1..cc409122f 100644 --- a/spinifex/gateway/ec2/igw/DetachInternetGateway.go +++ b/spinifex/domains/ec2/awsapi/igw/DetachInternetGateway.go @@ -1,4 +1,4 @@ -package gateway_ec2_igw +package igw import ( "context" diff --git a/spinifex/gateway/ec2/igw/igw_test.go b/spinifex/domains/ec2/awsapi/igw/igw_test.go similarity index 99% rename from spinifex/gateway/ec2/igw/igw_test.go rename to spinifex/domains/ec2/awsapi/igw/igw_test.go index 538683a90..e4348a38e 100644 --- a/spinifex/gateway/ec2/igw/igw_test.go +++ b/spinifex/domains/ec2/awsapi/igw/igw_test.go @@ -1,4 +1,4 @@ -package gateway_ec2_igw +package igw import ( "context" diff --git a/spinifex/gateway/ec2.go b/spinifex/gateway/ec2.go index 02c803bcd..871509fee 100644 --- a/spinifex/gateway/ec2.go +++ b/spinifex/gateway/ec2.go @@ -17,6 +17,7 @@ import ( ec2capacityreservationapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/capacityreservation" ec2eigwapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/eigw" ec2eipapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/eip" + ec2igwapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/igw" ec2keyapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/key" ec2launchtemplateapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/launchtemplate" ec2placementgroupapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/placementgroup" @@ -26,7 +27,6 @@ import ( awsxml "github.com/mulgadc/spinifex/spinifex/foundation/aws/xml" "github.com/mulgadc/spinifex/spinifex/foundation/lifecycle/idempotency" gateway_ec2 "github.com/mulgadc/spinifex/spinifex/gateway/ec2" - 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_natgw "github.com/mulgadc/spinifex/spinifex/gateway/ec2/natgw" @@ -410,19 +410,19 @@ var ec2Actions = map[string]ec2Action{ return gateway_ec2_snapshot.CopySnapshot(ctx, input, gw.NATSConn, accountID) }), "CreateInternetGateway": ec2Handler(func(ctx context.Context, input *ec2.CreateInternetGatewayInput, gw *GatewayConfig, accountID string) (any, error) { - return gateway_ec2_igw.CreateInternetGateway(ctx, input, gw.NATSConn, accountID) + return ec2igwapi.CreateInternetGateway(ctx, input, gw.NATSConn, accountID) }), "DeleteInternetGateway": ec2Handler(func(ctx context.Context, input *ec2.DeleteInternetGatewayInput, gw *GatewayConfig, accountID string) (any, error) { - return gateway_ec2_igw.DeleteInternetGateway(ctx, input, gw.NATSConn, accountID) + return ec2igwapi.DeleteInternetGateway(ctx, input, gw.NATSConn, accountID) }), "DescribeInternetGateways": ec2Handler(func(ctx context.Context, input *ec2.DescribeInternetGatewaysInput, gw *GatewayConfig, accountID string) (any, error) { - return gateway_ec2_igw.DescribeInternetGateways(ctx, input, gw.NATSConn, accountID) + return ec2igwapi.DescribeInternetGateways(ctx, input, gw.NATSConn, accountID) }), "AttachInternetGateway": ec2Handler(func(ctx context.Context, input *ec2.AttachInternetGatewayInput, gw *GatewayConfig, accountID string) (any, error) { - return gateway_ec2_igw.AttachInternetGateway(ctx, input, gw.NATSConn, accountID) + return ec2igwapi.AttachInternetGateway(ctx, input, gw.NATSConn, accountID) }), "DetachInternetGateway": ec2Handler(func(ctx context.Context, input *ec2.DetachInternetGatewayInput, gw *GatewayConfig, accountID string) (any, error) { - return gateway_ec2_igw.DetachInternetGateway(ctx, input, gw.NATSConn, accountID) + return ec2igwapi.DetachInternetGateway(ctx, input, gw.NATSConn, accountID) }), "CreateEgressOnlyInternetGateway": ec2IdempotentHandler(func(ctx context.Context, input *ec2.CreateEgressOnlyInternetGatewayInput, gw *GatewayConfig, accountID string) (ec2.CreateEgressOnlyInternetGatewayOutput, error) { return ec2eigwapi.CreateEgressOnlyInternetGateway(ctx, input, gw.NATSConn, accountID)