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

Add dates to IAM users, access keys & Elasticache Replication Groups #1093

Merged
merged 4 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading