Skip to content

Commit 4b31fa6

Browse files
committed
refactor(cloudwatchevent-target): properties from struct
1 parent 424fc85 commit 4b31fa6

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

resources/cloudwatchevents-target.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/aws/aws-sdk-go/aws"
7+
"github.com/gotidy/ptr"
8+
89
"github.com/aws/aws-sdk-go/service/cloudwatchevents"
910

1011
"github.com/ekristen/libnuke/pkg/registry"
@@ -56,9 +57,9 @@ func (l *CloudWatchEventsTargetLister) List(_ context.Context, o interface{}) ([
5657
for _, target := range targetResp.Targets {
5758
resources = append(resources, &CloudWatchEventsTarget{
5859
svc: svc,
59-
ruleName: rule.Name,
60-
targetID: target.Id,
61-
busName: bus.Name,
60+
Name: rule.Name,
61+
TargetID: target.Id,
62+
BusName: bus.Name,
6263
})
6364
}
6465
}
@@ -69,30 +70,27 @@ func (l *CloudWatchEventsTargetLister) List(_ context.Context, o interface{}) ([
6970

7071
type CloudWatchEventsTarget struct {
7172
svc *cloudwatchevents.CloudWatchEvents
72-
targetID *string
73-
ruleName *string
74-
busName *string
73+
TargetID *string
74+
Name *string
75+
BusName *string
7576
}
7677

7778
func (r *CloudWatchEventsTarget) Remove(_ context.Context) error {
78-
ids := []*string{r.targetID}
79+
ids := []*string{r.TargetID}
7980
_, err := r.svc.RemoveTargets(&cloudwatchevents.RemoveTargetsInput{
8081
Ids: ids,
81-
Rule: r.ruleName,
82-
EventBusName: r.busName,
83-
Force: aws.Bool(true),
82+
Rule: r.Name,
83+
EventBusName: r.BusName,
84+
Force: ptr.Bool(true),
8485
})
8586
return err
8687
}
8788

8889
func (r *CloudWatchEventsTarget) String() string {
8990
// TODO: change this to IAM format rule -> target and mark as breaking change for filters
90-
return fmt.Sprintf("Rule: %s Target ID: %s", *r.ruleName, *r.targetID)
91+
return fmt.Sprintf("Rule: %s Target ID: %s", *r.Name, *r.TargetID)
9192
}
9293

9394
func (r *CloudWatchEventsTarget) Properties() types.Properties {
94-
return types.NewProperties().
95-
Set("Name", r.ruleName).
96-
Set("TargetID", r.targetID).
97-
Set("BusName", r.busName)
95+
return types.NewPropertiesFromStruct(r)
9896
}

0 commit comments

Comments
 (0)