5
5
"strings"
6
6
"time"
7
7
8
+ "github.com/gotidy/ptr"
8
9
"go.uber.org/ratelimit"
9
10
10
- "github.com/aws/aws-sdk-go/aws"
11
11
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
12
12
13
13
"github.com/ekristen/libnuke/pkg/registry"
@@ -46,7 +46,7 @@ func (l *CloudWatchLogsLogGroupLister) List(_ context.Context, o interface{}) ([
46
46
streamRl := ratelimit .New (15 )
47
47
48
48
params := & cloudwatchlogs.DescribeLogGroupsInput {
49
- Limit : aws .Int64 (50 ),
49
+ Limit : ptr .Int64 (50 ),
50
50
}
51
51
52
52
for {
@@ -72,9 +72,9 @@ func (l *CloudWatchLogsLogGroupLister) List(_ context.Context, o interface{}) ([
72
72
// get last event ingestion time
73
73
lsResp , err := svc .DescribeLogStreams (& cloudwatchlogs.DescribeLogStreamsInput {
74
74
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 ),
78
78
})
79
79
if err != nil {
80
80
return nil , err
@@ -87,14 +87,21 @@ func (l *CloudWatchLogsLogGroupLister) List(_ context.Context, o interface{}) ([
87
87
lastEvent = time .Unix (* logGroup .CreationTime / 1000 , 0 )
88
88
}
89
89
90
+ var retentionInDays int64
91
+ if logGroup .RetentionInDays != nil {
92
+ retentionInDays = ptr .ToInt64 (logGroup .RetentionInDays )
93
+ }
94
+
90
95
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 ,
95
103
})
96
104
}
97
-
98
105
if output .NextToken == nil {
99
106
break
100
107
}
@@ -106,32 +113,28 @@ func (l *CloudWatchLogsLogGroupLister) List(_ context.Context, o interface{}) ([
106
113
}
107
114
108
115
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
113
123
}
114
124
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 ,
118
128
})
119
129
120
130
return err
121
131
}
122
132
123
- func (f * CloudWatchLogsLogGroup ) String () string {
124
- return * f . logGroup . LogGroupName
133
+ func (r * CloudWatchLogsLogGroup ) String () string {
134
+ return * r . Name
125
135
}
126
136
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
137
140
}
0 commit comments