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

Added properties for several AWS resources #980

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 24 additions & 0 deletions resources/cloudwatchevents-rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatchevents"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

func init() {
Expand All @@ -30,10 +31,20 @@ func ListCloudWatchEventsRules(sess *session.Session) ([]Resource, error) {
}

for _, rule := range resp.Rules {

ruleTagsOutput, err := svc.ListTagsForResource(&cloudwatchevents.ListTagsForResourceInput{
ResourceARN: rule.Arn,
})

if err != nil {
return nil, err
}

resources = append(resources, &CloudWatchEventsRule{
svc: svc,
name: rule.Name,
busName: bus.Name,
tags: ruleTagsOutput.Tags,
})
}
}
Expand All @@ -44,6 +55,7 @@ type CloudWatchEventsRule struct {
svc *cloudwatchevents.CloudWatchEvents
name *string
busName *string
tags []*cloudwatchevents.Tag
}

func (rule *CloudWatchEventsRule) Remove() error {
Expand All @@ -55,6 +67,18 @@ func (rule *CloudWatchEventsRule) Remove() error {
return err
}

func (rule *CloudWatchEventsRule) Properties() types.Properties {
properties := types.NewProperties()

properties.Set("Name", rule.name)

for _, tagValue := range rule.tags {
properties.SetTag(tagValue.Key, tagValue.Value)
}

return properties
}

func (rule *CloudWatchEventsRule) String() string {
return fmt.Sprintf("Rule: %s", *rule.name)
}
15 changes: 15 additions & 0 deletions resources/cloudwatchevents-targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatchevents"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

func init() {
Expand Down Expand Up @@ -37,6 +38,10 @@ func ListCloudWatchEventsTargets(sess *session.Session) ([]Resource, error) {
return nil, err
}
for _, target := range targetResp.Targets {
if err != nil {
return nil, err
}

Comment on lines +41 to +44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err != nil {
return nil, err
}

I think this was a copy-paste error

resources = append(resources, &CloudWatchEventsTarget{
svc: svc,
ruleName: rule.Name,
Expand Down Expand Up @@ -68,6 +73,16 @@ func (target *CloudWatchEventsTarget) Remove() error {
return err
}

func (target *CloudWatchEventsTarget) Properties() types.Properties {
properties := types.NewProperties()

properties.Set("TargetId", target.targetId)
properties.Set("RuleName", target.ruleName)
properties.Set("BusName", target.busName)

return properties
}

func (target *CloudWatchEventsTarget) String() string {
return fmt.Sprintf("Rule: %s Target ID: %s", *target.ruleName, *target.targetId)
}
10 changes: 10 additions & 0 deletions resources/cognito-userpool-domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package resources
import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -66,6 +67,15 @@ func (f *CognitoUserPoolDomain) Remove() error {
return err
}

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

properties.Set("Domain", f.name)
properties.Set("UserPoolName", f.userPoolName)
properties.Set("UserPoolId", f.userPoolId)
return properties
}

func (f *CognitoUserPoolDomain) String() string {
return *f.userPoolName + " -> " + *f.name
}
22 changes: 22 additions & 0 deletions resources/cognito-userpools.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type CognitoUserPool struct {
svc *cognitoidentityprovider.CognitoIdentityProvider
name *string
id *string
tags map[string]*string
}

func init() {
Expand All @@ -31,10 +33,19 @@ func ListCognitoUserPools(sess *session.Session) ([]Resource, error) {
}

for _, pool := range output.UserPools {
poolOutput, err := svc.DescribeUserPool(&cognitoidentityprovider.DescribeUserPoolInput{
UserPoolId: pool.Id,
})

if err != nil {
return nil, err
}

resources = append(resources, &CognitoUserPool{
svc: svc,
name: pool.Name,
id: pool.Id,
tags: poolOutput.UserPool.UserPoolTags,
})
}

Expand All @@ -57,6 +68,17 @@ func (f *CognitoUserPool) Remove() error {
return err
}

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

properties.Set("Name", f.name)

for tagKey, tagValue := range f.tags {
properties.SetTag(&tagKey, tagValue)
}
return properties
}

func (f *CognitoUserPool) String() string {
return *f.name
}
6 changes: 6 additions & 0 deletions resources/iam-saml-provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package resources
import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type IAMSAMLProvider struct {
Expand Down Expand Up @@ -45,6 +46,11 @@ func (e *IAMSAMLProvider) Remove() error {
return nil
}

func (e *IAMSAMLProvider) Properties() types.Properties {
properties := types.NewProperties()
return properties
}

Comment on lines +49 to +53
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have one property at least

func (e *IAMSAMLProvider) String() string {
return e.arn
}
10 changes: 10 additions & 0 deletions resources/iam-user-policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type IAMUserPolicy struct {
Expand Down Expand Up @@ -59,6 +60,15 @@ func (e *IAMUserPolicy) Remove() error {
return nil
}

func (e *IAMUserPolicy) Properties() types.Properties {
properties := types.NewProperties()

properties.Set("UserName", e.userName)
properties.Set("PolicyName", e.policyName)

return properties
}

func (e *IAMUserPolicy) String() string {
return fmt.Sprintf("%s -> %s", e.userName, e.policyName)
}
32 changes: 28 additions & 4 deletions resources/sfn-statemachines.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sfn"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type SFNStateMachine struct {
svc *sfn.SFN
ARN *string
svc *sfn.SFN
ARN *string
name *string
tags []*sfn.Tag
}

func init() {
Expand All @@ -30,9 +33,19 @@ func ListSFNStateMachines(sess *session.Session) ([]Resource, error) {
}

for _, stateMachine := range output.StateMachines {
tagsOutput, err := svc.ListTagsForResource(&sfn.ListTagsForResourceInput{
ResourceArn: stateMachine.StateMachineArn,
})

if err != nil {
return nil, err
}

resources = append(resources, &SFNStateMachine{
svc: svc,
ARN: stateMachine.StateMachineArn,
svc: svc,
ARN: stateMachine.StateMachineArn,
name: stateMachine.Name,
tags: tagsOutput.Tags,
})
}

Expand Down Expand Up @@ -76,6 +89,17 @@ func (f *SFNStateMachine) Remove() error {
return err
}

func (s *SFNStateMachine) Properties() types.Properties {
properties := types.NewProperties()

properties.Set("Name", s.name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have the ARN as well


for _, tagValue := range s.tags {
properties.SetTag(tagValue.Key, tagValue.Value)
}
return properties
}

func (f *SFNStateMachine) String() string {
return *f.ARN
}
11 changes: 11 additions & 0 deletions resources/sns-subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sns"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

func init() {
Expand All @@ -24,6 +25,7 @@ func ListSNSSubscriptions(sess *session.Session) ([]Resource, error) {
}
for _, subscription := range resp.Subscriptions {
if *subscription.SubscriptionArn != "PendingConfirmation" {

resources = append(resources, &SNSSubscription{
svc: svc,
id: subscription.SubscriptionArn,
Expand Down Expand Up @@ -56,6 +58,15 @@ func (subs *SNSSubscription) Remove() error {
return err
}

func (subs *SNSSubscription) Properties() types.Properties {
properties := types.NewProperties()

properties.Set("Id", subs.id)
properties.Set("Name", subs.name)

return properties
}

func (subs *SNSSubscription) String() string {
return fmt.Sprintf("Owner: %s ARN: %s", *subs.name, *subs.id)
}
15 changes: 15 additions & 0 deletions resources/ssm-documents.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ssm"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type SSMDocument struct {
svc *ssm.SSM
name *string
tags []*ssm.Tag
}

func init() {
Expand Down Expand Up @@ -41,6 +43,7 @@ func ListSSMDocuments(sess *session.Session) ([]Resource, error) {
resources = append(resources, &SSMDocument{
svc: svc,
name: documentIdentifier.Name,
tags: documentIdentifier.Tags,
})
}

Expand All @@ -63,6 +66,18 @@ func (f *SSMDocument) Remove() error {
return err
}

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

properties.Set("Name", f.name)

for _, tagValue := range f.tags {
properties.SetTag(tagValue.Key, tagValue.Value)
}

return properties
}

func (f *SSMDocument) String() string {
return *f.name
}
Loading