Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aws/resources/apigateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func NewApiGateway() AwsResource {
ResourceTypeName: "apigateway",
BatchSize: 10,
InitClient: WrapAwsInitClient(func(r *resource.Resource[ApiGatewayAPI], cfg aws.Config) {
r.Scope.Region = cfg.Region
r.Client = apigateway.NewFromConfig(cfg)
}),
ConfigGetter: func(c config.Config) config.ResourceType {
Expand Down
1 change: 1 addition & 0 deletions aws/resources/apigatewayv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func NewApiGatewayV2() AwsResource {
ResourceTypeName: "apigatewayv2",
BatchSize: 10,
InitClient: WrapAwsInitClient(func(r *resource.Resource[ApiGatewayV2API], cfg aws.Config) {
r.Scope.Region = cfg.Region
r.Client = apigatewayv2.NewFromConfig(cfg)
}),
ConfigGetter: func(c config.Config) config.ResourceType {
Expand Down
1 change: 1 addition & 0 deletions aws/resources/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func NewDynamoDB() AwsResource {
ResourceTypeName: "dynamodb",
BatchSize: DefaultBatchSize, // Tentative batch size to ensure AWS doesn't throttle
InitClient: WrapAwsInitClient(func(r *resource.Resource[DynamoDBAPI], cfg aws.Config) {
r.Scope.Region = cfg.Region
r.Client = dynamodb.NewFromConfig(cfg)
}),
ConfigGetter: func(c config.Config) config.ResourceType {
Expand Down
1 change: 1 addition & 0 deletions aws/resources/ebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func NewEBSVolumes() AwsResource {
ResourceTypeName: "ebs",
BatchSize: DefaultBatchSize,
InitClient: WrapAwsInitClient(func(r *resource.Resource[EBSVolumesAPI], cfg aws.Config) {
r.Scope.Region = cfg.Region
r.Client = ec2.NewFromConfig(cfg)
}),
ConfigGetter: func(c config.Config) config.ResourceType {
Expand Down
1 change: 1 addition & 0 deletions aws/resources/ec2_egress_only_igw.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func NewEgressOnlyInternetGateway() AwsResource {
ResourceTypeName: "egress-only-internet-gateway",
BatchSize: DefaultBatchSize,
InitClient: WrapAwsInitClient(func(r *resource.Resource[EgressOnlyIGAPI], cfg aws.Config) {
r.Scope.Region = cfg.Region
r.Client = ec2.NewFromConfig(cfg)
}),
ConfigGetter: func(c config.Config) config.ResourceType {
Expand Down
1 change: 1 addition & 0 deletions aws/resources/network_firewall_resource_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func NewNetworkFirewallResourcePolicy() AwsResource {
ResourceTypeName: "network-firewall-resource-policy",
BatchSize: 10,
InitClient: WrapAwsInitClient(func(r *resource.Resource[NetworkFirewallResourcePolicyAPI], cfg aws.Config) {
r.Scope.Region = cfg.Region
r.Client = networkfirewall.NewFromConfig(cfg)
}),
ConfigGetter: func(c config.Config) config.ResourceType {
Expand Down
1 change: 1 addition & 0 deletions aws/resources/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func NewDBInstances() AwsResource {
ResourceTypeName: "rds",
BatchSize: DefaultBatchSize,
InitClient: WrapAwsInitClient(func(r *resource.Resource[DBInstancesAPI], cfg aws.Config) {
r.Scope.Region = cfg.Region
r.Client = rds.NewFromConfig(cfg)
}),
ConfigGetter: func(c config.Config) config.ResourceType {
Expand Down
1 change: 1 addition & 0 deletions aws/resources/rds_parameter_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func NewRdsParameterGroup() AwsResource {
ResourceTypeName: "rds-parameter-group",
BatchSize: DefaultBatchSize,
InitClient: WrapAwsInitClient(func(r *resource.Resource[RdsParameterGroupAPI], cfg aws.Config) {
r.Scope.Region = cfg.Region
r.Client = rds.NewFromConfig(cfg)
}),
ConfigGetter: func(c config.Config) config.ResourceType {
Expand Down
1 change: 1 addition & 0 deletions aws/resources/rds_subnet_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func NewDBSubnetGroups() AwsResource {
ResourceTypeName: "rds-subnet-group",
BatchSize: DefaultBatchSize,
InitClient: WrapAwsInitClient(func(r *resource.Resource[DBSubnetGroupsAPI], cfg aws.Config) {
r.Scope.Region = cfg.Region
r.Client = rds.NewFromConfig(cfg)
}),
ConfigGetter: func(c config.Config) config.ResourceType {
Expand Down
24 changes: 22 additions & 2 deletions gcp/resources/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,33 @@ package resources

import (
"context"
"fmt"
"time"

"github.com/gruntwork-io/cloud-nuke/resource"
)

const (
DefaultWaitTimeout = 5 * time.Minute
DefaultBatchSize = 50
)

// GcpInitClientFunc is the type-safe client initialization function signature.
type GcpInitClientFunc[C any] func(r *resource.Resource[C], projectID string)

// WrapGcpInitClient converts a GcpInitClientFunc to the generic InitClient signature.
// Panics on type assertion failure since that indicates a programming error.
func WrapGcpInitClient[C any](fn GcpInitClientFunc[C]) func(r *resource.Resource[C], cfg any) {
return func(r *resource.Resource[C], cfg any) {
projectID, ok := cfg.(string)
if !ok {
panic(fmt.Sprintf("WrapGcpInitClient: expected string projectID, got %T", cfg))
}
fn(r, projectID)
}
}

// GcpResourceAdapter wraps a generic Resource to satisfy the GcpResource interface.
// It provides type-safe Init(string) for GCP's project ID initialization.
type GcpResourceAdapter[C any] struct {
*resource.Resource[C]
}
Expand All @@ -27,5 +48,4 @@ func (g *GcpResourceAdapter[C]) Nuke(ctx context.Context, identifiers []string)
return g.Resource.Nuke(ctx, identifiers)
}

// Compile-time interface satisfaction check
var _ GcpResource = (*GcpResourceAdapter[any])(nil)
14 changes: 4 additions & 10 deletions gcp/resources/gcs_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,15 @@ import (
func NewGCSBuckets() GcpResource {
return NewGcpResource(&resource.Resource[*storage.Client]{
ResourceTypeName: "gcs-bucket",
BatchSize: 50,
InitClient: func(r *resource.Resource[*storage.Client], cfg any) {
projectID, ok := cfg.(string)
if !ok {
logging.Debugf("Invalid config type for GCS client: expected string")
return
}
BatchSize: DefaultBatchSize,
InitClient: WrapGcpInitClient(func(r *resource.Resource[*storage.Client], projectID string) {
r.Scope.ProjectID = projectID
client, err := storage.NewClient(context.Background())
if err != nil {
logging.Debugf("Failed to create GCS client: %v", err)
return
panic(fmt.Sprintf("failed to create GCS client: %v", err))
}
r.Client = client
},
}),
ConfigGetter: func(c config.Config) config.ResourceType {
return c.GCSBucket
},
Expand Down