Skip to content

Commit

Permalink
Add wafregional rulegroup & properties for some resources (#541)
Browse files Browse the repository at this point in the history
* Add WAF regional rulegroup resource

* Add properties to wafregional resources
  • Loading branch information
der-eismann committed Aug 28, 2020
1 parent af924af commit f8ff7c2
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 8 deletions.
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
}

0 comments on commit f8ff7c2

Please sign in to comment.