Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add elasticache user and group support #11

Closed
Closed
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/rebuy-de/aws-nuke/v2
go 1.19

require (
github.com/aws/aws-sdk-go v1.44.295
github.com/aws/aws-sdk-go v1.44.307
github.com/fatih/color v1.15.0
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/aws/aws-sdk-go v1.44.295 h1:SGjU1+MqttXfRiWHD6WU0DRhaanJgAFY+xIhEaugV8Y=
github.com/aws/aws-sdk-go v1.44.295/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go v1.44.307 h1:2R0/EPgpZcFSUwZhYImq/srjaOrOfLv5MNRzrFyAM38=
github.com/aws/aws-sdk-go v1.44.307/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
36 changes: 26 additions & 10 deletions resources/elasticache-usergroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,34 @@ func init() {
func ListElasticacheUserGroups(sess *session.Session) ([]Resource, error) {
svc := elasticache.New(sess)

params := &elasticache.DescribeUserGroupsInput{MaxRecords: aws.Int64(100)}
resp, err := svc.DescribeUserGroups(params)
if err != nil {
return nil, err
}
var resources []Resource
for _, userGroup := range resp.UserGroups {
resources = append(resources, &ElasticacheUserGroup{
svc: svc,
groupId: userGroup.UserGroupId,
})
var marker *string // Marker for pagination

for {
params := &elasticache.DescribeUserGroupsInput{
MaxRecords: aws.Int64(100),
Marker: marker,
}
resp, err := svc.DescribeUserGroups(params)
if err != nil {
return nil, err
}

for _, userGroup := range resp.UserGroups {
resources = append(resources, &ElasticacheUserGroup{
svc: svc,
groupId: userGroup.UserGroupId,
})
}

// If there are more results, the response will have a Marker.
// Set the marker for the next iteration.
if resp.Marker != nil {
marker = resp.Marker
} else {
// No more results, break the loop.
break
}
}

return resources, nil
Expand Down
38 changes: 27 additions & 11 deletions resources/elasticache-users.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,35 @@ func init() {
func ListElasticacheUsers(sess *session.Session) ([]Resource, error) {
svc := elasticache.New(sess)

params := &elasticache.DescribeUsersInput{MaxRecords: aws.Int64(100)}
resp, err := svc.DescribeUsers(params)
if err != nil {
return nil, err
}
var resources []Resource
for _, user := range resp.Users {
resources = append(resources, &ElasticacheUser{
svc: svc,
userId: user.UserId,
userName: user.UserName,
})
var marker *string // Marker for pagination

for {
params := &elasticache.DescribeUsersInput{
MaxRecords: aws.Int64(100),
Marker: marker,
}
resp, err := svc.DescribeUsers(params)
if err != nil {
return nil, err
}

for _, user := range resp.Users {
resources = append(resources, &ElasticacheUser{
svc: svc,
userId: user.UserId,
userName: user.UserName,
})
}

// If there are more results, the response will have a Marker.
// Set the marker for the next iteration.
if resp.Marker != nil {
marker = resp.Marker
} else {
// No more results, break the loop.
break
}
}

return resources, nil
Expand Down
Loading