@@ -2,13 +2,12 @@ package resources
2
2
3
3
import (
4
4
"context"
5
- "github.com/gotidy/ptr"
6
5
"strings"
7
6
"time"
8
7
8
+ "github.com/gotidy/ptr"
9
9
"go.uber.org/ratelimit"
10
10
11
- "github.com/aws/aws-sdk-go/aws"
12
11
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
13
12
14
13
"github.com/ekristen/libnuke/pkg/registry"
@@ -47,7 +46,7 @@ func (l *CloudWatchLogsLogGroupLister) List(_ context.Context, o interface{}) ([
47
46
streamRl := ratelimit .New (15 )
48
47
49
48
params := & cloudwatchlogs.DescribeLogGroupsInput {
50
- Limit : aws .Int64 (50 ),
49
+ Limit : ptr .Int64 (50 ),
51
50
}
52
51
53
52
for {
@@ -73,9 +72,9 @@ func (l *CloudWatchLogsLogGroupLister) List(_ context.Context, o interface{}) ([
73
72
// get last event ingestion time
74
73
lsResp , err := svc .DescribeLogStreams (& cloudwatchlogs.DescribeLogStreamsInput {
75
74
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 ),
79
78
})
80
79
if err != nil {
81
80
return nil , err
@@ -95,10 +94,12 @@ func (l *CloudWatchLogsLogGroupLister) List(_ context.Context, o interface{}) ([
95
94
96
95
resources = append (resources , & CloudWatchLogsLogGroup {
97
96
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 ,
102
103
})
103
104
}
104
105
if output .NextToken == nil {
@@ -113,33 +114,27 @@ func (l *CloudWatchLogsLogGroupLister) List(_ context.Context, o interface{}) ([
113
114
114
115
type CloudWatchLogsLogGroup struct {
115
116
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
120
123
}
121
124
122
125
func (r * CloudWatchLogsLogGroup ) Remove (_ context.Context ) error {
123
126
_ , err := r .svc .DeleteLogGroup (& cloudwatchlogs.DeleteLogGroupInput {
124
- LogGroupName : r .logGroup . LogGroupName ,
127
+ LogGroupName : r .Name ,
125
128
})
126
129
127
130
return err
128
131
}
129
132
130
133
func (r * CloudWatchLogsLogGroup ) String () string {
131
- return * r .logGroup . LogGroupName
134
+ return * r .Name
132
135
}
133
136
134
137
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
145
140
}
0 commit comments