Skip to content

Commit d8ffbc5

Browse files
committed
feat(cloudwatchlogs-loggroup): new properties, refactor properties struct
1 parent 19ebeb3 commit d8ffbc5

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

resources/cloudwatchlogs-loggroup.go

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ package resources
22

33
import (
44
"context"
5-
"github.com/gotidy/ptr"
65
"strings"
76
"time"
87

8+
"github.com/gotidy/ptr"
99
"go.uber.org/ratelimit"
1010

11-
"github.com/aws/aws-sdk-go/aws"
1211
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
1312

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

4948
params := &cloudwatchlogs.DescribeLogGroupsInput{
50-
Limit: aws.Int64(50),
49+
Limit: ptr.Int64(50),
5150
}
5251

5352
for {
@@ -73,9 +72,9 @@ func (l *CloudWatchLogsLogGroupLister) List(_ context.Context, o interface{}) ([
7372
// get last event ingestion time
7473
lsResp, err := svc.DescribeLogStreams(&cloudwatchlogs.DescribeLogStreamsInput{
7574
LogGroupName: logGroup.LogGroupName,
76-
OrderBy: aws.String("LastEventTime"),
77-
Limit: aws.Int64(1),
78-
Descending: aws.Bool(true),
75+
OrderBy: ptr.String("LastEventTime"),
76+
Limit: ptr.Int64(1),
77+
Descending: ptr.Bool(true),
7978
})
8079
if err != nil {
8180
return nil, err
@@ -95,10 +94,12 @@ func (l *CloudWatchLogsLogGroupLister) List(_ context.Context, o interface{}) ([
9594

9695
resources = append(resources, &CloudWatchLogsLogGroup{
9796
svc: svc,
98-
logGroup: logGroup,
99-
lastEvent: lastEvent.Format(time.RFC3339),
100-
retentionInDays: retentionInDays,
101-
tags: tagResp.Tags,
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,
102103
})
103104
}
104105
if output.NextToken == nil {
@@ -113,33 +114,27 @@ func (l *CloudWatchLogsLogGroupLister) List(_ context.Context, o interface{}) ([
113114

114115
type CloudWatchLogsLogGroup struct {
115116
svc *cloudwatchlogs.CloudWatchLogs
116-
logGroup *cloudwatchlogs.LogGroup
117-
lastEvent string
118-
retentionInDays int64
119-
tags map[string]*string
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
120123
}
121124

122125
func (r *CloudWatchLogsLogGroup) Remove(_ context.Context) error {
123126
_, err := r.svc.DeleteLogGroup(&cloudwatchlogs.DeleteLogGroupInput{
124-
LogGroupName: r.logGroup.LogGroupName,
127+
LogGroupName: r.Name,
125128
})
126129

127130
return err
128131
}
129132

130133
func (r *CloudWatchLogsLogGroup) String() string {
131-
return *r.logGroup.LogGroupName
134+
return *r.Name
132135
}
133136

134137
func (r *CloudWatchLogsLogGroup) Properties() types.Properties {
135-
properties := types.NewProperties().
136-
Set("logGroupName", r.logGroup.LogGroupName).
137-
Set("CreatedTime", r.logGroup.CreationTime).
138-
Set("LastEvent", r.lastEvent).
139-
Set("RetentionInDays", r.retentionInDays)
140-
141-
for k, v := range r.tags {
142-
properties.SetTag(&k, v)
143-
}
144-
return properties
138+
return types.NewPropertiesFromStruct(r).
139+
Set("logGroupName", r.Name) // TODO(v4): remove this property
145140
}

0 commit comments

Comments
 (0)