-
-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d35d088
commit 342d131
Showing
16 changed files
with
1,161 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/ses" | ||
"github.com/gruntwork-io/cloud-nuke/config" | ||
"github.com/gruntwork-io/cloud-nuke/logging" | ||
"github.com/gruntwork-io/cloud-nuke/report" | ||
"github.com/gruntwork-io/go-commons/errors" | ||
) | ||
|
||
// Returns a formatted string of ses-configuartion set names | ||
func (s *SesConfigurationSet) getAll(c context.Context, configObj config.Config) ([]*string, error) { | ||
// Remove defalt route table, that will be deleted along with its TransitGateway | ||
param := &ses.ListConfigurationSetsInput{} | ||
|
||
result, err := s.Client.ListConfigurationSets(param) | ||
if err != nil { | ||
return nil, errors.WithStackTrace(err) | ||
} | ||
|
||
var setnames []*string | ||
for _, set := range result.ConfigurationSets { | ||
if configObj.SESConfigurationSet.ShouldInclude(config.ResourceValue{Name: set.Name}) { | ||
setnames = append(setnames, set.Name) | ||
} | ||
} | ||
|
||
return setnames, nil | ||
} | ||
|
||
// Deletes all sets | ||
func (s *SesConfigurationSet) nukeAll(sets []*string) error { | ||
if len(sets) == 0 { | ||
logging.Debugf("No SES configuartion sets to nuke in region %s", s.Region) | ||
return nil | ||
} | ||
|
||
logging.Debugf("Deleting all SES configuartion sets in region %s", s.Region) | ||
var deletedSets []*string | ||
|
||
for _, set := range sets { | ||
_, err := s.Client.DeleteConfigurationSet(&ses.DeleteConfigurationSetInput{ | ||
ConfigurationSetName: set, | ||
}) | ||
|
||
// Record status of this resource | ||
e := report.Entry{ | ||
Identifier: aws.StringValue(set), | ||
ResourceType: "SES configuartion set", | ||
Error: err, | ||
} | ||
report.Record(e) | ||
|
||
if err != nil { | ||
logging.Debugf("[Failed] %s", err) | ||
} else { | ||
deletedSets = append(deletedSets, set) | ||
logging.Debugf("Deleted SES configuartion set: %s", *set) | ||
} | ||
} | ||
|
||
logging.Debugf("[OK] %d SES configuartion set(s) deleted in %s", len(deletedSets), s.Region) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
awsgo "github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/ses" | ||
"github.com/aws/aws-sdk-go/service/ses/sesiface" | ||
"github.com/gruntwork-io/cloud-nuke/config" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type mockedSesConfigurationSet struct { | ||
sesiface.SESAPI | ||
DeleteConfigurationSetOutput ses.DeleteConfigurationSetOutput | ||
ListConfigurationSetsOutput ses.ListConfigurationSetsOutput | ||
} | ||
|
||
func (m mockedSesConfigurationSet) ListConfigurationSets(input *ses.ListConfigurationSetsInput) (*ses.ListConfigurationSetsOutput, error) { | ||
return &m.ListConfigurationSetsOutput, nil | ||
} | ||
|
||
func (m mockedSesConfigurationSet) DeleteConfigurationSet(*ses.DeleteConfigurationSetInput) (*ses.DeleteConfigurationSetOutput, error) { | ||
return &m.DeleteConfigurationSetOutput, nil | ||
} | ||
|
||
var ( | ||
id1 = "test-id-1" | ||
id2 = "test-id-2" | ||
configurationsSet1 = ses.ConfigurationSet{ | ||
Name: awsgo.String(id1), | ||
} | ||
configurationsSet2 = ses.ConfigurationSet{ | ||
Name: awsgo.String(id2), | ||
} | ||
) | ||
|
||
func TestSesConfigurationSet_GetAll(t *testing.T) { | ||
t.Parallel() | ||
|
||
identity := SesConfigurationSet{ | ||
Client: mockedSesConfigurationSet{ | ||
ListConfigurationSetsOutput: ses.ListConfigurationSetsOutput{ | ||
ConfigurationSets: []*ses.ConfigurationSet{ | ||
&configurationsSet1, | ||
&configurationsSet2, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
tests := map[string]struct { | ||
configObj config.ResourceType | ||
expected []string | ||
}{ | ||
"emptyFilter": { | ||
configObj: config.ResourceType{}, | ||
expected: []string{id1, id2}, | ||
}, | ||
"nameExclusionFilter": { | ||
configObj: config.ResourceType{ | ||
ExcludeRule: config.FilterRule{ | ||
NamesRegExp: []config.Expression{{ | ||
RE: *regexp.MustCompile(id2), | ||
}}}, | ||
}, | ||
expected: []string{id1}, | ||
}, | ||
} | ||
for name, tc := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
names, err := identity.getAll(context.Background(), config.Config{ | ||
SESConfigurationSet: tc.configObj, | ||
}) | ||
require.NoError(t, err) | ||
require.Equal(t, tc.expected, awsgo.StringValueSlice(names)) | ||
}) | ||
} | ||
} | ||
|
||
func TestSesConfigurationSet_NukeAll(t *testing.T) { | ||
t.Parallel() | ||
|
||
identity := SesConfigurationSet{ | ||
Client: mockedSesConfigurationSet{}, | ||
} | ||
|
||
err := identity.nukeAll([]*string{aws.String("test")}) | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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/ses" | ||
"github.com/aws/aws-sdk-go/service/ses/sesiface" | ||
"github.com/gruntwork-io/cloud-nuke/config" | ||
"github.com/gruntwork-io/go-commons/errors" | ||
) | ||
|
||
// SesConfigurationSet - represents all SES configuartion set | ||
type SesConfigurationSet struct { | ||
BaseAwsResource | ||
Client sesiface.SESAPI | ||
Region string | ||
Ids []string | ||
} | ||
|
||
func (scs *SesConfigurationSet) Init(session *session.Session) { | ||
scs.Client = ses.New(session) | ||
} | ||
|
||
// ResourceName - the simple name of the aws resource | ||
func (scs *SesConfigurationSet) ResourceName() string { | ||
return "ses-configuration-set" | ||
} | ||
|
||
// MaxBatchSize - Tentative batch size to ensure AWS doesn't throttle | ||
func (scs *SesConfigurationSet) MaxBatchSize() int { | ||
return maxBatchSize | ||
} | ||
|
||
// ResourceIdentifiers - The Ids of the configuration set | ||
func (scs *SesConfigurationSet) ResourceIdentifiers() []string { | ||
return scs.Ids | ||
} | ||
|
||
func (scs *SesConfigurationSet) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) { | ||
identifiers, err := scs.getAll(c, configObj) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
scs.Ids = awsgo.StringValueSlice(identifiers) | ||
return scs.Ids, nil | ||
} | ||
|
||
// Nuke - nuke 'em all!!! | ||
func (scs *SesConfigurationSet) Nuke(identifiers []string) error { | ||
if err := scs.nukeAll(awsgo.StringSlice(identifiers)); err != nil { | ||
return errors.WithStackTrace(err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.