diff --git a/aws/aws.go b/aws/aws.go index b28bf0e4..7cc8f5a5 100644 --- a/aws/aws.go +++ b/aws/aws.go @@ -1,6 +1,7 @@ package aws import ( + "context" "fmt" "github.com/gruntwork-io/cloud-nuke/util" "github.com/pterm/pterm" @@ -11,7 +12,6 @@ import ( commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/sts" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/cloud-nuke/logging" "github.com/gruntwork-io/cloud-nuke/progressbar" @@ -21,7 +21,7 @@ import ( ) // GetAllResources - Lists all aws resources -func GetAllResources(query *Query, configObj config.Config) (*AwsAccountResources, error) { +func GetAllResources(c context.Context, query *Query, configObj config.Config) (*AwsAccountResources, error) { configObj.AddExcludeAfterTime(query.ExcludeAfter) configObj.AddIncludeAfterTime(query.IncludeAfter) @@ -33,10 +33,10 @@ func GetAllResources(query *Query, configObj config.Config) (*AwsAccountResource spinner, _ := pterm.DefaultSpinner.WithRemoveWhenDone(true).Start() for _, region := range query.Regions { cloudNukeSession := NewSession(region) - stsService := sts.New(cloudNukeSession) - resp, err := stsService.GetCallerIdentity(&sts.GetCallerIdentityInput{}) + accountId, err := util.GetCurrentAccountId(cloudNukeSession) if err == nil { - telemetry.SetAccountId(*resp.Account) + telemetry.SetAccountId(accountId) + c = context.WithValue(c, util.AccountIdKey, accountId) } awsResource := AwsRegionResource{} @@ -46,7 +46,7 @@ func GetAllResources(query *Query, configObj config.Config) (*AwsAccountResource spinner.UpdateText( fmt.Sprintf("Searching %s resources in %s", (*resource).ResourceName(), region)) start := time.Now() - identifiers, err := (*resource).GetAndSetIdentifiers(configObj) + identifiers, err := (*resource).GetAndSetIdentifiers(c, configObj) if err != nil { ge := report.GeneralError{ Error: err, diff --git a/aws/resources/access_analyzer.go b/aws/resources/access_analyzer.go index de3c8e8a..381972fb 100644 --- a/aws/resources/access_analyzer.go +++ b/aws/resources/access_analyzer.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/service/accessanalyzer" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/cloud-nuke/logging" @@ -11,7 +12,7 @@ import ( "sync" ) -func (analyzer *AccessAnalyzer) getAll(configObj config.Config) ([]*string, error) { +func (analyzer *AccessAnalyzer) getAll(c context.Context, configObj config.Config) ([]*string, error) { allAnalyzers := []*string{} err := analyzer.Client.ListAnalyzersPages( &accessanalyzer.ListAnalyzersInput{}, diff --git a/aws/resources/access_analyzer_test.go b/aws/resources/access_analyzer_test.go index 836b2534..262fcaea 100644 --- a/aws/resources/access_analyzer_test.go +++ b/aws/resources/access_analyzer_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go-v2/aws" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/accessanalyzer" @@ -79,7 +80,7 @@ func TestAccessAnalyzer_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := aa.getAll(config.Config{ + names, err := aa.getAll(context.Background(), config.Config{ AccessAnalyzer: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/access_analyzer_types.go b/aws/resources/access_analyzer_types.go index 851994d1..d27fd689 100644 --- a/aws/resources/access_analyzer_types.go +++ b/aws/resources/access_analyzer_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/accessanalyzer" @@ -37,8 +38,8 @@ func (analyzer *AccessAnalyzer) MaxBatchSize() int { return 10 } -func (analyzer *AccessAnalyzer) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := analyzer.getAll(configObj) +func (analyzer *AccessAnalyzer) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := analyzer.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/acm.go b/aws/resources/acm.go index 6ddf78c6..f6a88457 100644 --- a/aws/resources/acm.go +++ b/aws/resources/acm.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/service/acm" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/cloud-nuke/logging" @@ -11,7 +12,7 @@ import ( ) // Returns a list of strings of ACM ARNs -func (a *ACM) getAll(configObj config.Config) ([]*string, error) { +func (a *ACM) getAll(c context.Context, configObj config.Config) ([]*string, error) { params := &acm.ListCertificatesInput{} diff --git a/aws/resources/acm_test.go b/aws/resources/acm_test.go index 5072772d..c6c64bec 100644 --- a/aws/resources/acm_test.go +++ b/aws/resources/acm_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "regexp" "testing" "time" @@ -52,12 +53,12 @@ func TestACMGetAll(t *testing.T) { } // without any filters - acms, err := acm.getAll(config.Config{}) + acms, err := acm.getAll(context.Background(), config.Config{}) require.NoError(t, err) require.Contains(t, aws.StringValueSlice(acms), testArn) // filtering domain names - acms, err = acm.getAll(config.Config{ + acms, err = acm.getAll(context.Background(), config.Config{ ACM: config.ResourceType{ ExcludeRule: config.FilterRule{ NamesRegExp: []config.Expression{{ @@ -68,7 +69,7 @@ func TestACMGetAll(t *testing.T) { require.NotContains(t, aws.StringValueSlice(acms), testArn) // filtering with time - acms, err = acm.getAll(config.Config{ + acms, err = acm.getAll(context.Background(), config.Config{ ACM: config.ResourceType{ ExcludeRule: config.FilterRule{ TimeAfter: aws.Time(now.Add(-1)), @@ -98,7 +99,7 @@ func TestACMGetAll_FilterInUse(t *testing.T) { }, } - acms, err := acm.getAll(config.Config{}) + acms, err := acm.getAll(context.Background(), config.Config{}) require.NoError(t, err) require.NotContains(t, acms, testArn) } diff --git a/aws/resources/acm_types.go b/aws/resources/acm_types.go index b2c7eec3..dd344435 100644 --- a/aws/resources/acm_types.go +++ b/aws/resources/acm_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/acm" @@ -35,8 +36,8 @@ func (a *ACM) MaxBatchSize() int { return 10 } -func (a *ACM) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := a.getAll(configObj) +func (a *ACM) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := a.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/acmpca.go b/aws/resources/acmpca.go index 4a87d0b2..a67ad113 100644 --- a/aws/resources/acmpca.go +++ b/aws/resources/acmpca.go @@ -1,6 +1,7 @@ package resources import ( + "context" "fmt" "sync" "time" @@ -18,7 +19,7 @@ import ( ) // GetAll returns a list of all arns of ACMPCA, which can be deleted. -func (ap *ACMPCA) getAll(configObj config.Config) ([]*string, error) { +func (ap *ACMPCA) getAll(c context.Context, configObj config.Config) ([]*string, error) { var arns []*string paginationErr := ap.Client.ListCertificateAuthoritiesPages( &acmpca.ListCertificateAuthoritiesInput{}, diff --git a/aws/resources/acmpca_test.go b/aws/resources/acmpca_test.go index f6299d3b..8260524c 100644 --- a/aws/resources/acmpca_test.go +++ b/aws/resources/acmpca_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "testing" "time" @@ -63,12 +64,12 @@ func TestAcmPcaGetAll(t *testing.T) { } // without filters - arns, err := acmPca.getAll(config.Config{}) + arns, err := acmPca.getAll(context.Background(), config.Config{}) require.NoError(t, err) require.Contains(t, awsgo.StringValueSlice(arns), testArn) // with exclude after filter - arns, err = acmPca.getAll(config.Config{ + arns, err = acmPca.getAll(context.Background(), config.Config{ ACMPCA: config.ResourceType{ ExcludeRule: config.FilterRule{ TimeAfter: awsgo.Time(now.Add(-1))}}, diff --git a/aws/resources/acmpca_types.go b/aws/resources/acmpca_types.go index 344a1d4c..84d1b6c3 100644 --- a/aws/resources/acmpca_types.go +++ b/aws/resources/acmpca_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/acmpca" @@ -35,8 +36,8 @@ func (ap *ACMPCA) MaxBatchSize() int { return 10 } -func (ap *ACMPCA) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := ap.getAll(configObj) +func (ap *ACMPCA) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := ap.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/ami.go b/aws/resources/ami.go index 018976ce..57cc3732 100644 --- a/aws/resources/ami.go +++ b/aws/resources/ami.go @@ -1,6 +1,7 @@ package resources import ( + "context" "strings" "time" @@ -17,7 +18,7 @@ import ( ) // Returns a formatted string of AMI Image ids -func (ami *AMIs) getAll(configObj config.Config) ([]*string, error) { +func (ami *AMIs) getAll(c context.Context, configObj config.Config) ([]*string, error) { params := &ec2.DescribeImagesInput{ Owners: []*string{awsgo.String("self")}, } diff --git a/aws/resources/ami_test.go b/aws/resources/ami_test.go index 0f90a706..c7374ef2 100644 --- a/aws/resources/ami_test.go +++ b/aws/resources/ami_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go/service/ec2/ec2iface" "github.com/gruntwork-io/cloud-nuke/config" @@ -67,7 +68,7 @@ func TestAMIGetAll_SkipAWSManaged(t *testing.T) { }, } - amis, err := acm.getAll(config.Config{}) + amis, err := acm.getAll(context.Background(), config.Config{}) assert.NoError(t, err) assert.NotContains(t, awsgo.StringValueSlice(amis), testImageId1) assert.NotContains(t, awsgo.StringValueSlice(amis), testImageId2) @@ -93,12 +94,12 @@ func TestAMIGetAll(t *testing.T) { } // without filters - amis, err := acm.getAll(config.Config{}) + amis, err := acm.getAll(context.Background(), config.Config{}) assert.NoError(t, err) assert.Contains(t, awsgo.StringValueSlice(amis), testImageId) // with name filter - amis, err = acm.getAll(config.Config{ + amis, err = acm.getAll(context.Background(), config.Config{ AMI: config.ResourceType{ ExcludeRule: config.FilterRule{ NamesRegExp: []config.Expression{{ @@ -108,7 +109,7 @@ func TestAMIGetAll(t *testing.T) { assert.NotContains(t, awsgo.StringValueSlice(amis), testImageId) // with time filter - amis, err = acm.getAll(config.Config{ + amis, err = acm.getAll(context.Background(), config.Config{ AMI: config.ResourceType{ ExcludeRule: config.FilterRule{ TimeAfter: awsgo.Time(now.Add(-12 * time.Hour))}}}) diff --git a/aws/resources/ami_types.go b/aws/resources/ami_types.go index aeb2525f..b91f0cd1 100644 --- a/aws/resources/ami_types.go +++ b/aws/resources/ami_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" @@ -35,8 +36,8 @@ func (ami *AMIs) MaxBatchSize() int { return 49 } -func (ami *AMIs) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := ami.getAll(configObj) +func (ami *AMIs) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := ami.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/apigateway.go b/aws/resources/apigateway.go index ff8153db..f45ed931 100644 --- a/aws/resources/apigateway.go +++ b/aws/resources/apigateway.go @@ -1,6 +1,7 @@ package resources import ( + "context" "sync" commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" @@ -15,7 +16,7 @@ import ( "github.com/hashicorp/go-multierror" ) -func (gateway *ApiGateway) getAll(configObj config.Config) ([]*string, error) { +func (gateway *ApiGateway) getAll(c context.Context, configObj config.Config) ([]*string, error) { result, err := gateway.Client.GetRestApis(&apigateway.GetRestApisInput{}) if err != nil { return []*string{}, errors.WithStackTrace(err) diff --git a/aws/resources/apigateway_test.go b/aws/resources/apigateway_test.go index 0286039e..61f6925f 100644 --- a/aws/resources/apigateway_test.go +++ b/aws/resources/apigateway_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "testing" "time" @@ -47,7 +48,7 @@ func TestAPIGatewayGetAllAndNukeAll(t *testing.T) { }, } - apis, err := apiGateway.getAll(config.Config{}) + apis, err := apiGateway.getAll(context.Background(), config.Config{}) require.NoError(t, err) require.Contains(t, awsgo.StringValueSlice(apis), testApiID) @@ -73,7 +74,7 @@ func TestAPIGatewayGetAllTimeFilter(t *testing.T) { } // test API is not excluded from the filter - IDs, err := apiGateway.getAll(config.Config{ + IDs, err := apiGateway.getAll(context.Background(), config.Config{ APIGateway: config.ResourceType{ ExcludeRule: config.FilterRule{ TimeAfter: aws.Time(now.Add(1)), @@ -84,7 +85,7 @@ func TestAPIGatewayGetAllTimeFilter(t *testing.T) { assert.Contains(t, aws.StringValueSlice(IDs), testApiID) // test API being excluded from the filter - apiGwIdsOlder, err := apiGateway.getAll(config.Config{ + apiGwIdsOlder, err := apiGateway.getAll(context.Background(), config.Config{ APIGateway: config.ResourceType{ ExcludeRule: config.FilterRule{ TimeAfter: aws.Time(now.Add(-1)), @@ -113,7 +114,7 @@ func TestNukeAPIGatewayMoreThanOne(t *testing.T) { }, } - apis, err := apiGateway.getAll(config.Config{}) + apis, err := apiGateway.getAll(context.Background(), config.Config{}) require.NoError(t, err) require.Contains(t, awsgo.StringValueSlice(apis), testApiID1) require.Contains(t, awsgo.StringValueSlice(apis), testApiID2) diff --git a/aws/resources/apigateway_types.go b/aws/resources/apigateway_types.go index 4ebfb1e6..dd58b080 100644 --- a/aws/resources/apigateway_types.go +++ b/aws/resources/apigateway_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/apigateway" @@ -31,8 +32,8 @@ func (gateway *ApiGateway) MaxBatchSize() int { return 10 } -func (gateway *ApiGateway) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := gateway.getAll(configObj) +func (gateway *ApiGateway) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := gateway.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/apigatewayv2.go b/aws/resources/apigatewayv2.go index 185ee1d1..d4e31ada 100644 --- a/aws/resources/apigatewayv2.go +++ b/aws/resources/apigatewayv2.go @@ -1,6 +1,7 @@ package resources import ( + "context" "sync" commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" @@ -15,7 +16,7 @@ import ( "github.com/hashicorp/go-multierror" ) -func (gw *ApiGatewayV2) getAll(configObj config.Config) ([]*string, error) { +func (gw *ApiGatewayV2) getAll(c context.Context, configObj config.Config) ([]*string, error) { output, err := gw.Client.GetApis(&apigatewayv2.GetApisInput{}) if err != nil { return []*string{}, errors.WithStackTrace(err) diff --git a/aws/resources/apigatewayv2_test.go b/aws/resources/apigatewayv2_test.go index 125f3b1e..28bc7c26 100644 --- a/aws/resources/apigatewayv2_test.go +++ b/aws/resources/apigatewayv2_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "regexp" "testing" "time" @@ -53,12 +54,12 @@ func TestApiGatewayV2GetAll(t *testing.T) { } // empty filter - apis, err := gw.getAll(config.Config{}) + apis, err := gw.getAll(context.Background(), config.Config{}) assert.NoError(t, err) assert.Contains(t, awsgo.StringValueSlice(apis), testApiID) // filter by name - apis, err = gw.getAll(config.Config{ + apis, err = gw.getAll(context.Background(), config.Config{ APIGatewayV2: config.ResourceType{ ExcludeRule: config.FilterRule{ NamesRegExp: []config.Expression{{ @@ -68,7 +69,7 @@ func TestApiGatewayV2GetAll(t *testing.T) { assert.NotContains(t, awsgo.StringValueSlice(apis), testApiID) // filter by date - apis, err = gw.getAll(config.Config{ + apis, err = gw.getAll(context.Background(), config.Config{ APIGatewayV2: config.ResourceType{ ExcludeRule: config.FilterRule{ TimeAfter: awsgo.Time(now.Add(-1))}}}) diff --git a/aws/resources/apigatewayv2_types.go b/aws/resources/apigatewayv2_types.go index 6cfb7a41..ceff89cc 100644 --- a/aws/resources/apigatewayv2_types.go +++ b/aws/resources/apigatewayv2_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/apigatewayv2" @@ -31,8 +32,8 @@ func (gw *ApiGatewayV2) MaxBatchSize() int { return 10 } -func (gw *ApiGatewayV2) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := gw.getAll(configObj) +func (gw *ApiGatewayV2) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := gw.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/asg.go b/aws/resources/asg.go index 2f51191e..6727b850 100644 --- a/aws/resources/asg.go +++ b/aws/resources/asg.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/autoscaling" "github.com/gruntwork-io/cloud-nuke/config" @@ -13,7 +14,7 @@ import ( ) // Returns a formatted string of ASG Names -func (ag *ASGroups) getAll(configObj config.Config) ([]*string, error) { +func (ag *ASGroups) getAll(c context.Context, configObj config.Config) ([]*string, error) { result, err := ag.Client.DescribeAutoScalingGroups(&autoscaling.DescribeAutoScalingGroupsInput{}) if err != nil { return nil, errors.WithStackTrace(err) diff --git a/aws/resources/asg_test.go b/aws/resources/asg_test.go index 48a6f50e..713e0e30 100644 --- a/aws/resources/asg_test.go +++ b/aws/resources/asg_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/service/autoscaling/autoscalingiface" "github.com/gruntwork-io/cloud-nuke/telemetry" "regexp" @@ -46,12 +47,12 @@ func TestAutoScalingGroupGetAll(t *testing.T) { }}}}} // empty filter - groups, err := ag.getAll(config.Config{}) + groups, err := ag.getAll(context.Background(), config.Config{}) assert.NoError(t, err) assert.Contains(t, awsgo.StringValueSlice(groups), testName) // name filter - groups, err = ag.getAll(config.Config{ + groups, err = ag.getAll(context.Background(), config.Config{ AutoScalingGroup: config.ResourceType{ ExcludeRule: config.FilterRule{ NamesRegExp: []config.Expression{{ @@ -61,7 +62,7 @@ func TestAutoScalingGroupGetAll(t *testing.T) { assert.NotContains(t, awsgo.StringValueSlice(groups), testName) // time filter - groups, err = ag.getAll(config.Config{ + groups, err = ag.getAll(context.Background(), config.Config{ AutoScalingGroup: config.ResourceType{ ExcludeRule: config.FilterRule{ TimeAfter: awsgo.Time(now.Add(-1)), diff --git a/aws/resources/asg_types.go b/aws/resources/asg_types.go index 97165460..9fbdedf6 100644 --- a/aws/resources/asg_types.go +++ b/aws/resources/asg_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/autoscaling" @@ -35,8 +36,8 @@ func (ag *ASGroups) ResourceIdentifiers() []string { return ag.GroupNames } -func (ag *ASGroups) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := ag.getAll(configObj) +func (ag *ASGroups) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := ag.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/backup_vault.go b/aws/resources/backup_vault.go index 7b9a0b5c..0541e566 100644 --- a/aws/resources/backup_vault.go +++ b/aws/resources/backup_vault.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/backup" "github.com/gruntwork-io/cloud-nuke/config" @@ -11,7 +12,7 @@ import ( commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" ) -func (bv *BackupVault) getAll(configObj config.Config) ([]*string, error) { +func (bv *BackupVault) getAll(c context.Context, configObj config.Config) ([]*string, error) { names := []*string{} paginator := func(output *backup.ListBackupVaultsOutput, lastPage bool) bool { for _, backupVault := range output.BackupVaultList { diff --git a/aws/resources/backup_vault_test.go b/aws/resources/backup_vault_test.go index 96be9ee3..b48945e4 100644 --- a/aws/resources/backup_vault_test.go +++ b/aws/resources/backup_vault_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/service/backup/backupiface" "regexp" "testing" @@ -79,7 +80,7 @@ func TestBackupVaultGetAll(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := bv.getAll(config.Config{ + names, err := bv.getAll(context.Background(), config.Config{ BackupVault: tc.configObj, }) diff --git a/aws/resources/backup_vault_types.go b/aws/resources/backup_vault_types.go index 3b8172ab..8290208a 100644 --- a/aws/resources/backup_vault_types.go +++ b/aws/resources/backup_vault_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/backup" @@ -33,8 +34,8 @@ func (bv *BackupVault) MaxBatchSize() int { return 50 } -func (bv *BackupVault) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := bv.getAll(configObj) +func (bv *BackupVault) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := bv.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/cloudtrail.go b/aws/resources/cloudtrail.go index e25c4cb7..dbcbf63e 100644 --- a/aws/resources/cloudtrail.go +++ b/aws/resources/cloudtrail.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/cloudtrail" "github.com/gruntwork-io/cloud-nuke/config" @@ -11,7 +12,7 @@ import ( commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" ) -func (ct *CloudtrailTrail) getAll(configObj config.Config) ([]*string, error) { +func (ct *CloudtrailTrail) getAll(c context.Context, configObj config.Config) ([]*string, error) { param := &cloudtrail.ListTrailsInput{} trailIds := []*string{} diff --git a/aws/resources/cloudtrail_test.go b/aws/resources/cloudtrail_test.go index 74e542d8..21df38e7 100644 --- a/aws/resources/cloudtrail_test.go +++ b/aws/resources/cloudtrail_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/cloudtrail" "github.com/aws/aws-sdk-go/service/cloudtrail/cloudtrailiface" @@ -69,7 +70,7 @@ func TestCloudTrailGetAll(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := ct.getAll(config.Config{ + names, err := ct.getAll(context.Background(), config.Config{ CloudtrailTrail: tc.configObj, }) diff --git a/aws/resources/cloudtrail_types.go b/aws/resources/cloudtrail_types.go index 5bee5970..4c49ce3d 100644 --- a/aws/resources/cloudtrail_types.go +++ b/aws/resources/cloudtrail_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudtrail" @@ -34,8 +35,8 @@ func (ct *CloudtrailTrail) MaxBatchSize() int { return 50 } -func (ct *CloudtrailTrail) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := ct.getAll(configObj) +func (ct *CloudtrailTrail) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := ct.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/cloudwatch_alarm.go b/aws/resources/cloudwatch_alarm.go index b9eed6d1..5168cb2d 100644 --- a/aws/resources/cloudwatch_alarm.go +++ b/aws/resources/cloudwatch_alarm.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/cloudwatch" "github.com/gruntwork-io/cloud-nuke/config" @@ -12,7 +13,7 @@ import ( commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" ) -func (cw *CloudWatchAlarms) getAll(configObj config.Config) ([]*string, error) { +func (cw *CloudWatchAlarms) getAll(c context.Context, configObj config.Config) ([]*string, error) { allAlarms := []*string{} input := &cloudwatch.DescribeAlarmsInput{ AlarmTypes: aws.StringSlice([]string{cloudwatch.AlarmTypeMetricAlarm, cloudwatch.AlarmTypeCompositeAlarm}), diff --git a/aws/resources/cloudwatch_alarm_test.go b/aws/resources/cloudwatch_alarm_test.go index d95d6877..7ac36cd3 100644 --- a/aws/resources/cloudwatch_alarm_test.go +++ b/aws/resources/cloudwatch_alarm_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface" "github.com/gruntwork-io/cloud-nuke/telemetry" "regexp" @@ -81,7 +82,7 @@ func TestCloudWatchAlarm_GetAll(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := cw.getAll(config.Config{ + names, err := cw.getAll(context.Background(), config.Config{ CloudWatchAlarm: tc.configObj, }) diff --git a/aws/resources/cloudwatch_alarm_types.go b/aws/resources/cloudwatch_alarm_types.go index 90fd6544..321ac22b 100644 --- a/aws/resources/cloudwatch_alarm_types.go +++ b/aws/resources/cloudwatch_alarm_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudwatch" @@ -34,8 +35,8 @@ func (cw *CloudWatchAlarms) MaxBatchSize() int { return 99 } -func (cw *CloudWatchAlarms) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := cw.getAll(configObj) +func (cw *CloudWatchAlarms) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := cw.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/cloudwatch_dashboard.go b/aws/resources/cloudwatch_dashboard.go index 59753fe5..b1d276c4 100644 --- a/aws/resources/cloudwatch_dashboard.go +++ b/aws/resources/cloudwatch_dashboard.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/cloudwatch" "github.com/gruntwork-io/cloud-nuke/telemetry" @@ -12,7 +13,7 @@ import ( "github.com/gruntwork-io/cloud-nuke/report" ) -func (cwdb *CloudWatchDashboards) getAll(configObj config.Config) ([]*string, error) { +func (cwdb *CloudWatchDashboards) getAll(c context.Context, configObj config.Config) ([]*string, error) { allDashboards := []*string{} input := &cloudwatch.ListDashboardsInput{} err := cwdb.Client.ListDashboardsPages( diff --git a/aws/resources/cloudwatch_dashboard_test.go b/aws/resources/cloudwatch_dashboard_test.go index afff2dd7..ecccf4ff 100644 --- a/aws/resources/cloudwatch_dashboard_test.go +++ b/aws/resources/cloudwatch_dashboard_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface" "github.com/gruntwork-io/cloud-nuke/telemetry" "regexp" @@ -78,7 +79,7 @@ func TestCloudWatchDashboard_GetAll(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := cw.getAll(config.Config{ + names, err := cw.getAll(context.Background(), config.Config{ CloudWatchDashboard: tc.configObj, }) diff --git a/aws/resources/cloudwatch_dashboard_types.go b/aws/resources/cloudwatch_dashboard_types.go index 76b9ae16..9b431195 100644 --- a/aws/resources/cloudwatch_dashboard_types.go +++ b/aws/resources/cloudwatch_dashboard_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudwatch" @@ -34,8 +35,8 @@ func (cwdb *CloudWatchDashboards) MaxBatchSize() int { return 49 } -func (cwdb *CloudWatchDashboards) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := cwdb.getAll(configObj) +func (cwdb *CloudWatchDashboards) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := cwdb.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/cloudwatch_loggroup.go b/aws/resources/cloudwatch_loggroup.go index 1a7096bc..4944108c 100644 --- a/aws/resources/cloudwatch_loggroup.go +++ b/aws/resources/cloudwatch_loggroup.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/telemetry" commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" "sync" @@ -16,7 +17,7 @@ import ( "github.com/hashicorp/go-multierror" ) -func (csr *CloudWatchLogGroups) getAll(configObj config.Config) ([]*string, error) { +func (csr *CloudWatchLogGroups) getAll(c context.Context, configObj config.Config) ([]*string, error) { allLogGroups := []*string{} err := csr.Client.DescribeLogGroupsPages( &cloudwatchlogs.DescribeLogGroupsInput{}, diff --git a/aws/resources/cloudwatch_loggroup_test.go b/aws/resources/cloudwatch_loggroup_test.go index 8c36d4b1..9379ef23 100644 --- a/aws/resources/cloudwatch_loggroup_test.go +++ b/aws/resources/cloudwatch_loggroup_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/cloudwatchlogs" "github.com/aws/aws-sdk-go/service/cloudwatchlogs/cloudwatchlogsiface" @@ -78,7 +79,7 @@ func TestCloudWatchLogGroup_GetAll(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := cw.getAll(config.Config{ + names, err := cw.getAll(context.Background(), config.Config{ CloudWatchLogGroup: tc.configObj, }) diff --git a/aws/resources/cloudwatch_loggroup_types.go b/aws/resources/cloudwatch_loggroup_types.go index 5dd16e53..e501b4ac 100644 --- a/aws/resources/cloudwatch_loggroup_types.go +++ b/aws/resources/cloudwatch_loggroup_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudwatchlogs" @@ -37,8 +38,8 @@ func (csr *CloudWatchLogGroups) MaxBatchSize() int { return 35 } -func (csr *CloudWatchLogGroups) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := csr.getAll(configObj) +func (csr *CloudWatchLogGroups) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := csr.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/codedeploy_application.go b/aws/resources/codedeploy_application.go index ea27d755..8299e7d7 100644 --- a/aws/resources/codedeploy_application.go +++ b/aws/resources/codedeploy_application.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/codedeploy" "github.com/gruntwork-io/cloud-nuke/config" @@ -13,10 +14,10 @@ import ( "sync" ) -func (c *CodeDeployApplications) getAll(configObj config.Config) ([]*string, error) { +func (cda *CodeDeployApplications) getAll(c context.Context, configObj config.Config) ([]*string, error) { codeDeployApplicationsFilteredByName := []string{} - err := c.Client.ListApplicationsPages( + err := cda.Client.ListApplicationsPages( &codedeploy.ListApplicationsInput{}, func(page *codedeploy.ListApplicationsOutput, lastPage bool) bool { for _, application := range page.Applications { // Check if the CodeDeploy Application should be excluded by name as that information is available to us here. @@ -35,11 +36,11 @@ func (c *CodeDeployApplications) getAll(configObj config.Config) ([]*string, err // Check if the CodeDeploy Application should be excluded by CreationDate and return. // We have to do this after the ListApplicationsPages API call because CreationDate is not available in that call. - return c.batchDescribeAndFilter(codeDeployApplicationsFilteredByName, configObj) + return cda.batchDescribeAndFilter(codeDeployApplicationsFilteredByName, configObj) } // batchDescribeAndFilterCodeDeployApplications - Describe the CodeDeploy Applications and filter out the ones that should be excluded by CreationDate. -func (c *CodeDeployApplications) batchDescribeAndFilter(identifiers []string, configObj config.Config) ([]*string, error) { +func (cda *CodeDeployApplications) batchDescribeAndFilter(identifiers []string, configObj config.Config) ([]*string, error) { // BatchGetApplications can only take 100 identifiers at a time, so we have to break up the identifiers into chunks of 100. batchSize := 100 var applicationNames []*string @@ -58,7 +59,7 @@ func (c *CodeDeployApplications) batchDescribeAndFilter(identifiers []string, co // get the next batch of identifiers batch := aws.StringSlice(identifiers[:batchSize]) // then using that batch of identifiers, get the applicationsinfo - resp, err := c.Client.BatchGetApplications( + resp, err := cda.Client.BatchGetApplications( &codedeploy.BatchGetApplicationsInput{ApplicationNames: batch}, ) if err != nil { @@ -81,20 +82,20 @@ func (c *CodeDeployApplications) batchDescribeAndFilter(identifiers []string, co return applicationNames, nil } -func (c *CodeDeployApplications) nukeAll(identifiers []string) error { +func (cda *CodeDeployApplications) nukeAll(identifiers []string) error { if len(identifiers) == 0 { - logging.Logger.Debugf("No CodeDeploy Applications to nuke in region %s", c.Region) + logging.Logger.Debugf("No CodeDeploy Applications to nuke in region %s", cda.Region) return nil } - logging.Logger.Infof("Deleting CodeDeploy Applications in region %s", c.Region) + logging.Logger.Infof("Deleting CodeDeploy Applications in region %s", cda.Region) var wg sync.WaitGroup errChan := make(chan error, len(identifiers)) for _, identifier := range identifiers { wg.Add(1) - go c.deleteAsync(&wg, errChan, identifier) + go cda.deleteAsync(&wg, errChan, identifier) } wg.Wait() @@ -108,7 +109,7 @@ func (c *CodeDeployApplications) nukeAll(identifiers []string) error { telemetry.TrackEvent(commonTelemetry.EventContext{ EventName: "Error Nuking CodeDeploy Application", }, map[string]interface{}{ - "region": c.Region, + "region": cda.Region, }) } @@ -120,10 +121,10 @@ func (c *CodeDeployApplications) nukeAll(identifiers []string) error { return nil } -func (c *CodeDeployApplications) deleteAsync(wg *sync.WaitGroup, errChan chan<- error, identifier string) { +func (cda *CodeDeployApplications) deleteAsync(wg *sync.WaitGroup, errChan chan<- error, identifier string) { defer wg.Done() - _, err := c.Client.DeleteApplication(&codedeploy.DeleteApplicationInput{ApplicationName: &identifier}) + _, err := cda.Client.DeleteApplication(&codedeploy.DeleteApplicationInput{ApplicationName: &identifier}) if err != nil { errChan <- err } diff --git a/aws/resources/codedeploy_application_test.go b/aws/resources/codedeploy_application_test.go index 572e4817..1a2c74f2 100644 --- a/aws/resources/codedeploy_application_test.go +++ b/aws/resources/codedeploy_application_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/codedeploy/codedeployiface" "github.com/gruntwork-io/cloud-nuke/telemetry" @@ -106,7 +107,7 @@ func TestCodeDeployApplication_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := c.getAll(config.Config{ + names, err := c.getAll(context.Background(), config.Config{ CodeDeployApplications: tc.configObj, }) diff --git a/aws/resources/codedeploy_application_types.go b/aws/resources/codedeploy_application_types.go index 6f64d1fa..42ee1456 100644 --- a/aws/resources/codedeploy_application_types.go +++ b/aws/resources/codedeploy_application_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/codedeploy" @@ -16,38 +17,38 @@ type CodeDeployApplications struct { AppNames []string } -func (c *CodeDeployApplications) Init(session *session.Session) { - c.Client = codedeploy.New(session) +func (cda *CodeDeployApplications) Init(session *session.Session) { + cda.Client = codedeploy.New(session) } // ResourceName - the simple name of the aws resource -func (c *CodeDeployApplications) ResourceName() string { +func (cda *CodeDeployApplications) ResourceName() string { return "codedeploy-application" } // ResourceIdentifiers - The instance ids of the code deploy applications -func (c *CodeDeployApplications) ResourceIdentifiers() []string { - return c.AppNames +func (cda *CodeDeployApplications) ResourceIdentifiers() []string { + return cda.AppNames } -func (c *CodeDeployApplications) MaxBatchSize() int { +func (cda *CodeDeployApplications) MaxBatchSize() int { // Tentative batch size to ensure AWS doesn't throttle. return 100 } -func (c *CodeDeployApplications) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := c.getAll(configObj) +func (cda *CodeDeployApplications) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := cda.getAll(c, configObj) if err != nil { return nil, err } - c.AppNames = awsgo.StringValueSlice(identifiers) - return c.AppNames, nil + cda.AppNames = awsgo.StringValueSlice(identifiers) + return cda.AppNames, nil } // Nuke - nuke 'em all!!! -func (c *CodeDeployApplications) Nuke(identifiers []string) error { - if err := c.nukeAll(identifiers); err != nil { +func (cda *CodeDeployApplications) Nuke(identifiers []string) error { + if err := cda.nukeAll(identifiers); err != nil { return errors.WithStackTrace(err) } diff --git a/aws/resources/config_recorder.go b/aws/resources/config_recorder.go index a845b68c..28e3b6ce 100644 --- a/aws/resources/config_recorder.go +++ b/aws/resources/config_recorder.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/configservice" "github.com/gruntwork-io/cloud-nuke/config" @@ -11,7 +12,7 @@ import ( commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" ) -func (csr *ConfigServiceRecorders) getAll(configObj config.Config) ([]*string, error) { +func (csr *ConfigServiceRecorders) getAll(c context.Context, configObj config.Config) ([]*string, error) { configRecorderNames := []*string{} diff --git a/aws/resources/config_recorder_test.go b/aws/resources/config_recorder_test.go index ca791be7..60ebcf09 100644 --- a/aws/resources/config_recorder_test.go +++ b/aws/resources/config_recorder_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/configservice" "github.com/aws/aws-sdk-go/service/configservice/configserviceiface" @@ -62,7 +63,7 @@ func TestConfigServiceRecorder_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := csr.getAll(config.Config{ + names, err := csr.getAll(context.Background(), config.Config{ ConfigServiceRecorder: tc.configObj, }) diff --git a/aws/resources/config_recorder_types.go b/aws/resources/config_recorder_types.go index 2ebcc407..9d5207f2 100644 --- a/aws/resources/config_recorder_types.go +++ b/aws/resources/config_recorder_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/configservice" @@ -31,8 +32,8 @@ func (csr *ConfigServiceRecorders) MaxBatchSize() int { return 50 } -func (csr *ConfigServiceRecorders) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := csr.getAll(configObj) +func (csr *ConfigServiceRecorders) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := csr.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/config_service.go b/aws/resources/config_service.go index 45f3d83b..0454afef 100644 --- a/aws/resources/config_service.go +++ b/aws/resources/config_service.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/configservice" "github.com/gruntwork-io/cloud-nuke/config" @@ -11,7 +12,7 @@ import ( commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" ) -func (csr *ConfigServiceRule) getAll(configObj config.Config) ([]*string, error) { +func (csr *ConfigServiceRule) getAll(c context.Context, configObj config.Config) ([]*string, error) { configRuleNames := []*string{} paginator := func(output *configservice.DescribeConfigRulesOutput, lastPage bool) bool { diff --git a/aws/resources/config_service_test.go b/aws/resources/config_service_test.go index f83fdd5d..8d39ccfa 100644 --- a/aws/resources/config_service_test.go +++ b/aws/resources/config_service_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/configservice" "github.com/aws/aws-sdk-go/service/configservice/configserviceiface" @@ -63,7 +64,7 @@ func TestConfigServiceRule_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := csr.getAll(config.Config{ + names, err := csr.getAll(context.Background(), config.Config{ ConfigServiceRule: tc.configObj, }) diff --git a/aws/resources/config_service_types.go b/aws/resources/config_service_types.go index 4f650c2a..7396a512 100644 --- a/aws/resources/config_service_types.go +++ b/aws/resources/config_service_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/configservice" @@ -31,8 +32,8 @@ func (csr *ConfigServiceRule) MaxBatchSize() int { return 200 } -func (csr *ConfigServiceRule) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := csr.getAll(configObj) +func (csr *ConfigServiceRule) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := csr.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/dynamodb.go b/aws/resources/dynamodb.go index c1b2e0d8..cd882b61 100644 --- a/aws/resources/dynamodb.go +++ b/aws/resources/dynamodb.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/dynamodb" @@ -13,7 +14,7 @@ import ( "log" ) -func (ddb *DynamoDB) getAll(configObj config.Config) ([]*string, error) { +func (ddb *DynamoDB) getAll(c context.Context, configObj config.Config) ([]*string, error) { var tableNames []*string err := ddb.Client.ListTablesPages( diff --git a/aws/resources/dynamodb_test.go b/aws/resources/dynamodb_test.go index e5d31d90..0fed233b 100644 --- a/aws/resources/dynamodb_test.go +++ b/aws/resources/dynamodb_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface" "github.com/gruntwork-io/cloud-nuke/telemetry" "regexp" @@ -93,7 +94,7 @@ func TestDynamoDB_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := ddb.getAll(config.Config{ + names, err := ddb.getAll(context.Background(), config.Config{ DynamoDB: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/dynamodb_types.go b/aws/resources/dynamodb_types.go index 9171cb47..98fc401f 100644 --- a/aws/resources/dynamodb_types.go +++ b/aws/resources/dynamodb_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/dynamodb" @@ -32,8 +33,8 @@ func (ddb *DynamoDB) MaxBatchSize() int { return 49 } -func (ddb *DynamoDB) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := ddb.getAll(configObj) +func (ddb *DynamoDB) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := ddb.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/ebs.go b/aws/resources/ebs.go index ca4d6263..f8cdf2ef 100644 --- a/aws/resources/ebs.go +++ b/aws/resources/ebs.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/telemetry" "github.com/gruntwork-io/cloud-nuke/util" commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" @@ -15,7 +16,7 @@ import ( ) // Returns a formatted string of EBS volume ids -func (ev *EBSVolumes) getAll(configObj config.Config) ([]*string, error) { +func (ev *EBSVolumes) getAll(c context.Context, configObj config.Config) ([]*string, error) { // Available statuses: (creating | available | in-use | deleting | deleted | error). // Since the output of this function is used to delete the returned volumes // We want to only list EBS volumes with a status of "available" or "creating" diff --git a/aws/resources/ebs_test.go b/aws/resources/ebs_test.go index af15ee81..2febe076 100644 --- a/aws/resources/ebs_test.go +++ b/aws/resources/ebs_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/service/ec2/ec2iface" "regexp" "testing" @@ -92,7 +93,7 @@ func TestEBSVolume_GetAll(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := ev.getAll(config.Config{ + names, err := ev.getAll(context.Background(), config.Config{ EBSVolume: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/ebs_types.go b/aws/resources/ebs_types.go index 3070ac31..dcaebf83 100644 --- a/aws/resources/ebs_types.go +++ b/aws/resources/ebs_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" @@ -35,8 +36,8 @@ func (ev *EBSVolumes) MaxBatchSize() int { return 49 } -func (ev *EBSVolumes) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := ev.getAll(configObj) +func (ev *EBSVolumes) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := ev.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/ec2.go b/aws/resources/ec2.go index a4ed41dc..9cd5a608 100644 --- a/aws/resources/ec2.go +++ b/aws/resources/ec2.go @@ -1,6 +1,7 @@ package resources import ( + "context" "fmt" "github.com/gruntwork-io/cloud-nuke/externalcreds" "github.com/gruntwork-io/cloud-nuke/telemetry" @@ -46,7 +47,7 @@ func (ei *EC2Instances) filterOutProtectedInstances(output *ec2.DescribeInstance } // Returns a formatted string of EC2 instance ids -func (ei *EC2Instances) getAll(configObj config.Config) ([]*string, error) { +func (ei *EC2Instances) getAll(c context.Context, configObj config.Config) ([]*string, error) { params := &ec2.DescribeInstancesInput{ Filters: []*ec2.Filter{ { diff --git a/aws/resources/ec2_dedicated_host.go b/aws/resources/ec2_dedicated_host.go index ce92d568..c7f3b808 100644 --- a/aws/resources/ec2_dedicated_host.go +++ b/aws/resources/ec2_dedicated_host.go @@ -1,6 +1,7 @@ package resources import ( + "context" "fmt" "github.com/aws/aws-sdk-go/aws" awsgo "github.com/aws/aws-sdk-go/aws" @@ -13,7 +14,7 @@ import ( commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" ) -func (h *EC2DedicatedHosts) getAll(configObj config.Config) ([]*string, error) { +func (h *EC2DedicatedHosts) getAll(c context.Context, configObj config.Config) ([]*string, error) { var hostIds []*string describeHostsInput := &ec2.DescribeHostsInput{ diff --git a/aws/resources/ec2_dedicated_host_test.go b/aws/resources/ec2_dedicated_host_test.go index e3fb29d5..83a14fb1 100644 --- a/aws/resources/ec2_dedicated_host_test.go +++ b/aws/resources/ec2_dedicated_host_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go-v2/aws" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" @@ -93,7 +94,7 @@ func TestEC2DedicatedHosts_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := h.getAll(config.Config{ + names, err := h.getAll(context.Background(), config.Config{ EC2DedicatedHosts: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/ec2_dedicated_host_types.go b/aws/resources/ec2_dedicated_host_types.go index 9d80890a..67b09210 100644 --- a/aws/resources/ec2_dedicated_host_types.go +++ b/aws/resources/ec2_dedicated_host_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" @@ -35,8 +36,8 @@ func (h *EC2DedicatedHosts) MaxBatchSize() int { return 49 } -func (h *EC2DedicatedHosts) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := h.getAll(configObj) +func (h *EC2DedicatedHosts) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := h.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/ec2_key_pair.go b/aws/resources/ec2_key_pair.go index 9cdd2c0a..0684d8ff 100644 --- a/aws/resources/ec2_key_pair.go +++ b/aws/resources/ec2_key_pair.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/service/ec2" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/cloud-nuke/logging" @@ -11,7 +12,7 @@ import ( ) // getAllEc2KeyPairs extracts the list of existing ec2 key pairs. -func (k *EC2KeyPairs) getAll(configObj config.Config) ([]*string, error) { +func (k *EC2KeyPairs) getAll(c context.Context, configObj config.Config) ([]*string, error) { result, err := k.Client.DescribeKeyPairs(&ec2.DescribeKeyPairsInput{}) if err != nil { return nil, errors.WithStackTrace(err) diff --git a/aws/resources/ec2_key_pair_test.go b/aws/resources/ec2_key_pair_test.go index eee51897..6b7a80dd 100644 --- a/aws/resources/ec2_key_pair_test.go +++ b/aws/resources/ec2_key_pair_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go-v2/aws" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" @@ -82,7 +83,7 @@ func TestEC2KeyPairs_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := k.getAll(config.Config{ + names, err := k.getAll(context.Background(), config.Config{ EC2KeyPairs: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/ec2_key_pair_types.go b/aws/resources/ec2_key_pair_types.go index 7dbac5d6..7623ec09 100644 --- a/aws/resources/ec2_key_pair_types.go +++ b/aws/resources/ec2_key_pair_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" @@ -34,8 +35,8 @@ func (k *EC2KeyPairs) MaxBatchSize() int { return 200 } -func (k *EC2KeyPairs) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := k.getAll(configObj) +func (k *EC2KeyPairs) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := k.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/ec2_test.go b/aws/resources/ec2_test.go index a098ac27..a9f92482 100644 --- a/aws/resources/ec2_test.go +++ b/aws/resources/ec2_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go-v2/aws" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" @@ -120,7 +121,7 @@ func TestEc2Instances_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := ei.getAll(config.Config{ + names, err := ei.getAll(context.Background(), config.Config{ EC2: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/ec2_types.go b/aws/resources/ec2_types.go index 00ce3348..94609a7e 100644 --- a/aws/resources/ec2_types.go +++ b/aws/resources/ec2_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" @@ -35,8 +36,8 @@ func (ei *EC2Instances) MaxBatchSize() int { return 49 } -func (ei *EC2Instances) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := ei.getAll(configObj) +func (ei *EC2Instances) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := ei.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/ec2_vpc.go b/aws/resources/ec2_vpc.go index 799cae38..9063119c 100644 --- a/aws/resources/ec2_vpc.go +++ b/aws/resources/ec2_vpc.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/util" "time" @@ -50,7 +51,7 @@ func (v *EC2VPCs) getFirstSeenTag(vpc ec2.Vpc) (*time.Time, error) { return nil, nil } -func (v *EC2VPCs) getAll(configObj config.Config) ([]*string, error) { +func (v *EC2VPCs) getAll(c context.Context, configObj config.Config) ([]*string, error) { result, err := v.Client.DescribeVpcs(&ec2.DescribeVpcsInput{ Filters: []*ec2.Filter{ // Note: this filter omits the default since there is special diff --git a/aws/resources/ec2_vpc_test.go b/aws/resources/ec2_vpc_test.go index 3f278d03..d1c46f3a 100644 --- a/aws/resources/ec2_vpc_test.go +++ b/aws/resources/ec2_vpc_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go-v2/aws" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" @@ -99,7 +100,7 @@ func TestEC2VPC_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := vpc.getAll(config.Config{ + names, err := vpc.getAll(context.Background(), config.Config{ VPC: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/ec2_vpc_types.go b/aws/resources/ec2_vpc_types.go index e149ae79..e22dd418 100644 --- a/aws/resources/ec2_vpc_types.go +++ b/aws/resources/ec2_vpc_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" @@ -34,8 +35,8 @@ func (v *EC2VPCs) MaxBatchSize() int { return 49 } -func (v *EC2VPCs) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := v.getAll(configObj) +func (v *EC2VPCs) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := v.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/ecr.go b/aws/resources/ecr.go index 8f25c1d8..837762a6 100644 --- a/aws/resources/ecr.go +++ b/aws/resources/ecr.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ecr" "github.com/gruntwork-io/cloud-nuke/config" @@ -11,7 +12,7 @@ import ( commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" ) -func (registry *ECR) getAll(configObj config.Config) ([]*string, error) { +func (registry *ECR) getAll(c context.Context, configObj config.Config) ([]*string, error) { repositoryNames := []*string{} paginator := func(output *ecr.DescribeRepositoriesOutput, lastPage bool) bool { diff --git a/aws/resources/ecr_test.go b/aws/resources/ecr_test.go index bf85b3df..fa995eb6 100644 --- a/aws/resources/ecr_test.go +++ b/aws/resources/ecr_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ecr" "github.com/aws/aws-sdk-go/service/ecr/ecriface" @@ -78,7 +79,7 @@ func TestECR_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := er.getAll(config.Config{ + names, err := er.getAll(context.Background(), config.Config{ ECRRepository: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/ecr_types.go b/aws/resources/ecr_types.go index b1c30443..e4c7cf85 100644 --- a/aws/resources/ecr_types.go +++ b/aws/resources/ecr_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ecr" @@ -31,8 +32,8 @@ func (registry *ECR) MaxBatchSize() int { return 50 } -func (registry *ECR) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := registry.getAll(configObj) +func (registry *ECR) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := registry.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/ecs_cluster.go b/aws/resources/ecs_cluster.go index cf47669d..e219c4e0 100644 --- a/aws/resources/ecs_cluster.go +++ b/aws/resources/ecs_cluster.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/util" "time" @@ -94,7 +95,7 @@ func shouldIncludeECSCluster(cluster *ecs.Cluster, configObj config.Config) bool return configObj.ECSCluster.ShouldInclude(config.ResourceValue{Name: cluster.ClusterName}) } -func (clusters *ECSClusters) getAll(configObj config.Config) ([]*string, error) { +func (clusters *ECSClusters) getAll(c context.Context, configObj config.Config) ([]*string, error) { clusterArns, err := clusters.getAllActiveEcsClusterArns(configObj) if err != nil { logging.Logger.Debugf("Error getting all ECS clusters with `ACTIVE` status") diff --git a/aws/resources/ecs_cluster_test.go b/aws/resources/ecs_cluster_test.go index ccb3dea3..50a6e431 100644 --- a/aws/resources/ecs_cluster_test.go +++ b/aws/resources/ecs_cluster_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ecs" "github.com/aws/aws-sdk-go/service/ecs/ecsiface" @@ -113,7 +114,7 @@ func TestEC2Cluster_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := ec.getAll(config.Config{ + names, err := ec.getAll(context.Background(), config.Config{ ECSCluster: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/ecs_cluster_types.go b/aws/resources/ecs_cluster_types.go index 050c7d89..bb66786c 100644 --- a/aws/resources/ecs_cluster_types.go +++ b/aws/resources/ecs_cluster_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ecs" @@ -41,8 +42,8 @@ func (clusters *ECSClusters) MaxBatchSize() int { return maxBatchSize } -func (clusters *ECSClusters) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := clusters.getAll(configObj) +func (clusters *ECSClusters) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := clusters.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/ecs_service.go b/aws/resources/ecs_service.go index 3674eac8..a4bd8c00 100644 --- a/aws/resources/ecs_service.go +++ b/aws/resources/ecs_service.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/telemetry" "github.com/gruntwork-io/cloud-nuke/util" commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" @@ -70,7 +71,7 @@ func (services *ECSServices) filterOutRecentServices(clusterArn *string, ecsServ // clusters. For ECS, need to track ECS clusters of services as all service // level API endpoints require providing the corresponding cluster. // Note that this looks up services by ECS cluster ARNs. -func (services *ECSServices) getAll(configObj config.Config) ([]*string, error) { +func (services *ECSServices) getAll(c context.Context, configObj config.Config) ([]*string, error) { ecsClusterArns, err := services.getAllEcsClusters() if err != nil { return nil, errors.WithStackTrace(err) diff --git a/aws/resources/ecs_service_test.go b/aws/resources/ecs_service_test.go index 4fe9ca11..591b0af5 100644 --- a/aws/resources/ecs_service_test.go +++ b/aws/resources/ecs_service_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ecs" "github.com/aws/aws-sdk-go/service/ecs/ecsiface" @@ -114,7 +115,7 @@ func TestEC2Service_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := es.getAll(config.Config{ + names, err := es.getAll(context.Background(), config.Config{ ECSService: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/ecs_service_types.go b/aws/resources/ecs_service_types.go index 25340490..759e938a 100644 --- a/aws/resources/ecs_service_types.go +++ b/aws/resources/ecs_service_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ecs" @@ -35,8 +36,8 @@ func (services *ECSServices) MaxBatchSize() int { return 49 } -func (services *ECSServices) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := services.getAll(configObj) +func (services *ECSServices) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := services.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/efs.go b/aws/resources/efs.go index a0408cf9..b0b9a56e 100644 --- a/aws/resources/efs.go +++ b/aws/resources/efs.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/telemetry" commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" "sync" @@ -15,7 +16,7 @@ import ( "github.com/hashicorp/go-multierror" ) -func (ef *ElasticFileSystem) getAll(configObj config.Config) ([]*string, error) { +func (ef *ElasticFileSystem) getAll(c context.Context, configObj config.Config) ([]*string, error) { allEfs := []*string{} err := ef.Client.DescribeFileSystemsPages(&efs.DescribeFileSystemsInput{}, func(page *efs.DescribeFileSystemsOutput, lastPage bool) bool { diff --git a/aws/resources/efs_test.go b/aws/resources/efs_test.go index 6510350e..2a8ed99f 100644 --- a/aws/resources/efs_test.go +++ b/aws/resources/efs_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/efs" "github.com/aws/aws-sdk-go/service/efs/efsiface" @@ -102,7 +103,7 @@ func TestEFS_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := ef.getAll(config.Config{ + names, err := ef.getAll(context.Background(), config.Config{ ElasticFileSystem: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/efs_types.go b/aws/resources/efs_types.go index 2b179d2d..2044f719 100644 --- a/aws/resources/efs_types.go +++ b/aws/resources/efs_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/efs" @@ -31,8 +32,8 @@ func (ef *ElasticFileSystem) MaxBatchSize() int { return 10 } -func (ef *ElasticFileSystem) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := ef.getAll(configObj) +func (ef *ElasticFileSystem) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := ef.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/eip.go b/aws/resources/eip.go index ab4fce85..72789834 100644 --- a/aws/resources/eip.go +++ b/aws/resources/eip.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/telemetry" "github.com/gruntwork-io/cloud-nuke/util" commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" @@ -51,7 +52,7 @@ func (ea *EIPAddresses) getFirstSeenTag(address ec2.Address) (*time.Time, error) } // Returns a formatted string of EIP allocation ids -func (ea *EIPAddresses) getAll(configObj config.Config) ([]*string, error) { +func (ea *EIPAddresses) getAll(c context.Context, configObj config.Config) ([]*string, error) { result, err := ea.Client.DescribeAddresses(&ec2.DescribeAddressesInput{}) if err != nil { return nil, errors.WithStackTrace(err) diff --git a/aws/resources/eip_test.go b/aws/resources/eip_test.go index 468c505c..0da5f47e 100644 --- a/aws/resources/eip_test.go +++ b/aws/resources/eip_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go-v2/aws" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" @@ -99,7 +100,7 @@ func TestEIPAddress_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := ea.getAll(config.Config{ + names, err := ea.getAll(context.Background(), config.Config{ ElasticIP: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/eip_types.go b/aws/resources/eip_types.go index 95052c58..3cce1e05 100644 --- a/aws/resources/eip_types.go +++ b/aws/resources/eip_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" @@ -35,8 +36,8 @@ func (address *EIPAddresses) MaxBatchSize() int { return 49 } -func (address *EIPAddresses) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := address.getAll(configObj) +func (address *EIPAddresses) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := address.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/eks.go b/aws/resources/eks.go index 7223b04e..5c484801 100644 --- a/aws/resources/eks.go +++ b/aws/resources/eks.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/eks" "github.com/gruntwork-io/cloud-nuke/config" @@ -15,7 +16,7 @@ import ( ) // getAll returns a list of strings of EKS Cluster Names that uniquely identify each cluster. -func (clusters *EKSClusters) getAll(configObj config.Config) ([]*string, error) { +func (clusters *EKSClusters) getAll(c context.Context, configObj config.Config) ([]*string, error) { result, err := clusters.Client.ListClusters(&eks.ListClustersInput{}) if err != nil { return nil, errors.WithStackTrace(err) diff --git a/aws/resources/eks_test.go b/aws/resources/eks_test.go index 349f8ff0..4fba7bc6 100644 --- a/aws/resources/eks_test.go +++ b/aws/resources/eks_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "testing" "time" @@ -95,7 +96,7 @@ func TestEKSClusterGetAll(t *testing.T) { }, } - clusters, err := eksCluster.getAll(config.Config{}) + clusters, err := eksCluster.getAll(context.Background(), config.Config{}) require.NoError(t, err) require.Contains(t, awsgo.StringValueSlice(clusters), testClusterName) } diff --git a/aws/resources/eks_types.go b/aws/resources/eks_types.go index adca8ef4..e0e924e0 100644 --- a/aws/resources/eks_types.go +++ b/aws/resources/eks_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/eks" @@ -37,8 +38,8 @@ func (clusters *EKSClusters) MaxBatchSize() int { return 10 } -func (clusters *EKSClusters) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := clusters.getAll(configObj) +func (clusters *EKSClusters) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := clusters.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/elasticache.go b/aws/resources/elasticache.go index f8f3949f..10a4e99a 100644 --- a/aws/resources/elasticache.go +++ b/aws/resources/elasticache.go @@ -1,6 +1,7 @@ package resources import ( + "context" "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" @@ -15,7 +16,7 @@ import ( ) // Returns a formatted string of Elasticache cluster Ids -func (cache *Elasticaches) getAll(configObj config.Config) ([]*string, error) { +func (cache *Elasticaches) getAll(c context.Context, configObj config.Config) ([]*string, error) { // First, get any cache clusters that are replication groups, which will be the case for all multi-node Redis clusters replicationGroupsResult, replicationGroupsErr := cache.Client.DescribeReplicationGroups(&elasticache.DescribeReplicationGroupsInput{}) if replicationGroupsErr != nil { @@ -210,7 +211,7 @@ func (err CouldNotLookupCacheClusterErr) Error() string { Elasticache Parameter Groups */ -func (pg *ElasticacheParameterGroups) getAll(configObj config.Config) ([]*string, error) { +func (pg *ElasticacheParameterGroups) getAll(c context.Context, configObj config.Config) ([]*string, error) { var paramGroupNames []*string err := pg.Client.DescribeCacheParameterGroupsPages( &elasticache.DescribeCacheParameterGroupsInput{}, @@ -276,7 +277,7 @@ func (pg *ElasticacheParameterGroups) nukeAll(paramGroupNames []*string) error { /* Elasticache Subnet Groups */ -func (sg *ElasticacheSubnetGroups) getAll(configObj config.Config) ([]*string, error) { +func (sg *ElasticacheSubnetGroups) getAll(c context.Context, configObj config.Config) ([]*string, error) { var subnetGroupNames []*string err := sg.Client.DescribeCacheSubnetGroupsPages( &elasticache.DescribeCacheSubnetGroupsInput{}, diff --git a/aws/resources/elasticache_test.go b/aws/resources/elasticache_test.go index 51ff49b9..960dad17 100644 --- a/aws/resources/elasticache_test.go +++ b/aws/resources/elasticache_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/elasticache" "github.com/aws/aws-sdk-go/service/elasticache/elasticacheiface" @@ -89,7 +90,7 @@ func TestElasticache_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := ec.getAll(config.Config{ + names, err := ec.getAll(context.Background(), config.Config{ Elasticache: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/elasticache_types.go b/aws/resources/elasticache_types.go index 2bc5b845..6d5b0a2c 100644 --- a/aws/resources/elasticache_types.go +++ b/aws/resources/elasticache_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/elasticache" @@ -35,8 +36,8 @@ func (cache *Elasticaches) MaxBatchSize() int { return 49 } -func (cache *Elasticaches) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := cache.getAll(configObj) +func (cache *Elasticaches) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := cache.getAll(c, configObj) if err != nil { return nil, err } @@ -83,8 +84,8 @@ func (pg *ElasticacheParameterGroups) MaxBatchSize() int { return 49 } -func (pg *ElasticacheParameterGroups) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := pg.getAll(configObj) +func (pg *ElasticacheParameterGroups) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := pg.getAll(c, configObj) if err != nil { return nil, err } @@ -130,8 +131,8 @@ func (sg *ElasticacheSubnetGroups) MaxBatchSize() int { return 49 } -func (sg *ElasticacheSubnetGroups) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := sg.getAll(configObj) +func (sg *ElasticacheSubnetGroups) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := sg.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/elb.go b/aws/resources/elb.go index f8e1fec9..b6fbee3f 100644 --- a/aws/resources/elb.go +++ b/aws/resources/elb.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/cloud-nuke/telemetry" commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" @@ -33,7 +34,7 @@ func (balancer *LoadBalancers) waitUntilElbDeleted(input *elb.DescribeLoadBalanc } // Returns a formatted string of ELB names -func (balancer *LoadBalancers) getAll(configObj config.Config) ([]*string, error) { +func (balancer *LoadBalancers) getAll(c context.Context, configObj config.Config) ([]*string, error) { result, err := balancer.Client.DescribeLoadBalancers(&elb.DescribeLoadBalancersInput{}) if err != nil { return nil, errors.WithStackTrace(err) diff --git a/aws/resources/elb_test.go b/aws/resources/elb_test.go index 80c4b082..410b0757 100644 --- a/aws/resources/elb_test.go +++ b/aws/resources/elb_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/elb" @@ -79,7 +80,7 @@ func TestElb_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := balancer.getAll(config.Config{ + names, err := balancer.getAll(context.Background(), config.Config{ ELBv1: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/elb_types.go b/aws/resources/elb_types.go index 70f4bffa..3bc4b1f0 100644 --- a/aws/resources/elb_types.go +++ b/aws/resources/elb_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/elb" @@ -35,8 +36,8 @@ func (balancer *LoadBalancers) MaxBatchSize() int { return 49 } -func (balancer *LoadBalancers) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := balancer.getAll(configObj) +func (balancer *LoadBalancers) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := balancer.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/elbv2.go b/aws/resources/elbv2.go index fca5642d..6c3ce7d9 100644 --- a/aws/resources/elbv2.go +++ b/aws/resources/elbv2.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/elbv2" "github.com/gruntwork-io/cloud-nuke/config" @@ -12,7 +13,7 @@ import ( ) // Returns a formatted string of ELBv2 Arns -func (balancer *LoadBalancersV2) getAll(configObj config.Config) ([]*string, error) { +func (balancer *LoadBalancersV2) getAll(c context.Context, configObj config.Config) ([]*string, error) { result, err := balancer.Client.DescribeLoadBalancers(&elbv2.DescribeLoadBalancersInput{}) if err != nil { return nil, errors.WithStackTrace(err) diff --git a/aws/resources/elbv2_test.go b/aws/resources/elbv2_test.go index f8f55779..c864cc66 100644 --- a/aws/resources/elbv2_test.go +++ b/aws/resources/elbv2_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/elbv2" "github.com/aws/aws-sdk-go/service/elbv2/elbv2iface" @@ -85,7 +86,7 @@ func TestElbV2_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := balancer.getAll(config.Config{ + names, err := balancer.getAll(context.Background(), config.Config{ ELBv2: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/elbv2_types.go b/aws/resources/elbv2_types.go index 10c4200e..d19e6284 100644 --- a/aws/resources/elbv2_types.go +++ b/aws/resources/elbv2_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/elbv2" @@ -35,8 +36,8 @@ func (balancer *LoadBalancersV2) ResourceIdentifiers() []string { return balancer.Arns } -func (balancer *LoadBalancersV2) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := balancer.getAll(configObj) +func (balancer *LoadBalancersV2) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := balancer.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/guardduty.go b/aws/resources/guardduty.go index 10b7a560..1e3d37ec 100644 --- a/aws/resources/guardduty.go +++ b/aws/resources/guardduty.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/telemetry" commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" "time" @@ -18,7 +19,7 @@ type DetectorOutputWithID struct { Output *guardduty.GetDetectorOutput } -func (gd *GuardDuty) getAll(configObj config.Config) ([]*string, error) { +func (gd *GuardDuty) getAll(c context.Context, configObj config.Config) ([]*string, error) { var detectorIdsToInclude []*string var detectorIds []*string err := gd.Client.ListDetectorsPages(&guardduty.ListDetectorsInput{}, func(page *guardduty.ListDetectorsOutput, lastPage bool) bool { diff --git a/aws/resources/guardduty_test.go b/aws/resources/guardduty_test.go index ea2b93ca..bf516c1a 100644 --- a/aws/resources/guardduty_test.go +++ b/aws/resources/guardduty_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/guardduty" "github.com/aws/aws-sdk-go/service/guardduty/guarddutyiface" @@ -70,7 +71,7 @@ func TestGuardDuty_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := gd.getAll(config.Config{ + names, err := gd.getAll(context.Background(), config.Config{ GuardDuty: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/guardduty_types.go b/aws/resources/guardduty_types.go index 755de2a6..0b2eed2d 100644 --- a/aws/resources/guardduty_types.go +++ b/aws/resources/guardduty_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/guardduty" @@ -30,8 +31,8 @@ func (gd *GuardDuty) MaxBatchSize() int { return 10 } -func (gd *GuardDuty) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := gd.getAll(configObj) +func (gd *GuardDuty) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := gd.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/iam.go b/aws/resources/iam.go index f7a820ef..07fc7c12 100644 --- a/aws/resources/iam.go +++ b/aws/resources/iam.go @@ -1,6 +1,7 @@ package resources import ( + "context" "fmt" "github.com/gruntwork-io/cloud-nuke/telemetry" "github.com/gruntwork-io/cloud-nuke/util" @@ -19,7 +20,7 @@ import ( ) // List all IAM users in the AWS account and returns a slice of the UserNames -func (iu *IAMUsers) getAll(configObj config.Config) ([]*string, error) { +func (iu *IAMUsers) getAll(c context.Context, configObj config.Config) ([]*string, error) { input := &iam.ListUsersInput{} var userNames []*string diff --git a/aws/resources/iam_group.go b/aws/resources/iam_group.go index 0c05f8e1..72adf8de 100644 --- a/aws/resources/iam_group.go +++ b/aws/resources/iam_group.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/iam" "github.com/gruntwork-io/cloud-nuke/config" @@ -13,7 +14,7 @@ import ( "sync" ) -func (ig *IAMGroups) getAll(configObj config.Config) ([]*string, error) { +func (ig *IAMGroups) getAll(c context.Context, configObj config.Config) ([]*string, error) { var allIamGroups []*string err := ig.Client.ListGroupsPages( &iam.ListGroupsInput{}, diff --git a/aws/resources/iam_group_test.go b/aws/resources/iam_group_test.go index 22ebe905..b0da25b5 100644 --- a/aws/resources/iam_group_test.go +++ b/aws/resources/iam_group_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/service/iam/iamiface" "github.com/gruntwork-io/cloud-nuke/telemetry" "regexp" @@ -111,7 +112,7 @@ func TestIamGroups_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := ig.getAll(config.Config{ + names, err := ig.getAll(context.Background(), config.Config{ IAMGroups: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/iam_group_types.go b/aws/resources/iam_group_types.go index 0e23d14c..43ff7285 100644 --- a/aws/resources/iam_group_types.go +++ b/aws/resources/iam_group_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" @@ -35,8 +36,8 @@ func (ig *IAMGroups) MaxBatchSize() int { return 49 } -func (ig *IAMGroups) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := ig.getAll(configObj) +func (ig *IAMGroups) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := ig.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/iam_policy.go b/aws/resources/iam_policy.go index 6d98485e..c7ae2e12 100644 --- a/aws/resources/iam_policy.go +++ b/aws/resources/iam_policy.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/iam" "github.com/gruntwork-io/cloud-nuke/config" @@ -14,7 +15,7 @@ import ( ) // Returns the ARN of all customer managed policies -func (ip *IAMPolicies) getAll(configObj config.Config) ([]*string, error) { +func (ip *IAMPolicies) getAll(c context.Context, configObj config.Config) ([]*string, error) { var allIamPolicies []*string err := ip.Client.ListPoliciesPages( diff --git a/aws/resources/iam_policy_test.go b/aws/resources/iam_policy_test.go index faebb464..98b08e79 100644 --- a/aws/resources/iam_policy_test.go +++ b/aws/resources/iam_policy_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/iam" "github.com/aws/aws-sdk-go/service/iam/iamiface" @@ -115,7 +116,7 @@ func TestIAMPolicy_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := ip.getAll(config.Config{ + names, err := ip.getAll(context.Background(), config.Config{ IAMPolicies: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/iam_policy_types.go b/aws/resources/iam_policy_types.go index f0cf8e53..c8112e86 100644 --- a/aws/resources/iam_policy_types.go +++ b/aws/resources/iam_policy_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" @@ -34,8 +35,8 @@ func (ip *IAMPolicies) MaxBatchSize() int { return 20 } -func (ip *IAMPolicies) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := ip.getAll(configObj) +func (ip *IAMPolicies) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := ip.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/iam_role.go b/aws/resources/iam_role.go index 92e92400..e9de2569 100644 --- a/aws/resources/iam_role.go +++ b/aws/resources/iam_role.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/iam" "github.com/gruntwork-io/cloud-nuke/config" @@ -15,7 +16,7 @@ import ( ) // List all IAM Roles in the AWS account -func (ir *IAMRoles) getAll(configObj config.Config) ([]*string, error) { +func (ir *IAMRoles) getAll(c context.Context, configObj config.Config) ([]*string, error) { allIAMRoles := []*string{} err := ir.Client.ListRolesPages( &iam.ListRolesInput{}, diff --git a/aws/resources/iam_role_test.go b/aws/resources/iam_role_test.go index 1f4e4ed9..64f1d907 100644 --- a/aws/resources/iam_role_test.go +++ b/aws/resources/iam_role_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/iam" "github.com/aws/aws-sdk-go/service/iam/iamiface" @@ -113,7 +114,7 @@ func TestIAMRoles_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := ir.getAll(config.Config{ + names, err := ir.getAll(context.Background(), config.Config{ IAMRoles: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/iam_role_types.go b/aws/resources/iam_role_types.go index 931e4eb8..8fd4a0b0 100644 --- a/aws/resources/iam_role_types.go +++ b/aws/resources/iam_role_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" @@ -34,8 +35,8 @@ func (ir *IAMRoles) MaxBatchSize() int { return 20 } -func (ir *IAMRoles) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := ir.getAll(configObj) +func (ir *IAMRoles) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := ir.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/iam_service_linked_role.go b/aws/resources/iam_service_linked_role.go index 9ad0fbe7..b5486092 100644 --- a/aws/resources/iam_service_linked_role.go +++ b/aws/resources/iam_service_linked_role.go @@ -1,6 +1,7 @@ package resources import ( + "context" "errors" "fmt" "github.com/gruntwork-io/cloud-nuke/telemetry" @@ -19,7 +20,7 @@ import ( ) // List all IAM Roles in the AWS account -func (islr *IAMServiceLinkedRoles) getAll(configObj config.Config) ([]*string, error) { +func (islr *IAMServiceLinkedRoles) getAll(c context.Context, configObj config.Config) ([]*string, error) { allIAMServiceLinkedRoles := []*string{} err := islr.Client.ListRolesPages( &iam.ListRolesInput{}, diff --git a/aws/resources/iam_service_linked_role_test.go b/aws/resources/iam_service_linked_role_test.go index d8d50d99..54b8eb9f 100644 --- a/aws/resources/iam_service_linked_role_test.go +++ b/aws/resources/iam_service_linked_role_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/iam" "github.com/aws/aws-sdk-go/service/iam/iamiface" @@ -85,7 +86,7 @@ func TestIAMServiceLinkedRoles_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := islr.getAll(config.Config{ + names, err := islr.getAll(context.Background(), config.Config{ IAMServiceLinkedRoles: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/iam_service_linked_role_types.go b/aws/resources/iam_service_linked_role_types.go index d3618a28..80d55449 100644 --- a/aws/resources/iam_service_linked_role_types.go +++ b/aws/resources/iam_service_linked_role_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" @@ -34,8 +35,8 @@ func (islr *IAMServiceLinkedRoles) MaxBatchSize() int { return 49 } -func (islr *IAMServiceLinkedRoles) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := islr.getAll(configObj) +func (islr *IAMServiceLinkedRoles) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := islr.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/iam_test.go b/aws/resources/iam_test.go index e48a8966..ce75592e 100644 --- a/aws/resources/iam_test.go +++ b/aws/resources/iam_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go-v2/aws" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/iam" @@ -169,7 +170,7 @@ func TestIAMUsers_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := iu.getAll(config.Config{ + names, err := iu.getAll(context.Background(), config.Config{ IAMUsers: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/iam_types.go b/aws/resources/iam_types.go index e47fcd48..06288c95 100644 --- a/aws/resources/iam_types.go +++ b/aws/resources/iam_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" @@ -34,8 +35,8 @@ func (iu *IAMUsers) MaxBatchSize() int { return 49 } -func (iu *IAMUsers) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := iu.getAll(configObj) +func (iu *IAMUsers) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := iu.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/kinesis_stream.go b/aws/resources/kinesis_stream.go index 34856583..fc1d2bc9 100644 --- a/aws/resources/kinesis_stream.go +++ b/aws/resources/kinesis_stream.go @@ -1,6 +1,7 @@ package resources import ( + "context" "sync" "github.com/gruntwork-io/cloud-nuke/telemetry" @@ -16,7 +17,7 @@ import ( "github.com/hashicorp/go-multierror" ) -func (ks *KinesisStreams) getAll(configObj config.Config) ([]*string, error) { +func (ks *KinesisStreams) getAll(c context.Context, configObj config.Config) ([]*string, error) { allStreams := []*string{} err := ks.Client.ListStreamsPages(&kinesis.ListStreamsInput{}, func(page *kinesis.ListStreamsOutput, lastPage bool) bool { for _, stream := range page.StreamNames { diff --git a/aws/resources/kinesis_stream_test.go b/aws/resources/kinesis_stream_test.go index b4f24757..21aaf93e 100644 --- a/aws/resources/kinesis_stream_test.go +++ b/aws/resources/kinesis_stream_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/kinesis" "github.com/aws/aws-sdk-go/service/kinesis/kinesisiface" @@ -60,7 +61,7 @@ func TestKinesisStreams_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := ks.getAll(config.Config{ + names, err := ks.getAll(context.Background(), config.Config{ KinesisStream: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/kinesis_stream_types.go b/aws/resources/kinesis_stream_types.go index 77b43168..5cfffddc 100644 --- a/aws/resources/kinesis_stream_types.go +++ b/aws/resources/kinesis_stream_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/kinesis" @@ -37,8 +38,8 @@ func (ks *KinesisStreams) MaxBatchSize() int { return 35 } -func (ks *KinesisStreams) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := ks.getAll(configObj) +func (ks *KinesisStreams) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := ks.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/kms_customer_key.go b/aws/resources/kms_customer_key.go index a92a7db8..333e9a6c 100644 --- a/aws/resources/kms_customer_key.go +++ b/aws/resources/kms_customer_key.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/telemetry" commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" "sync" @@ -15,7 +16,7 @@ import ( "github.com/hashicorp/go-multierror" ) -func (kck *KmsCustomerKeys) getAll(configObj config.Config) ([]*string, error) { +func (kck *KmsCustomerKeys) getAll(c context.Context, configObj config.Config) ([]*string, error) { // Collect all keys in the account var keys []string err := kck.Client.ListKeysPages(&kms.ListKeysInput{}, func(page *kms.ListKeysOutput, lastPage bool) bool { diff --git a/aws/resources/kms_customer_key_test.go b/aws/resources/kms_customer_key_test.go index 1ccb7c35..85e78235 100644 --- a/aws/resources/kms_customer_key_test.go +++ b/aws/resources/kms_customer_key_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/kms" "github.com/aws/aws-sdk-go/service/kms/kmsiface" @@ -129,7 +130,7 @@ func TestKMS_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := kck.getAll(config.Config{ + names, err := kck.getAll(context.Background(), config.Config{ KMSCustomerKeys: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/kms_customer_key_types.go b/aws/resources/kms_customer_key_types.go index 74c46813..189c9752 100644 --- a/aws/resources/kms_customer_key_types.go +++ b/aws/resources/kms_customer_key_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/kms" @@ -39,8 +40,8 @@ func (kck *KmsCustomerKeys) MaxBatchSize() int { return 49 } -func (kck *KmsCustomerKeys) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := kck.getAll(configObj) +func (kck *KmsCustomerKeys) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := kck.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/lambda.go b/aws/resources/lambda.go index 8b14f103..71e0950f 100644 --- a/aws/resources/lambda.go +++ b/aws/resources/lambda.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/telemetry" commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" "time" @@ -13,7 +14,7 @@ import ( "github.com/gruntwork-io/cloud-nuke/report" ) -func (lf *LambdaFunctions) getAll(configObj config.Config) ([]*string, error) { +func (lf *LambdaFunctions) getAll(c context.Context, configObj config.Config) ([]*string, error) { var names []*string err := lf.Client.ListFunctionsPages( diff --git a/aws/resources/lambda_test.go b/aws/resources/lambda_test.go index 905e1222..969f365d 100644 --- a/aws/resources/lambda_test.go +++ b/aws/resources/lambda_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/lambda" "github.com/aws/aws-sdk-go/service/lambda/lambdaiface" @@ -84,7 +85,7 @@ func TestLambdaFunction_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := lf.getAll(config.Config{ + names, err := lf.getAll(context.Background(), config.Config{ LambdaFunction: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/lambda_types.go b/aws/resources/lambda_types.go index e0161c3b..e58e7b7b 100644 --- a/aws/resources/lambda_types.go +++ b/aws/resources/lambda_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/lambda" @@ -33,8 +34,8 @@ func (lf *LambdaFunctions) MaxBatchSize() int { return 49 } -func (lf *LambdaFunctions) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := lf.getAll(configObj) +func (lf *LambdaFunctions) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := lf.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/launch_config.go b/aws/resources/launch_config.go index 9bda252d..e46b0642 100644 --- a/aws/resources/launch_config.go +++ b/aws/resources/launch_config.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/autoscaling" "github.com/gruntwork-io/cloud-nuke/config" @@ -12,7 +13,7 @@ import ( ) // Returns a formatted string of Launch config Names -func (lc *LaunchConfigs) getAll(configObj config.Config) ([]*string, error) { +func (lc *LaunchConfigs) getAll(c context.Context, configObj config.Config) ([]*string, error) { result, err := lc.Client.DescribeLaunchConfigurations(&autoscaling.DescribeLaunchConfigurationsInput{}) if err != nil { return nil, errors.WithStackTrace(err) diff --git a/aws/resources/launch_config_test.go b/aws/resources/launch_config_test.go index 69ebe38a..888d6de1 100644 --- a/aws/resources/launch_config_test.go +++ b/aws/resources/launch_config_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/service/autoscaling/autoscalingiface" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/cloud-nuke/telemetry" @@ -78,7 +79,7 @@ func TestLaunchConfigurations_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := lc.getAll(config.Config{ + names, err := lc.getAll(context.Background(), config.Config{ LaunchConfiguration: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/launch_config_types.go b/aws/resources/launch_config_types.go index fd4cc0cf..abeccd9e 100644 --- a/aws/resources/launch_config_types.go +++ b/aws/resources/launch_config_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/autoscaling" @@ -35,8 +36,8 @@ func (lc *LaunchConfigs) ResourceIdentifiers() []string { return lc.LaunchConfigurationNames } -func (lc *LaunchConfigs) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := lc.getAll(configObj) +func (lc *LaunchConfigs) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := lc.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/launch_template.go b/aws/resources/launch_template.go index ca00bfb7..0144b1eb 100644 --- a/aws/resources/launch_template.go +++ b/aws/resources/launch_template.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" "github.com/gruntwork-io/cloud-nuke/config" @@ -12,7 +13,7 @@ import ( ) // Returns a formatted string of Launch Template Names -func (lt *LaunchTemplates) getAll(configObj config.Config) ([]*string, error) { +func (lt *LaunchTemplates) getAll(c context.Context, configObj config.Config) ([]*string, error) { result, err := lt.Client.DescribeLaunchTemplates(&ec2.DescribeLaunchTemplatesInput{}) if err != nil { return nil, errors.WithStackTrace(err) diff --git a/aws/resources/launch_template_test.go b/aws/resources/launch_template_test.go index 783b42ec..32f49d88 100644 --- a/aws/resources/launch_template_test.go +++ b/aws/resources/launch_template_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2/ec2iface" @@ -77,7 +78,7 @@ func TestLaunchTemplate_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := lt.getAll(config.Config{ + names, err := lt.getAll(context.Background(), config.Config{ LaunchTemplate: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/launch_template_types.go b/aws/resources/launch_template_types.go index 55f1c53d..18869e11 100644 --- a/aws/resources/launch_template_types.go +++ b/aws/resources/launch_template_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" @@ -35,8 +36,8 @@ func (lt *LaunchTemplates) ResourceIdentifiers() []string { return lt.LaunchTemplateNames } -func (lt *LaunchTemplates) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := lt.getAll(configObj) +func (lt *LaunchTemplates) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := lt.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/macie.go b/aws/resources/macie.go index a436d47f..a6c42288 100644 --- a/aws/resources/macie.go +++ b/aws/resources/macie.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/cloud-nuke/telemetry" commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" @@ -17,7 +18,7 @@ import ( // getAll will find and return any Macie accounts that were created via accepting an invite from another AWS Account // Unfortunately, the Macie API doesn't provide the metadata information we'd need to implement the configObj pattern, so we // currently can only accept a session and excludeAfter -func (mm *MacieMember) getAll(configObj config.Config) ([]*string, error) { +func (mm *MacieMember) getAll(c context.Context, configObj config.Config) ([]*string, error) { var macieStatus []*string output, err := mm.Client.GetMacieSession(&macie2.GetMacieSessionInput{}) diff --git a/aws/resources/macie_test.go b/aws/resources/macie_test.go index ad5bbcc2..eeb26cef 100644 --- a/aws/resources/macie_test.go +++ b/aws/resources/macie_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/macie2" "github.com/aws/aws-sdk-go/service/macie2/macie2iface" @@ -64,7 +65,7 @@ func TestMacie_GetAll(t *testing.T) { }, } - _, err := mm.getAll(config.Config{}) + _, err := mm.getAll(context.Background(), config.Config{}) require.NoError(t, err) } diff --git a/aws/resources/macie_types.go b/aws/resources/macie_types.go index 9bcdf0bd..c3590f8b 100644 --- a/aws/resources/macie_types.go +++ b/aws/resources/macie_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/macie2" @@ -31,8 +32,8 @@ func (mm *MacieMember) MaxBatchSize() int { return 10 } -func (mm *MacieMember) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := mm.getAll(configObj) +func (mm *MacieMember) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := mm.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/msk_cluster.go b/aws/resources/msk_cluster.go index 838965b8..47acedfc 100644 --- a/aws/resources/msk_cluster.go +++ b/aws/resources/msk_cluster.go @@ -1,13 +1,14 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/service/kafka" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/cloud-nuke/logging" "github.com/gruntwork-io/cloud-nuke/report" ) -func (m MSKCluster) getAll(configObj config.Config) ([]*string, error) { +func (m MSKCluster) getAll(c context.Context, configObj config.Config) ([]*string, error) { var clusterIDs []*string err := m.Client.ListClustersV2Pages(&kafka.ListClustersV2Input{}, func(page *kafka.ListClustersV2Output, lastPage bool) bool { diff --git a/aws/resources/msk_cluster_test.go b/aws/resources/msk_cluster_test.go index 090e8ff7..6d6ccfa4 100644 --- a/aws/resources/msk_cluster_test.go +++ b/aws/resources/msk_cluster_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "fmt" "regexp" "strings" @@ -48,7 +49,7 @@ func TestListMSKClustersSingle(t *testing.T) { Client: &mockMskClient, } - clusterIDs, err := msk.getAll(config.Config{}) + clusterIDs, err := msk.getAll(context.Background(), config.Config{}) if err != nil { t.Fatalf("Unable to list MSK Clusters: %v", err) } @@ -93,7 +94,7 @@ func TestListMSKClustersMultiple(t *testing.T) { Client: &mockMskClient, } - clusterIDs, err := msk.getAll(config.Config{}) + clusterIDs, err := msk.getAll(context.Background(), config.Config{}) if err != nil { t.Fatalf("Unable to list MSK Clusters: %v", err) } @@ -121,7 +122,7 @@ func TestGetAllMSKError(t *testing.T) { Client: &mockMskClient, } - _, err := msk.getAll(config.Config{}) + _, err := msk.getAll(context.Background(), config.Config{}) if err == nil { t.Fatalf("Expected error listing MSK Clusters") } diff --git a/aws/resources/msk_cluster_types.go b/aws/resources/msk_cluster_types.go index 4cb024e3..d9fc5616 100644 --- a/aws/resources/msk_cluster_types.go +++ b/aws/resources/msk_cluster_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/kafka" @@ -37,8 +38,8 @@ func (msk MSKCluster) MaxBatchSize() int { return 10 } -func (msk MSKCluster) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := msk.getAll(configObj) +func (msk MSKCluster) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := msk.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/nat_gateway.go b/aws/resources/nat_gateway.go index bc5d90e7..11bbefa7 100644 --- a/aws/resources/nat_gateway.go +++ b/aws/resources/nat_gateway.go @@ -1,6 +1,7 @@ package resources import ( + "context" "fmt" "github.com/gruntwork-io/cloud-nuke/telemetry" "github.com/gruntwork-io/cloud-nuke/util" @@ -19,7 +20,7 @@ import ( "github.com/hashicorp/go-multierror" ) -func (ngw *NatGateways) getAll(configObj config.Config) ([]*string, error) { +func (ngw *NatGateways) getAll(c context.Context, configObj config.Config) ([]*string, error) { allNatGateways := []*string{} input := &ec2.DescribeNatGatewaysInput{} err := ngw.Client.DescribeNatGatewaysPages( diff --git a/aws/resources/nat_gateway_test.go b/aws/resources/nat_gateway_test.go index dcfe3118..2dbed128 100644 --- a/aws/resources/nat_gateway_test.go +++ b/aws/resources/nat_gateway_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ec2/ec2iface" "github.com/gruntwork-io/cloud-nuke/telemetry" @@ -99,7 +100,7 @@ func TestNatGateway_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := ng.getAll(config.Config{ + names, err := ng.getAll(context.Background(), config.Config{ NatGateway: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/nat_gateway_types.go b/aws/resources/nat_gateway_types.go index bf6bcf39..649c108b 100644 --- a/aws/resources/nat_gateway_types.go +++ b/aws/resources/nat_gateway_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" @@ -37,8 +38,8 @@ func (secret NatGateways) MaxBatchSize() int { return 10 } -func (secret NatGateways) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := secret.getAll(configObj) +func (secret NatGateways) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := secret.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/oidc_provider.go b/aws/resources/oidc_provider.go index f8fa0f8c..e8e3b2e5 100644 --- a/aws/resources/oidc_provider.go +++ b/aws/resources/oidc_provider.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/telemetry" commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" "sync" @@ -28,7 +29,7 @@ type oidcProvider struct { // the requested rules (older-than and config file settings). Note that since the list API does not return the necessary // information to implement the filters, we use goroutines to asynchronously and concurrently fetch the details for all // the providers that are found in the account. -func (oidcprovider *OIDCProviders) getAll(configObj config.Config) ([]*string, error) { +func (oidcprovider *OIDCProviders) getAll(c context.Context, configObj config.Config) ([]*string, error) { output, err := oidcprovider.Client.ListOpenIDConnectProviders(&iam.ListOpenIDConnectProvidersInput{}) if err != nil { return nil, errors.WithStackTrace(err) diff --git a/aws/resources/oidc_provider_test.go b/aws/resources/oidc_provider_test.go index 956a3580..d804e0a0 100644 --- a/aws/resources/oidc_provider_test.go +++ b/aws/resources/oidc_provider_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/iam" "github.com/aws/aws-sdk-go/service/iam/iamiface" @@ -91,7 +92,7 @@ func TestOIDCProvider_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := oidcp.getAll(config.Config{ + names, err := oidcp.getAll(context.Background(), config.Config{ OIDCProvider: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/oidc_provider_types.go b/aws/resources/oidc_provider_types.go index 6d10bea6..795cc670 100644 --- a/aws/resources/oidc_provider_types.go +++ b/aws/resources/oidc_provider_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" @@ -36,8 +37,8 @@ func (oidcprovider *OIDCProviders) MaxBatchSize() int { return 10 } -func (oidcprovider *OIDCProviders) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := oidcprovider.getAll(configObj) +func (oidcprovider *OIDCProviders) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := oidcprovider.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/opensearch.go b/aws/resources/opensearch.go index 120c4a17..7e03e86a 100644 --- a/aws/resources/opensearch.go +++ b/aws/resources/opensearch.go @@ -1,6 +1,7 @@ package resources import ( + "context" "fmt" "github.com/gruntwork-io/cloud-nuke/telemetry" "github.com/gruntwork-io/cloud-nuke/util" @@ -22,7 +23,7 @@ import ( // the excludeAfter and configObj configurations. Note that OpenSearch Domains do not have resource timestamps, so we // use the first-seen tagging pattern to track which OpenSearch Domains should be nuked based on time. This routine will // tag resources with the first-seen tag if it does not have one. -func (osd *OpenSearchDomains) getAll(configObj config.Config) ([]*string, error) { +func (osd *OpenSearchDomains) getAll(c context.Context, configObj config.Config) ([]*string, error) { domains, err := osd.getAllActiveOpenSearchDomains() if err != nil { return nil, errors.WithStackTrace(err) diff --git a/aws/resources/opensearch_test.go b/aws/resources/opensearch_test.go index 90e1f1a5..877624b9 100644 --- a/aws/resources/opensearch_test.go +++ b/aws/resources/opensearch_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/opensearchservice" "github.com/aws/aws-sdk-go/service/opensearchservice/opensearchserviceiface" @@ -111,7 +112,7 @@ func TestOpenSearch_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := osd.getAll(config.Config{ + names, err := osd.getAll(context.Background(), config.Config{ OpenSearchDomain: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/opensearch_types.go b/aws/resources/opensearch_types.go index a527de0b..f049686c 100644 --- a/aws/resources/opensearch_types.go +++ b/aws/resources/opensearch_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/opensearchservice" @@ -38,8 +39,8 @@ func (osd *OpenSearchDomains) MaxBatchSize() int { return 10 } -func (osd *OpenSearchDomains) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := osd.getAll(configObj) +func (osd *OpenSearchDomains) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := osd.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/rds.go b/aws/resources/rds.go index 5a89f7d7..f6d63c05 100644 --- a/aws/resources/rds.go +++ b/aws/resources/rds.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/rds" @@ -13,7 +14,7 @@ import ( commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" ) -func (di *DBInstances) getAll(configObj config.Config) ([]*string, error) { +func (di *DBInstances) getAll(c context.Context, configObj config.Config) ([]*string, error) { result, err := di.Client.DescribeDBInstances(&rds.DescribeDBInstancesInput{}) if err != nil { return nil, errors.WithStackTrace(err) diff --git a/aws/resources/rds_cluster.go b/aws/resources/rds_cluster.go index ce3d0168..c94c9b56 100644 --- a/aws/resources/rds_cluster.go +++ b/aws/resources/rds_cluster.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/util" "time" @@ -36,7 +37,7 @@ func (instance *DBClusters) waitUntilRdsClusterDeleted(input *rds.DescribeDBClus return RdsDeleteError{name: *input.DBClusterIdentifier} } -func (instance *DBClusters) getAll(configObj config.Config) ([]*string, error) { +func (instance *DBClusters) getAll(c context.Context, configObj config.Config) ([]*string, error) { result, err := instance.Client.DescribeDBClusters(&rds.DescribeDBClustersInput{}) if err != nil { return nil, errors.WithStackTrace(err) diff --git a/aws/resources/rds_cluster_test.go b/aws/resources/rds_cluster_test.go index bb706982..54568709 100644 --- a/aws/resources/rds_cluster_test.go +++ b/aws/resources/rds_cluster_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws/awserr" "strings" "testing" @@ -51,12 +52,12 @@ func TestRDSClusterGetAll(t *testing.T) { } // Testing empty config - clusters, err := dbCluster.getAll(config.Config{DBClusters: config.ResourceType{}}) + clusters, err := dbCluster.getAll(context.Background(), config.Config{DBClusters: config.ResourceType{}}) assert.NoError(t, err) assert.Contains(t, awsgo.StringValueSlice(clusters), strings.ToLower(testName)) // Testing db cluster exclusion - clusters, err = dbCluster.getAll(config.Config{ + clusters, err = dbCluster.getAll(context.Background(), config.Config{ DBClusters: config.ResourceType{ ExcludeRule: config.FilterRule{ TimeAfter: awsgo.Time(now.Add(-1)), diff --git a/aws/resources/rds_cluster_types.go b/aws/resources/rds_cluster_types.go index 35d31e4b..c8954109 100644 --- a/aws/resources/rds_cluster_types.go +++ b/aws/resources/rds_cluster_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/rds" @@ -33,8 +34,8 @@ func (instance *DBClusters) MaxBatchSize() int { return 49 } -func (instance *DBClusters) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := instance.getAll(configObj) +func (instance *DBClusters) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := instance.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/rds_subnet_group.go b/aws/resources/rds_subnet_group.go index 9193c72f..0427331c 100644 --- a/aws/resources/rds_subnet_group.go +++ b/aws/resources/rds_subnet_group.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/gruntwork-io/cloud-nuke/config" "time" @@ -34,7 +35,7 @@ func (dsg *DBSubnetGroups) waitUntilRdsDbSubnetGroupDeleted(name *string) error return RdsDeleteError{name: *name} } -func (dsg *DBSubnetGroups) getAll(configObj config.Config) ([]*string, error) { +func (dsg *DBSubnetGroups) getAll(c context.Context, configObj config.Config) ([]*string, error) { var names []*string err := dsg.Client.DescribeDBSubnetGroupsPages( &rds.DescribeDBSubnetGroupsInput{}, diff --git a/aws/resources/rds_subnet_group_test.go b/aws/resources/rds_subnet_group_test.go index 30cb7186..6f6bec18 100644 --- a/aws/resources/rds_subnet_group_test.go +++ b/aws/resources/rds_subnet_group_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/rds" @@ -73,7 +74,7 @@ func TestDBSubnetGroups_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := dsg.getAll(config.Config{ + names, err := dsg.getAll(context.Background(), config.Config{ DBSubnetGroups: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/rds_subnet_group_types.go b/aws/resources/rds_subnet_group_types.go index 5809e276..a4cea4ec 100644 --- a/aws/resources/rds_subnet_group_types.go +++ b/aws/resources/rds_subnet_group_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/rds" @@ -33,8 +34,8 @@ func (dsg *DBSubnetGroups) MaxBatchSize() int { return 49 } -func (dsg *DBSubnetGroups) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := dsg.getAll(configObj) +func (dsg *DBSubnetGroups) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := dsg.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/rds_test.go b/aws/resources/rds_test.go index 67c2af8d..7673e6cf 100644 --- a/aws/resources/rds_test.go +++ b/aws/resources/rds_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go/service/rds/rdsiface" "github.com/gruntwork-io/cloud-nuke/config" @@ -88,7 +89,7 @@ func TestDBInstances_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := di.getAll(config.Config{ + names, err := di.getAll(context.Background(), config.Config{ DBInstances: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/rds_types.go b/aws/resources/rds_types.go index 54fb5bcf..0bfc97c9 100644 --- a/aws/resources/rds_types.go +++ b/aws/resources/rds_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/rds" @@ -33,8 +34,8 @@ func (di *DBInstances) MaxBatchSize() int { return 49 } -func (di *DBInstances) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := di.getAll(configObj) +func (di *DBInstances) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := di.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/redshift.go b/aws/resources/redshift.go index fec465fd..6103794c 100644 --- a/aws/resources/redshift.go +++ b/aws/resources/redshift.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/redshift" "github.com/gruntwork-io/cloud-nuke/config" @@ -11,7 +12,7 @@ import ( commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" ) -func (rc *RedshiftClusters) getAll(configObj config.Config) ([]*string, error) { +func (rc *RedshiftClusters) getAll(c context.Context, configObj config.Config) ([]*string, error) { var clusterIds []*string err := rc.Client.DescribeClustersPages( &redshift.DescribeClustersInput{}, diff --git a/aws/resources/redshift_test.go b/aws/resources/redshift_test.go index 2a08141d..544b3bef 100644 --- a/aws/resources/redshift_test.go +++ b/aws/resources/redshift_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/redshift" "github.com/aws/aws-sdk-go/service/redshift/redshiftiface" @@ -83,7 +84,7 @@ func TestRedshiftCluster_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := rc.getAll(config.Config{ + names, err := rc.getAll(context.Background(), config.Config{ Redshift: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/redshift_types.go b/aws/resources/redshift_types.go index 14e51703..aa415c64 100644 --- a/aws/resources/redshift_types.go +++ b/aws/resources/redshift_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/redshift" @@ -33,8 +34,8 @@ func (rc *RedshiftClusters) MaxBatchSize() int { return 49 } -func (rc *RedshiftClusters) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := rc.getAll(configObj) +func (rc *RedshiftClusters) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := rc.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/s3.go b/aws/resources/s3.go index 8a91e444..d98dd537 100644 --- a/aws/resources/s3.go +++ b/aws/resources/s3.go @@ -1,6 +1,7 @@ package resources import ( + "context" "fmt" "github.com/gruntwork-io/cloud-nuke/telemetry" "github.com/gruntwork-io/cloud-nuke/util" @@ -75,7 +76,7 @@ type S3Bucket struct { } // getAllS3Buckets returns a map of per region AWS S3 buckets which were created before excludeAfter -func (sb S3Buckets) getAll(configObj config.Config) ([]*string, error) { +func (sb S3Buckets) getAll(c context.Context, configObj config.Config) ([]*string, error) { input := &s3.ListBucketsInput{} output, err := sb.Client.ListBuckets(input) if err != nil { diff --git a/aws/resources/s3_test.go b/aws/resources/s3_test.go index 8cffdf5f..973f3b64 100644 --- a/aws/resources/s3_test.go +++ b/aws/resources/s3_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/s3" "github.com/aws/aws-sdk-go/service/s3/s3iface" @@ -119,7 +120,7 @@ func TestS3Bucket_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := sb.getAll(config.Config{ + names, err := sb.getAll(context.Background(), config.Config{ S3: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/s3_types.go b/aws/resources/s3_types.go index 40fa7e32..af17818a 100644 --- a/aws/resources/s3_types.go +++ b/aws/resources/s3_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" @@ -49,8 +50,8 @@ func (bucket *S3Buckets) ResourceIdentifiers() []string { return bucket.Names } -func (bucket *S3Buckets) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := bucket.getAll(configObj) +func (bucket *S3Buckets) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := bucket.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/sagemaker_notebook_instance.go b/aws/resources/sagemaker_notebook_instance.go index e515a282..bc781efe 100644 --- a/aws/resources/sagemaker_notebook_instance.go +++ b/aws/resources/sagemaker_notebook_instance.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/sagemaker" @@ -12,7 +13,7 @@ import ( commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" ) -func (smni *SageMakerNotebookInstances) getAll(configObj config.Config) ([]*string, error) { +func (smni *SageMakerNotebookInstances) getAll(c context.Context, configObj config.Config) ([]*string, error) { result, err := smni.Client.ListNotebookInstances(&sagemaker.ListNotebookInstancesInput{}) if err != nil { return nil, errors.WithStackTrace(err) diff --git a/aws/resources/sagemaker_notebook_instance_test.go b/aws/resources/sagemaker_notebook_instance_test.go index 305fcfc2..49c4caf8 100644 --- a/aws/resources/sagemaker_notebook_instance_test.go +++ b/aws/resources/sagemaker_notebook_instance_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go-v2/aws" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/sagemaker" @@ -95,7 +96,7 @@ func TestSageMakerNotebookInstances_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := smni.getAll(config.Config{ + names, err := smni.getAll(context.Background(), config.Config{ SageMakerNotebook: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/sagemaker_notebook_instance_types.go b/aws/resources/sagemaker_notebook_instance_types.go index d1305c2b..daa36c0f 100644 --- a/aws/resources/sagemaker_notebook_instance_types.go +++ b/aws/resources/sagemaker_notebook_instance_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sagemaker" @@ -33,8 +34,8 @@ func (smni *SageMakerNotebookInstances) MaxBatchSize() int { return 49 } -func (smni *SageMakerNotebookInstances) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := smni.getAll(configObj) +func (smni *SageMakerNotebookInstances) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := smni.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/secrets_manager.go b/aws/resources/secrets_manager.go index 89c608d0..946e48ea 100644 --- a/aws/resources/secrets_manager.go +++ b/aws/resources/secrets_manager.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/telemetry" commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" "sync" @@ -16,7 +17,7 @@ import ( "github.com/gruntwork-io/go-commons/errors" ) -func (sms *SecretsManagerSecrets) getAll(configObj config.Config) ([]*string, error) { +func (sms *SecretsManagerSecrets) getAll(c context.Context, configObj config.Config) ([]*string, error) { allSecrets := []*string{} input := &secretsmanager.ListSecretsInput{} err := sms.Client.ListSecretsPages( diff --git a/aws/resources/secrets_manager_test.go b/aws/resources/secrets_manager_test.go index b5ca9b40..07b7fb90 100644 --- a/aws/resources/secrets_manager_test.go +++ b/aws/resources/secrets_manager_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/secretsmanager" "github.com/aws/aws-sdk-go/service/secretsmanager/secretsmanageriface" @@ -92,7 +93,7 @@ func TestSecretsManagerSecrets_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := sms.getAll(config.Config{ + names, err := sms.getAll(context.Background(), config.Config{ SecretsManagerSecrets: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/secrets_manager_types.go b/aws/resources/secrets_manager_types.go index cbb59b8a..0c50f79d 100644 --- a/aws/resources/secrets_manager_types.go +++ b/aws/resources/secrets_manager_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/secretsmanager" @@ -37,8 +38,8 @@ func (sms *SecretsManagerSecrets) MaxBatchSize() int { return 10 } -func (sms *SecretsManagerSecrets) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := sms.getAll(configObj) +func (sms *SecretsManagerSecrets) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := sms.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/security_hub.go b/aws/resources/security_hub.go index 40e940fe..f09201dd 100644 --- a/aws/resources/security_hub.go +++ b/aws/resources/security_hub.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/config" "strings" "time" @@ -15,7 +16,7 @@ import ( commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" ) -func (sh *SecurityHub) getAll(configObj config.Config) ([]*string, error) { +func (sh *SecurityHub) getAll(c context.Context, configObj config.Config) ([]*string, error) { var securityHubArns []*string output, err := sh.Client.DescribeHub(&securityhub.DescribeHubInput{}) diff --git a/aws/resources/security_hub_test.go b/aws/resources/security_hub_test.go index 235ccc94..d10eff65 100644 --- a/aws/resources/security_hub_test.go +++ b/aws/resources/security_hub_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/service/securityhub/securityhubiface" "github.com/gruntwork-io/cloud-nuke/config" "testing" @@ -85,7 +86,7 @@ func TestSecurityHub_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := sh.getAll(config.Config{ + names, err := sh.getAll(context.Background(), config.Config{ SecurityHub: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/security_hub_types.go b/aws/resources/security_hub_types.go index f376d58c..27957cb9 100644 --- a/aws/resources/security_hub_types.go +++ b/aws/resources/security_hub_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/securityhub" @@ -31,8 +32,8 @@ func (sh *SecurityHub) MaxBatchSize() int { return 5 } -func (sh *SecurityHub) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := sh.getAll(configObj) +func (sh *SecurityHub) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := sh.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/snapshot.go b/aws/resources/snapshot.go index 3dd2eacd..6abd61d2 100644 --- a/aws/resources/snapshot.go +++ b/aws/resources/snapshot.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/cloud-nuke/telemetry" "github.com/gruntwork-io/cloud-nuke/util" @@ -15,7 +16,7 @@ import ( ) // Returns a formatted string of Snapshot snapshot ids -func (s *Snapshots) getAll(configObj config.Config) ([]*string, error) { +func (s *Snapshots) getAll(c context.Context, configObj config.Config) ([]*string, error) { // status - The status of the s (pending | completed | error). // Since the output of this function is used to delete the returned snapshots diff --git a/aws/resources/snapshot_test.go b/aws/resources/snapshot_test.go index 29ec2f3d..9c8d67bd 100644 --- a/aws/resources/snapshot_test.go +++ b/aws/resources/snapshot_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go/service/ec2/ec2iface" "github.com/gruntwork-io/cloud-nuke/config" @@ -76,7 +77,7 @@ func TestSnapshot_GetAll(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := s.getAll(config.Config{ + names, err := s.getAll(context.Background(), config.Config{ Snapshots: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/snapshot_types.go b/aws/resources/snapshot_types.go index 282b148d..05648263 100644 --- a/aws/resources/snapshot_types.go +++ b/aws/resources/snapshot_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" @@ -35,8 +36,8 @@ func (s *Snapshots) MaxBatchSize() int { return 49 } -func (s *Snapshots) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := s.getAll(configObj) +func (s *Snapshots) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := s.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/sns.go b/aws/resources/sns.go index eb3b569e..d23df3d2 100644 --- a/aws/resources/sns.go +++ b/aws/resources/sns.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/service/sns" "strings" "sync" @@ -20,7 +21,7 @@ import ( // getAllSNSTopics returns a list of all SNS topics in the region, filtering the name by the config // The SQS APIs do not return a creation date, therefore we tag the resources with a first seen time when the topic first appears. We then // use that tag to measure the excludeAfter time duration, and determine whether to nuke the resource based on that. -func (s *SNSTopic) getAll(configObj config.Config) ([]*string, error) { +func (s *SNSTopic) getAll(c context.Context, configObj config.Config) ([]*string, error) { var snsTopics []*string err := s.Client.ListTopicsPages(&sns.ListTopicsInput{}, func(page *sns.ListTopicsOutput, lastPage bool) bool { diff --git a/aws/resources/sns_test.go b/aws/resources/sns_test.go index 593357f1..fa25a7b1 100644 --- a/aws/resources/sns_test.go +++ b/aws/resources/sns_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/service/sns/snsiface" "regexp" "testing" @@ -97,7 +98,7 @@ func TestSNS_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := s.getAll(config.Config{ + names, err := s.getAll(context.Background(), config.Config{ SNS: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/sns_types.go b/aws/resources/sns_types.go index a374e75e..beb6f09f 100644 --- a/aws/resources/sns_types.go +++ b/aws/resources/sns_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sns" @@ -31,8 +32,8 @@ func (s *SNSTopic) MaxBatchSize() int { return 50 } -func (s *SNSTopic) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := s.getAll(configObj) +func (s *SNSTopic) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := s.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/sqs.go b/aws/resources/sqs.go index 8ab8885e..9c8c376c 100644 --- a/aws/resources/sqs.go +++ b/aws/resources/sqs.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/cloud-nuke/telemetry" commonTelemetry "github.com/gruntwork-io/go-commons/telemetry" @@ -15,7 +16,7 @@ import ( ) // Returns a formatted string of SQS Queue URLs -func (sq *SqsQueue) getAll(configObj config.Config) ([]*string, error) { +func (sq *SqsQueue) getAll(c context.Context, configObj config.Config) ([]*string, error) { result := []*string{} paginator := func(output *sqs.ListQueuesOutput, lastPage bool) bool { result = append(result, output.QueueUrls...) diff --git a/aws/resources/sqs_test.go b/aws/resources/sqs_test.go index 3fbdcbfa..488381c3 100644 --- a/aws/resources/sqs_test.go +++ b/aws/resources/sqs_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go-v2/aws" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/sqs" @@ -93,7 +94,7 @@ func TestSqsQueue_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := sq.getAll(config.Config{ + names, err := sq.getAll(context.Background(), config.Config{ SQS: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/sqs_types.go b/aws/resources/sqs_types.go index c965dc6b..752ae348 100644 --- a/aws/resources/sqs_types.go +++ b/aws/resources/sqs_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sqs" @@ -35,8 +36,8 @@ func (sq *SqsQueue) ResourceIdentifiers() []string { return sq.QueueUrls } -func (sq *SqsQueue) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := sq.getAll(configObj) +func (sq *SqsQueue) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := sq.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/resources/transit_gateway.go b/aws/resources/transit_gateway.go index df6d4773..84b75d35 100644 --- a/aws/resources/transit_gateway.go +++ b/aws/resources/transit_gateway.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" @@ -13,7 +14,7 @@ import ( ) // Returns a formatted string of TransitGateway IDs -func (tgw *TransitGateways) getAll(configObj config.Config) ([]*string, error) { +func (tgw *TransitGateways) getAll(c context.Context, configObj config.Config) ([]*string, error) { result, err := tgw.Client.DescribeTransitGateways(&ec2.DescribeTransitGatewaysInput{}) if err != nil { return nil, errors.WithStackTrace(err) @@ -73,7 +74,7 @@ func (tgw *TransitGateways) nukeAll(ids []*string) error { } // Returns a formatted string of TranstGatewayRouteTable IDs -func (tgw *TransitGatewaysRouteTables) getAll(configObj config.Config) ([]*string, error) { +func (tgw *TransitGatewaysRouteTables) getAll(c context.Context, configObj config.Config) ([]*string, error) { // Remove defalt route table, that will be deleted along with its TransitGateway param := &ec2.DescribeTransitGatewayRouteTablesInput{ Filters: []*ec2.Filter{ @@ -131,7 +132,7 @@ func (tgw *TransitGatewaysRouteTables) nukeAll(ids []*string) error { } // Returns a formated string of TransitGatewayVpcAttachment IDs -func (tgw *TransitGatewaysVpcAttachment) getAll(configObj config.Config) ([]*string, error) { +func (tgw *TransitGatewaysVpcAttachment) getAll(c context.Context, configObj config.Config) ([]*string, error) { result, err := tgw.Client.DescribeTransitGatewayVpcAttachments(&ec2.DescribeTransitGatewayVpcAttachmentsInput{}) if err != nil { return nil, errors.WithStackTrace(err) diff --git a/aws/resources/transit_gateway_test.go b/aws/resources/transit_gateway_test.go index f4a5bf61..772c8446 100644 --- a/aws/resources/transit_gateway_test.go +++ b/aws/resources/transit_gateway_test.go @@ -1,6 +1,7 @@ package resources import ( + "context" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2/ec2iface" @@ -102,7 +103,7 @@ func TestTransitGateways_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := tgw.getAll(config.Config{ + names, err := tgw.getAll(context.Background(), config.Config{ TransitGateway: tc.configObj, }) require.NoError(t, err) @@ -169,7 +170,7 @@ func TestTransitGatewayRouteTables_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := tgw.getAll(config.Config{ + names, err := tgw.getAll(context.Background(), config.Config{ TransitGatewayRouteTable: tc.configObj, }) require.NoError(t, err) @@ -235,7 +236,7 @@ func TestTransitGatewayVpcAttachments_GetAll(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - names, err := tgw.getAll(config.Config{ + names, err := tgw.getAll(context.Background(), config.Config{ TransitGatewaysVpcAttachment: tc.configObj, }) require.NoError(t, err) diff --git a/aws/resources/transit_gateway_types.go b/aws/resources/transit_gateway_types.go index 4b5ac162..42ab807a 100644 --- a/aws/resources/transit_gateway_types.go +++ b/aws/resources/transit_gateway_types.go @@ -1,6 +1,7 @@ package resources import ( + "context" awsgo "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" @@ -35,8 +36,8 @@ func (tgw *TransitGatewaysVpcAttachment) ResourceIdentifiers() []string { return tgw.Ids } -func (tgw *TransitGatewaysVpcAttachment) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := tgw.getAll(configObj) +func (tgw *TransitGatewaysVpcAttachment) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := tgw.getAll(c, configObj) if err != nil { return nil, err } @@ -80,8 +81,8 @@ func (tgw *TransitGatewaysRouteTables) ResourceIdentifiers() []string { return tgw.Ids } -func (tgw *TransitGatewaysRouteTables) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := tgw.getAll(configObj) +func (tgw *TransitGatewaysRouteTables) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := tgw.getAll(c, configObj) if err != nil { return nil, err } @@ -125,8 +126,8 @@ func (tgw *TransitGateways) ResourceIdentifiers() []string { return tgw.Ids } -func (tgw *TransitGateways) GetAndSetIdentifiers(configObj config.Config) ([]string, error) { - identifiers, err := tgw.getAll(configObj) +func (tgw *TransitGateways) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { + identifiers, err := tgw.getAll(c, configObj) if err != nil { return nil, err } diff --git a/aws/types.go b/aws/types.go index 015e337d..2fed23ab 100644 --- a/aws/types.go +++ b/aws/types.go @@ -1,6 +1,7 @@ package aws import ( + "context" "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/gruntwork-io/cloud-nuke/config" @@ -78,7 +79,7 @@ type AwsResources interface { ResourceIdentifiers() []string MaxBatchSize() int Nuke(identifiers []string) error - GetAndSetIdentifiers(configObj config.Config) ([]string, error) + GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) } type AwsRegionResource struct { diff --git a/commands/cli.go b/commands/cli.go index 0ed06c90..35f5c1ec 100644 --- a/commands/cli.go +++ b/commands/cli.go @@ -543,7 +543,7 @@ func handleGetResources(c *cli.Context, configObj config.Config, includeUnaliase } pterm.Println() - accountResources, err := aws.GetAllResources(query, configObj) + accountResources, err := aws.GetAllResources(c.Context, query, configObj) if err != nil { telemetry.TrackEvent(commonTelemetry.EventContext{ EventName: "Error inspecting resources", diff --git a/util/get_current_account_id.go b/util/get_current_account_id.go index 840a7f39..abb43518 100644 --- a/util/get_current_account_id.go +++ b/util/get_current_account_id.go @@ -7,12 +7,13 @@ import ( "github.com/gruntwork-io/go-commons/errors" ) +const ( + AccountIdKey = "accountId" +) + func GetCurrentAccountId(session *session.Session) (string, error) { stssvc := sts.New(session) - - input := &sts.GetCallerIdentityInput{} - - output, err := stssvc.GetCallerIdentity(input) + output, err := stssvc.GetCallerIdentity(&sts.GetCallerIdentityInput{}) if err != nil { return "", errors.WithStackTrace(err) }