Skip to content

Commit

Permalink
feat(tags): add tags property to more resources
Browse files Browse the repository at this point in the history
  • Loading branch information
apgrucza committed Feb 8, 2025
1 parent aafc87d commit 8f12ba7
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 6 deletions.
13 changes: 13 additions & 0 deletions resources/applicationautoscaling-scalable-targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,22 @@ func (l *ApplicationAutoScalingScalableTargetLister) List(_ context.Context, o i
}

for _, out := range resp.ScalableTargets {
tags, err := svc.ListTagsForResource(
&applicationautoscaling.ListTagsForResourceInput{
ResourceARN: out.ScalableTargetARN,
})
if err != nil {
return nil, err
}

resources = append(resources, &AppAutoScaling{
svc: svc,
target: out,
id: *out.ResourceId,
roleARN: *out.RoleARN,
dimension: *out.ScalableDimension,
namespace: *out.ServiceNamespace,
tags: tags.Tags,
})
}

Expand All @@ -79,6 +88,7 @@ type AppAutoScaling struct {
roleARN string
dimension string
namespace string
tags map[string]*string
}

func (a *AppAutoScaling) Remove(_ context.Context) error {
Expand All @@ -97,6 +107,9 @@ func (a *AppAutoScaling) Remove(_ context.Context) error {

func (a *AppAutoScaling) Properties() types.Properties {
properties := types.NewProperties()
for key, tag := range a.tags {
properties.SetTag(&key, tag)
}
properties.Set("ResourceID", a.id)
properties.Set("ScalableDimension", a.dimension)
properties.Set("ServiceNamespace", a.namespace)
Expand Down
18 changes: 16 additions & 2 deletions resources/cloudtrail-trails.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,18 @@ func (l *CloudTrailTrailLister) List(_ context.Context, o interface{}) ([]resour

resources := make([]resource.Resource, 0)
for _, trail := range resp.TrailList {
tags, err := svc.ListTags(
&cloudtrail.ListTagsInput{
ResourceIdList: []*string{trail.TrailARN},
})
if err != nil {
return nil, err
}

resources = append(resources, &CloudTrailTrail{
svc: svc,
name: trail.Name,
tags: tags.ResourceTagList[0].TagsList,
})
}

Expand All @@ -49,6 +58,7 @@ func (l *CloudTrailTrailLister) List(_ context.Context, o interface{}) ([]resour
type CloudTrailTrail struct {
svc *cloudtrail.CloudTrail
name *string
tags []*cloudtrail.Tag
}

func (trail *CloudTrailTrail) Remove(_ context.Context) error {
Expand All @@ -59,8 +69,12 @@ func (trail *CloudTrailTrail) Remove(_ context.Context) error {
}

func (trail *CloudTrailTrail) Properties() types.Properties {
return types.NewProperties().
Set("Name", trail.name)
properties := types.NewProperties()
for _, tagValue := range trail.tags {
properties.SetTag(tagValue.Key, tagValue.Value)
}
properties.Set("Name", trail.name)
return properties
}

func (trail *CloudTrailTrail) String() string {
Expand Down
20 changes: 20 additions & 0 deletions resources/firehose-deliverystreams.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/v3/pkg/nuke"
)
Expand Down Expand Up @@ -45,9 +46,18 @@ func (l *FirehoseDeliveryStreamLister) List(_ context.Context, o interface{}) ([
}

for _, deliveryStreamName := range output.DeliveryStreamNames {
tags, err := svc.ListTagsForDeliveryStream(
&firehose.ListTagsForDeliveryStreamInput{
DeliveryStreamName: deliveryStreamName,
})
if err != nil {
return nil, err
}

resources = append(resources, &FirehoseDeliveryStream{
svc: svc,
deliveryStreamName: deliveryStreamName,
tags: tags.Tags,
})
lastDeliveryStreamName = deliveryStreamName
}
Expand All @@ -65,6 +75,7 @@ func (l *FirehoseDeliveryStreamLister) List(_ context.Context, o interface{}) ([
type FirehoseDeliveryStream struct {
svc *firehose.Firehose
deliveryStreamName *string
tags []*firehose.Tag
}

func (f *FirehoseDeliveryStream) Remove(_ context.Context) error {
Expand All @@ -75,6 +86,15 @@ func (f *FirehoseDeliveryStream) Remove(_ context.Context) error {
return err
}

func (f *FirehoseDeliveryStream) Properties() types.Properties {
properties := types.NewProperties()
for _, tagValue := range f.tags {
properties.SetTag(tagValue.Key, tagValue.Value)
}
properties.Set("Name", f.deliveryStreamName)
return properties
}

func (f *FirehoseDeliveryStream) String() string {
return *f.deliveryStreamName
}
10 changes: 10 additions & 0 deletions resources/resource-explorer2-index.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,19 @@ func (l *ResourceExplorer2IndexLister) List(_ context.Context, o interface{}) ([
}

for _, index := range output.Indexes {
tags, err := svc.ListTagsForResource(
&resourceexplorer2.ListTagsForResourceInput{
ResourceArn: index.Arn,
})
if err != nil {
return nil, err
}

resources = append(resources, &ResourceExplorer2Index{
svc: svc,
ARN: index.Arn,
Type: index.Type,
Tags: tags.Tags,
})
}

Expand All @@ -64,6 +73,7 @@ type ResourceExplorer2Index struct {
svc *resourceexplorer2.ResourceExplorer2
ARN *string
Type *string
Tags map[string]*string
}

func (r *ResourceExplorer2Index) Remove(_ context.Context) error {
Expand Down
18 changes: 14 additions & 4 deletions resources/resource-explorer2-view.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,18 @@ func (l *ResourceExplorer2ViewLister) List(_ context.Context, o interface{}) ([]
}

for _, view := range output.Views {
tags, err := svc.ListTagsForResource(
&resourceexplorer2.ListTagsForResourceInput{
ResourceArn: view,
})
if err != nil {
return nil, err
}

resources = append(resources, &ResourceExplorer2View{
svc: svc,
ARN: view,
svc: svc,
ARN: view,
Tags: tags.Tags,
})
}

Expand All @@ -57,8 +66,9 @@ func (l *ResourceExplorer2ViewLister) List(_ context.Context, o interface{}) ([]
}

type ResourceExplorer2View struct {
svc *resourceexplorer2.ResourceExplorer2
ARN *string `description:"The ARN of the Resource Explorer View"`
svc *resourceexplorer2.ResourceExplorer2
ARN *string `description:"The ARN of the Resource Explorer View"`
Tags map[string]*string
}

func (r *ResourceExplorer2View) Remove(_ context.Context) error {
Expand Down
12 changes: 12 additions & 0 deletions resources/ssm-documents.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/v3/pkg/nuke"
)
Expand Down Expand Up @@ -53,6 +54,7 @@ func (l *SSMDocumentLister) List(_ context.Context, o interface{}) ([]resource.R
resources = append(resources, &SSMDocument{
svc: svc,
name: documentIdentifier.Name,
tags: documentIdentifier.Tags,
})
}

Expand All @@ -69,6 +71,7 @@ func (l *SSMDocumentLister) List(_ context.Context, o interface{}) ([]resource.R
type SSMDocument struct {
svc *ssm.SSM
name *string
tags []*ssm.Tag
}

func (f *SSMDocument) Remove(_ context.Context) error {
Expand All @@ -79,6 +82,15 @@ func (f *SSMDocument) Remove(_ context.Context) error {
return err
}

func (f *SSMDocument) Properties() types.Properties {
properties := types.NewProperties()
for _, tagValue := range f.tags {
properties.SetTag(tagValue.Key, tagValue.Value)
}
properties.Set("Name", f.name)
return properties
}

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

0 comments on commit 8f12ba7

Please sign in to comment.