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

add firewall manager resources #491

Merged
merged 4 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}