Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Add dates to IAM users, access keys & Elasticache Replication Groups (#…
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
der-eismann and rbroemeling authored Aug 29, 2023
1 parent bffd366 commit ac386b8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
25 changes: 21 additions & 4 deletions resources/elasticache-replicationgroups.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package resources

import (
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/elasticache"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type ElasticacheReplicationGroup struct {
svc *elasticache.ElastiCache
groupID *string
svc *elasticache.ElastiCache
groupID *string
createTime *time.Time
}

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

for _, replicationGroup := range resp.ReplicationGroups {
resources = append(resources, &ElasticacheReplicationGroup{
svc: svc,
groupID: replicationGroup.ReplicationGroupId,
svc: svc,
groupID: replicationGroup.ReplicationGroupId,
createTime: replicationGroup.ReplicationGroupCreateTime,
})
}

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

func (i *ElasticacheReplicationGroup) Properties() types.Properties {
properties := types.NewProperties()

properties.Set("ID", i.groupID)

if i.createTime != nil {
properties.Set("CreateTime", i.createTime.Format(time.RFC3339))
}

return properties
}

func (i *ElasticacheReplicationGroup) Remove() error {
params := &elasticache.DeleteReplicationGroupInput{
ReplicationGroupId: i.groupID,
Expand Down
7 changes: 7 additions & 0 deletions resources/iam-user-access-keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"fmt"
"time"

"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/iam"
Expand All @@ -11,6 +12,7 @@ import (
type IAMUserAccessKey struct {
svc *iam.IAM
accessKeyId string
createDate *time.Time
userName string
status string
userTags []*iam.Tag
Expand Down Expand Up @@ -47,6 +49,7 @@ func ListIAMUserAccessKeys(sess *session.Session) ([]Resource, error) {
resources = append(resources, &IAMUserAccessKey{
svc: svc,
accessKeyId: *meta.AccessKeyId,
createDate: meta.CreateDate,
userName: *meta.UserName,
status: *meta.Status,
userTags: userTags.Tags,
Expand Down Expand Up @@ -75,6 +78,10 @@ func (e *IAMUserAccessKey) Properties() types.Properties {
properties.Set("UserName", e.userName)
properties.Set("AccessKeyID", e.accessKeyId)

if e.createDate != nil {
properties.Set("CreateDate", e.createDate.Format(time.RFC3339))
}

for _, tag := range e.userTags {
properties.SetTag(tag.Key, tag.Value)
}
Expand Down
25 changes: 19 additions & 6 deletions resources/iam-users.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package resources

import (
"time"

"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
"github.com/sirupsen/logrus"
)

type IAMUser struct {
svc *iam.IAM
name string
tags []*iam.Tag
svc *iam.IAM
name string
tags []*iam.Tag
createDate *time.Time
passwordLastUsed *time.Time
}

func init() {
Expand All @@ -37,9 +41,11 @@ func ListIAMUsers(sess *session.Session) ([]Resource, error) {
continue
}
resources = append(resources, &IAMUser{
svc: svc,
name: *out.UserName,
tags: user.Tags,
svc: svc,
name: *user.UserName,
tags: user.Tags,
createDate: user.CreateDate,
passwordLastUsed: user.PasswordLastUsed,
})
}
return true
Expand Down Expand Up @@ -70,6 +76,13 @@ func (e *IAMUser) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Name", e.name)

if e.createDate != nil {
properties.Set("CreateDate", e.createDate.Format(time.RFC3339))
}
if e.passwordLastUsed != nil {
properties.Set("PasswordLastUsed", e.passwordLastUsed.Format(time.RFC3339))
}

for _, tag := range e.tags {
properties.SetTag(tag.Key, tag.Value)
}
Expand Down

0 comments on commit ac386b8

Please sign in to comment.