Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wafregional rulegroup & properties for some resources #541

Merged
merged 2 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 79 additions & 0 deletions resources/wafregional-rulegroup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/waf"
"github.com/aws/aws-sdk-go/service/wafregional"
"github.com/rebuy-de/aws-nuke/pkg/types"
)

type WAFRegionalRuleGroup struct {
svc *wafregional.WAFRegional
ID *string
name *string
}

func init() {
register("WAFRegionalRuleGroup", ListWAFRegionalRuleGroups)
}

func ListWAFRegionalRuleGroups(sess *session.Session) ([]Resource, error) {
svc := wafregional.New(sess)
resources := []Resource{}

params := &waf.ListRuleGroupsInput{
Limit: aws.Int64(50),
}

for {
resp, err := svc.ListRuleGroups(params)
if err != nil {
return nil, err
}

for _, rule := range resp.RuleGroups {
resources = append(resources, &WAFRegionalRuleGroup{
svc: svc,
ID: rule.RuleGroupId,
name: rule.Name,
})
}

if resp.NextMarker == nil {
break
}

params.NextMarker = resp.NextMarker
}

return resources, nil
}

func (f *WAFRegionalRuleGroup) Remove() error {

tokenOutput, err := f.svc.GetChangeToken(&waf.GetChangeTokenInput{})
if err != nil {
return err
}

_, err = f.svc.DeleteRuleGroup(&waf.DeleteRuleGroupInput{
RuleGroupId: f.ID,
ChangeToken: tokenOutput.ChangeToken,
})

return err
}

func (f *WAFRegionalRuleGroup) String() string {
return *f.ID
}

func (f *WAFRegionalRuleGroup) Properties() types.Properties {
properties := types.NewProperties()

properties.
Set("ID", f.ID).
Set("Name", f.name)
return properties
}
20 changes: 16 additions & 4 deletions resources/wafregional-rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/waf"
"github.com/aws/aws-sdk-go/service/wafregional"
"github.com/rebuy-de/aws-nuke/pkg/types"
)

type WAFRegionalRule struct {
svc *wafregional.WAFRegional
ID *string
svc *wafregional.WAFRegional
ID *string
name *string
}

func init() {
Expand All @@ -32,8 +34,9 @@ func ListWAFRegionalRules(sess *session.Session) ([]Resource, error) {

for _, rule := range resp.Rules {
resources = append(resources, &WAFRegionalRule{
svc: svc,
ID: rule.RuleId,
svc: svc,
ID: rule.RuleId,
name: rule.Name,
})
}

Expand Down Expand Up @@ -65,3 +68,12 @@ func (f *WAFRegionalRule) Remove() error {
func (f *WAFRegionalRule) String() string {
return *f.ID
}

func (f *WAFRegionalRule) Properties() types.Properties {
properties := types.NewProperties()

properties.
Set("ID", f.ID).
Set("Name", f.name)
return properties
}
20 changes: 16 additions & 4 deletions resources/wafregional-webacls.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/waf"
"github.com/aws/aws-sdk-go/service/wafregional"
"github.com/rebuy-de/aws-nuke/pkg/types"
)

type WAFRegionalWebACL struct {
svc *wafregional.WAFRegional
ID *string
svc *wafregional.WAFRegional
ID *string
name *string
}

func init() {
Expand All @@ -32,8 +34,9 @@ func ListWAFRegionalWebACLs(sess *session.Session) ([]Resource, error) {

for _, webACL := range resp.WebACLs {
resources = append(resources, &WAFRegionalWebACL{
svc: svc,
ID: webACL.WebACLId,
svc: svc,
ID: webACL.WebACLId,
name: webACL.Name,
})
}

Expand Down Expand Up @@ -65,3 +68,12 @@ func (f *WAFRegionalWebACL) Remove() error {
func (f *WAFRegionalWebACL) String() string {
return *f.ID
}

func (f *WAFRegionalWebACL) Properties() types.Properties {
properties := types.NewProperties()

properties.
Set("ID", f.ID).
Set("Name", f.name)
return properties
}