Skip to content

Commit ac386b8

Browse files
Add dates to IAM users, access keys & Elasticache Replication Groups (#1093)
* Add `CreateDate` property to IAM users Add the ability to easily filter for old or expired IAM users by adding the `CreateDate` property to them. This allows the possibility of nuking users that are "old" while leaving recently-created ones intact. * Add `CreateDate` property to IAM user access keys Add the ability to easily filter for old or expired IAM user access keys by adding the `CreateDate` property to them. This allows us to nuke user access keys that are old or expired while leaving recent ones intact. * Add `CreationTime` to elasticache replication groups Add the ability to easily filter for old or expired elasticache replication groups by adding the `CreationTime` property to them. This allows `aws-nuke` to easily clear out all "old" resources while leaving recent ones intact. * Fix ECRG change to stop using whole object --------- Co-authored-by: Remi Broemeling <[email protected]>
1 parent bffd366 commit ac386b8

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

resources/elasticache-replicationgroups.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package resources
22

33
import (
4+
"time"
5+
46
"github.com/aws/aws-sdk-go/aws"
57
"github.com/aws/aws-sdk-go/aws/session"
68
"github.com/aws/aws-sdk-go/service/elasticache"
9+
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
710
)
811

912
type ElasticacheReplicationGroup struct {
10-
svc *elasticache.ElastiCache
11-
groupID *string
13+
svc *elasticache.ElastiCache
14+
groupID *string
15+
createTime *time.Time
1216
}
1317

1418
func init() {
@@ -29,8 +33,9 @@ func ListElasticacheReplicationGroups(sess *session.Session) ([]Resource, error)
2933

3034
for _, replicationGroup := range resp.ReplicationGroups {
3135
resources = append(resources, &ElasticacheReplicationGroup{
32-
svc: svc,
33-
groupID: replicationGroup.ReplicationGroupId,
36+
svc: svc,
37+
groupID: replicationGroup.ReplicationGroupId,
38+
createTime: replicationGroup.ReplicationGroupCreateTime,
3439
})
3540
}
3641

@@ -44,6 +49,18 @@ func ListElasticacheReplicationGroups(sess *session.Session) ([]Resource, error)
4449
return resources, nil
4550
}
4651

52+
func (i *ElasticacheReplicationGroup) Properties() types.Properties {
53+
properties := types.NewProperties()
54+
55+
properties.Set("ID", i.groupID)
56+
57+
if i.createTime != nil {
58+
properties.Set("CreateTime", i.createTime.Format(time.RFC3339))
59+
}
60+
61+
return properties
62+
}
63+
4764
func (i *ElasticacheReplicationGroup) Remove() error {
4865
params := &elasticache.DeleteReplicationGroupInput{
4966
ReplicationGroupId: i.groupID,

resources/iam-user-access-keys.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package resources
22

33
import (
44
"fmt"
5+
"time"
56

67
"github.com/aws/aws-sdk-go/aws/session"
78
"github.com/aws/aws-sdk-go/service/iam"
@@ -11,6 +12,7 @@ import (
1112
type IAMUserAccessKey struct {
1213
svc *iam.IAM
1314
accessKeyId string
15+
createDate *time.Time
1416
userName string
1517
status string
1618
userTags []*iam.Tag
@@ -47,6 +49,7 @@ func ListIAMUserAccessKeys(sess *session.Session) ([]Resource, error) {
4749
resources = append(resources, &IAMUserAccessKey{
4850
svc: svc,
4951
accessKeyId: *meta.AccessKeyId,
52+
createDate: meta.CreateDate,
5053
userName: *meta.UserName,
5154
status: *meta.Status,
5255
userTags: userTags.Tags,
@@ -75,6 +78,10 @@ func (e *IAMUserAccessKey) Properties() types.Properties {
7578
properties.Set("UserName", e.userName)
7679
properties.Set("AccessKeyID", e.accessKeyId)
7780

81+
if e.createDate != nil {
82+
properties.Set("CreateDate", e.createDate.Format(time.RFC3339))
83+
}
84+
7885
for _, tag := range e.userTags {
7986
properties.SetTag(tag.Key, tag.Value)
8087
}

resources/iam-users.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
package resources
22

33
import (
4+
"time"
5+
46
"github.com/aws/aws-sdk-go/aws/session"
57
"github.com/aws/aws-sdk-go/service/iam"
68
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
79
"github.com/sirupsen/logrus"
810
)
911

1012
type IAMUser struct {
11-
svc *iam.IAM
12-
name string
13-
tags []*iam.Tag
13+
svc *iam.IAM
14+
name string
15+
tags []*iam.Tag
16+
createDate *time.Time
17+
passwordLastUsed *time.Time
1418
}
1519

1620
func init() {
@@ -37,9 +41,11 @@ func ListIAMUsers(sess *session.Session) ([]Resource, error) {
3741
continue
3842
}
3943
resources = append(resources, &IAMUser{
40-
svc: svc,
41-
name: *out.UserName,
42-
tags: user.Tags,
44+
svc: svc,
45+
name: *user.UserName,
46+
tags: user.Tags,
47+
createDate: user.CreateDate,
48+
passwordLastUsed: user.PasswordLastUsed,
4349
})
4450
}
4551
return true
@@ -70,6 +76,13 @@ func (e *IAMUser) Properties() types.Properties {
7076
properties := types.NewProperties()
7177
properties.Set("Name", e.name)
7278

79+
if e.createDate != nil {
80+
properties.Set("CreateDate", e.createDate.Format(time.RFC3339))
81+
}
82+
if e.passwordLastUsed != nil {
83+
properties.Set("PasswordLastUsed", e.passwordLastUsed.Format(time.RFC3339))
84+
}
85+
7386
for _, tag := range e.tags {
7487
properties.SetTag(tag.Key, tag.Value)
7588
}

0 commit comments

Comments
 (0)