Skip to content

Commit

Permalink
fix: active ruleset wont able to nuke (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
james03160927 authored Jun 24, 2024
1 parent 11d905b commit 9750364
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions aws/resources/ses_email_receiving.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"slices"

"github.com/aws/aws-sdk-go/aws"
awsgo "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"
Expand All @@ -30,13 +31,25 @@ func (s *SesReceiptRule) getAll(c context.Context, configObj config.Config) ([]*
return nil, nil
}

// https://docs.aws.amazon.com/cli/latest/reference/ses/delete-receipt-rule-set.html
// Important : The currently active rule set cannot be deleted.
activeRule, err := s.Client.DescribeActiveReceiptRuleSetWithContext(s.Context, &ses.DescribeActiveReceiptRuleSetInput{})
if err != nil {
return nil, errors.WithStackTrace(err)
}

result, err := s.Client.ListReceiptRuleSetsWithContext(s.Context, &ses.ListReceiptRuleSetsInput{})
if err != nil {
return nil, errors.WithStackTrace(err)
}

var rulesets []*string
for _, sets := range result.RuleSets {
// checking the rule set is the active one
if activeRule != nil && activeRule.Metadata != nil && awsgo.StringValue(activeRule.Metadata.Name) == awsgo.StringValue(sets.Name) {
logging.Debugf("The Ruleset %s is active and you wont able to delete it", awsgo.StringValue(sets.Name))
continue
}
if configObj.SESReceiptRuleSet.ShouldInclude(config.ResourceValue{
Name: sets.Name,
Time: sets.CreatedTimestamp,
Expand Down
5 changes: 5 additions & 0 deletions aws/resources/ses_email_receiving_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type mockedSesReceiptRule struct {
sesiface.SESAPI
DeleteReceiptRuleSetOutput ses.DeleteReceiptRuleSetOutput
ListReceiptRuleSetsOutput ses.ListReceiptRuleSetsOutput
DescribeActiveReceiptRuleSetOutput ses.DescribeActiveReceiptRuleSetOutput
}

func (m mockedSesReceiptRule) ListReceiptRuleSetsWithContext(_ awsgo.Context, _ *ses.ListReceiptRuleSetsInput, _ ...request.Option) (*ses.ListReceiptRuleSetsOutput, error) {
Expand All @@ -29,6 +30,10 @@ func (m mockedSesReceiptRule) DeleteReceiptRuleSetWithContext(_ awsgo.Context, _
return &m.DeleteReceiptRuleSetOutput, nil
}

func (m mockedSesReceiptRule) DescribeActiveReceiptRuleSetWithContext(_ awsgo.Context, _ *ses.DescribeActiveReceiptRuleSetInput, _ ...request.Option) (*ses.DescribeActiveReceiptRuleSetOutput, error) {
return &m.DescribeActiveReceiptRuleSetOutput, nil
}

func TestSesReceiptRule_GetAll(t *testing.T) {

id1 := "test-id-1"
Expand Down

0 comments on commit 9750364

Please sign in to comment.