Skip to content

Commit 3d90281

Browse files
committed
Merge branch 'jan2025-improvements' of github.com:ekristen/aws-nuke into jan2025-improvements
* 'jan2025-improvements' of github.com:ekristen/aws-nuke: docs(resources): auto-generated test(cloudwatchlogs-loggroup): add property test coverage feat(cloudwatchlogs-loggroup): new properties, refactor properties struct refactor(cloudwatchlogs-loggroup): standardization fix(cloudwatchlogs-loggroup): property RetentionInDays should always have a value feat(cloudwatchlogs-loggroup): add RetentionInDays properties fix(deps): update module github.com/aws/aws-sdk-go-v2/service/s3 to v1.72.0
2 parents 38bfa1c + e6f963d commit 3d90281

File tree

5 files changed

+79
-32
lines changed

5 files changed

+79
-32
lines changed

docs/resources/cloud-watch-logs-log-group.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@ generated: true
1111
CloudWatchLogsLogGroup
1212
```
1313

14+
## Properties
1415

1516

17+
- `CreatedTime`: The creation time of the log group in unix timestamp format
18+
- `CreationTime`: The creation time of the log group in RFC3339 format
19+
- `LastEvent`: The last event time of the log group in RFC3339 format
20+
- `Name`: The name of the log group
21+
- `RetentionInDays`: The number of days to retain log events in the log group
22+
- `tag:<key>:`: This resource has tags with property `Tags`. These are key/value pairs that are
23+
added as their own property with the prefix of `tag:` (e.g. [tag:example: "value"])
24+
1625
!!! note - Using Properties
1726
Properties are what [Filters](../config-filtering.md) are written against in your configuration. You use the property
1827
names to write filters for what you want to **keep** and omit from the nuke process.

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ require (
77
github.com/aws/aws-sdk-go-v2 v1.32.7
88
github.com/aws/aws-sdk-go-v2/config v1.28.7
99
github.com/aws/aws-sdk-go-v2/credentials v1.17.48
10-
github.com/aws/aws-sdk-go-v2/service/s3 v1.71.1
10+
github.com/aws/aws-sdk-go-v2/service/s3 v1.72.0
11+
github.com/aws/aws-sdk-go-v2/service/ssmquicksetup v1.3.2
1112
github.com/aws/aws-sdk-go-v2/service/sts v1.33.3
1213
github.com/aws/smithy-go v1.22.1
1314
github.com/ekristen/libnuke v0.24.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.7 h1:8eUsivBQz
2828
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.7/go.mod h1:kLPQvGUmxn/fqiCrDeohwG33bq2pQpGeY62yRO6Nrh0=
2929
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.7 h1:Hi0KGbrnr57bEHWM0bJ1QcBzxLrL/k2DHvGYhb8+W1w=
3030
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.7/go.mod h1:wKNgWgExdjjrm4qvfbTorkvocEstaoDl4WCvGfeCy9c=
31-
github.com/aws/aws-sdk-go-v2/service/s3 v1.71.1 h1:aOVVZJgWbaH+EJYPvEgkNhCEbXXvH7+oML36oaPK3zE=
32-
github.com/aws/aws-sdk-go-v2/service/s3 v1.71.1/go.mod h1:r+xl5yzMk9083rMR+sJ5TYj9Tihvf/l1oxzZXDgGj2Q=
3331
github.com/aws/aws-sdk-go-v2/service/s3control v1.52.1 h1:xxGbXbGtO/VMz2JqB1UwEDlSchryUss0KmQJSZ0oTUE=
3432
github.com/aws/aws-sdk-go-v2/service/s3control v1.52.1/go.mod h1:6BuUa52of67a+ri/poTH82XiL+rTGQWUPZCmf2cfVHI=
33+
github.com/aws/aws-sdk-go-v2/service/s3 v1.72.0 h1:SAfh4pNx5LuTafKKWR02Y+hL3A+3TX8cTKG1OIAJaBk=
34+
github.com/aws/aws-sdk-go-v2/service/s3 v1.72.0/go.mod h1:r+xl5yzMk9083rMR+sJ5TYj9Tihvf/l1oxzZXDgGj2Q=
3535
github.com/aws/aws-sdk-go-v2/service/ssmquicksetup v1.3.2 h1:4siT1z3nEVxJq1jZYu1SRoct5xgbKen+ammCuZBZ2zI=
3636
github.com/aws/aws-sdk-go-v2/service/ssmquicksetup v1.3.2/go.mod h1:KSO1+erW2SUB6Mw/Qamu1fOT5fn/mzd9G79ENbYqyRQ=
3737
github.com/aws/aws-sdk-go-v2/service/sso v1.24.8 h1:CvuUmnXI7ebaUAhbJcDy9YQx8wHR69eZ9I7q5hszt/g=

resources/cloudwatchlogs-loggroups.go renamed to resources/cloudwatchlogs-loggroup.go

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"strings"
66
"time"
77

8+
"github.com/gotidy/ptr"
89
"go.uber.org/ratelimit"
910

10-
"github.com/aws/aws-sdk-go/aws"
1111
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
1212

1313
"github.com/ekristen/libnuke/pkg/registry"
@@ -46,7 +46,7 @@ func (l *CloudWatchLogsLogGroupLister) List(_ context.Context, o interface{}) ([
4646
streamRl := ratelimit.New(15)
4747

4848
params := &cloudwatchlogs.DescribeLogGroupsInput{
49-
Limit: aws.Int64(50),
49+
Limit: ptr.Int64(50),
5050
}
5151

5252
for {
@@ -72,9 +72,9 @@ func (l *CloudWatchLogsLogGroupLister) List(_ context.Context, o interface{}) ([
7272
// get last event ingestion time
7373
lsResp, err := svc.DescribeLogStreams(&cloudwatchlogs.DescribeLogStreamsInput{
7474
LogGroupName: logGroup.LogGroupName,
75-
OrderBy: aws.String("LastEventTime"),
76-
Limit: aws.Int64(1),
77-
Descending: aws.Bool(true),
75+
OrderBy: ptr.String("LastEventTime"),
76+
Limit: ptr.Int64(1),
77+
Descending: ptr.Bool(true),
7878
})
7979
if err != nil {
8080
return nil, err
@@ -87,14 +87,21 @@ func (l *CloudWatchLogsLogGroupLister) List(_ context.Context, o interface{}) ([
8787
lastEvent = time.Unix(*logGroup.CreationTime/1000, 0)
8888
}
8989

90+
var retentionInDays int64
91+
if logGroup.RetentionInDays != nil {
92+
retentionInDays = ptr.ToInt64(logGroup.RetentionInDays)
93+
}
94+
9095
resources = append(resources, &CloudWatchLogsLogGroup{
91-
svc: svc,
92-
logGroup: logGroup,
93-
lastEvent: lastEvent.Format(time.RFC3339),
94-
tags: tagResp.Tags,
96+
svc: svc,
97+
Name: logGroup.LogGroupName,
98+
CreatedTime: logGroup.CreationTime,
99+
CreationTime: ptr.Time(time.Unix(*logGroup.CreationTime/1000, 0).UTC()),
100+
LastEvent: ptr.Time(lastEvent), // TODO(v4): convert to UTC
101+
RetentionInDays: retentionInDays,
102+
Tags: tagResp.Tags,
95103
})
96104
}
97-
98105
if output.NextToken == nil {
99106
break
100107
}
@@ -106,32 +113,28 @@ func (l *CloudWatchLogsLogGroupLister) List(_ context.Context, o interface{}) ([
106113
}
107114

108115
type CloudWatchLogsLogGroup struct {
109-
svc *cloudwatchlogs.CloudWatchLogs
110-
logGroup *cloudwatchlogs.LogGroup
111-
lastEvent string
112-
tags map[string]*string
116+
svc *cloudwatchlogs.CloudWatchLogs
117+
Name *string `description:"The name of the log group"`
118+
CreatedTime *int64 `description:"The creation time of the log group in unix timestamp format"`
119+
CreationTime *time.Time `description:"The creation time of the log group in RFC3339 format"`
120+
LastEvent *time.Time `description:"The last event time of the log group in RFC3339 format"`
121+
RetentionInDays int64 `description:"The number of days to retain log events in the log group"`
122+
Tags map[string]*string
113123
}
114124

115-
func (f *CloudWatchLogsLogGroup) Remove(_ context.Context) error {
116-
_, err := f.svc.DeleteLogGroup(&cloudwatchlogs.DeleteLogGroupInput{
117-
LogGroupName: f.logGroup.LogGroupName,
125+
func (r *CloudWatchLogsLogGroup) Remove(_ context.Context) error {
126+
_, err := r.svc.DeleteLogGroup(&cloudwatchlogs.DeleteLogGroupInput{
127+
LogGroupName: r.Name,
118128
})
119129

120130
return err
121131
}
122132

123-
func (f *CloudWatchLogsLogGroup) String() string {
124-
return *f.logGroup.LogGroupName
133+
func (r *CloudWatchLogsLogGroup) String() string {
134+
return *r.Name
125135
}
126136

127-
func (f *CloudWatchLogsLogGroup) Properties() types.Properties {
128-
properties := types.NewProperties().
129-
Set("logGroupName", f.logGroup.LogGroupName).
130-
Set("CreatedTime", f.logGroup.CreationTime).
131-
Set("LastEvent", f.lastEvent)
132-
133-
for k, v := range f.tags {
134-
properties.SetTag(&k, v)
135-
}
136-
return properties
137+
func (r *CloudWatchLogsLogGroup) Properties() types.Properties {
138+
return types.NewPropertiesFromStruct(r).
139+
Set("logGroupName", r.Name) // TODO(v4): remove this property
137140
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package resources
2+
3+
import (
4+
"strconv"
5+
"testing"
6+
"time"
7+
8+
"github.com/gotidy/ptr"
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestCloudWatchLogsLogGroupProperties(t *testing.T) {
13+
now := time.Now().UTC()
14+
15+
r := &CloudWatchLogsLogGroup{
16+
Name: ptr.String("test-log-group"),
17+
CreatedTime: ptr.Int64(now.Unix()),
18+
CreationTime: ptr.Time(now),
19+
LastEvent: ptr.Time(now),
20+
RetentionInDays: 7,
21+
Tags: map[string]*string{
22+
"Environment": ptr.String("production"),
23+
},
24+
}
25+
26+
properties := r.Properties()
27+
assert.Equal(t, properties.Get("logGroupName"), "test-log-group")
28+
assert.Equal(t, properties.Get("Name"), "test-log-group")
29+
assert.Equal(t, properties.Get("CreatedTime"), strconv.Itoa(int(now.Unix())))
30+
assert.Equal(t, properties.Get("CreationTime"), now.Format(time.RFC3339))
31+
assert.Equal(t, properties.Get("LastEvent"), now.Format(time.RFC3339))
32+
assert.Equal(t, properties.Get("RetentionInDays"), "7")
33+
assert.Equal(t, properties.Get("tag:Environment"), "production")
34+
}

0 commit comments

Comments
 (0)