Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
add firewall manager resources
Browse files Browse the repository at this point in the history
  • Loading branch information
tylersouthwick committed Mar 25, 2020
1 parent 4b199d2 commit 2d5a508
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
47 changes: 47 additions & 0 deletions resources/fms_notification_channels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/fms"
)

type FMSNotificationChannel struct {
svc *fms.FMS
}

func init() {
register("FMSNotificationChannel", ListFMSNotificationChannel)
}

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

if _, err := svc.GetNotificationChannel(&fms.GetNotificationChannelInput{}); err != nil {
if aerr, ok := err.(awserr.Error); ok {
if aerr.Code() != fms.ErrCodeResourceNotFoundException {
return nil, err
}
} else {
return nil, err
}
} else {
resources = append(resources, &FMSNotificationChannel{
svc: svc,
})
}

return resources, nil
}

func (f *FMSNotificationChannel) Remove() error {

_, err := f.svc.DeleteNotificationChannel(&fms.DeleteNotificationChannelInput{})

return err
}

func (f *FMSNotificationChannel) String() string {
return "fms-notification-channel"
}
61 changes: 61 additions & 0 deletions resources/fms_policies.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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/fms"
)

type FMSPolicy struct {
svc *fms.FMS
policyId *string
}

func init() {
register("FMSPolicy", ListFMSPolicies)
}

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

params := &fms.ListPoliciesInput{
MaxResults: aws.Int64(50),
}

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

for _, policy := range resp.PolicyList {
resources = append(resources, &FMSPolicy{
svc: svc,
policyId: policy.PolicyId,
})
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

func (f *FMSPolicy) Remove() error {

_, err := f.svc.DeletePolicy(&fms.DeletePolicyInput{
PolicyId: f.policyId,
DeleteAllPolicyResources: aws.Bool(false),
})

return err
}

func (f *FMSPolicy) String() string {
return *f.policyId
}

0 comments on commit 2d5a508

Please sign in to comment.