This repository was archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 727
Add elasticache user and group support #1044
Merged
der-eismann
merged 12 commits into
rebuy-de:main
from
oreillymedia:Add-Elasticache-User-and-Group-Support
Aug 24, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
67be0c0
Adding Elasticache User and UserGroup Support
swhite-oreilly 80c7bae
Create opensearchservice-packages.go
swhite-oreilly 449f471
Delete opensearchservice-packages.go
swhite-oreilly 66c5354
Merge branch 'main' into Add-Elasticache-User-and-Group-Support
swhite-oreilly 91e271b
Updating elasticache user/group list calls with pagination.
swhite-oreilly 43401f9
Reverting versions to match oreilly-main
swhite-oreilly aced3a6
Updating go version to match upstream.
swhite-oreilly 81865a3
Merge branch 'main' into Add-Elasticache-User-and-Group-Support
swhite-oreilly e958ffc
Updating to more closely match style of other resource types.
swhite-oreilly e3d63d7
Merge branch 'main' into Add-Elasticache-User-and-Group-Support
swhite-oreilly c08c6f4
Merge branch 'main' into Add-Elasticache-User-and-Group-Support
swhite-oreilly faa8433
Adding properties to EC user/usergroups.
swhite-oreilly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package resources | ||
|
||
import ( | ||
"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 ElasticacheUserGroup struct { | ||
svc *elasticache.ElastiCache | ||
groupId *string | ||
} | ||
|
||
func init() { | ||
register("ElasticacheUserGroup", ListElasticacheUserGroups) | ||
} | ||
|
||
func ListElasticacheUserGroups(sess *session.Session) ([]Resource, error) { | ||
svc := elasticache.New(sess) | ||
resources := []Resource{} | ||
var nextToken *string | ||
|
||
for { | ||
params := &elasticache.DescribeUserGroupsInput{ | ||
MaxRecords: aws.Int64(100), | ||
Marker: nextToken, | ||
} | ||
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, | ||
}) | ||
} | ||
|
||
// Check if there are more results | ||
if resp.Marker == nil { | ||
break // No more results, exit the loop | ||
} | ||
|
||
// Set the nextToken for the next iteration | ||
nextToken = resp.Marker | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (i *ElasticacheUserGroup) Remove() error { | ||
params := &elasticache.DeleteUserGroupInput{ | ||
UserGroupId: i.groupId, | ||
} | ||
|
||
_, err := i.svc.DeleteUserGroup(params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (i *ElasticacheUserGroup) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("ID", i.groupId) | ||
return properties | ||
} | ||
|
||
func (i *ElasticacheUserGroup) String() string { | ||
return *i.groupId | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package resources | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"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 ElasticacheUser struct { | ||
svc *elasticache.ElastiCache | ||
userId *string | ||
userName *string | ||
} | ||
|
||
func init() { | ||
register("ElasticacheUser", ListElasticacheUsers) | ||
} | ||
|
||
func ListElasticacheUsers(sess *session.Session) ([]Resource, error) { | ||
svc := elasticache.New(sess) | ||
resources := []Resource{} | ||
var nextToken *string | ||
|
||
for { | ||
params := &elasticache.DescribeUsersInput{ | ||
MaxRecords: aws.Int64(100), | ||
Marker: nextToken, | ||
} | ||
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, | ||
}) | ||
} | ||
|
||
// Check if there are more results | ||
if resp.Marker == nil { | ||
break // No more results, exit the loop | ||
} | ||
|
||
// Set the nextToken for the next iteration | ||
nextToken = resp.Marker | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (i *ElasticacheUser) Filter() error { | ||
if strings.HasPrefix(*i.userName, "default") { | ||
return fmt.Errorf("cannot delete default user") | ||
} | ||
return nil | ||
} | ||
|
||
func (i *ElasticacheUser) Remove() error { | ||
params := &elasticache.DeleteUserInput{ | ||
UserId: i.userId, | ||
} | ||
|
||
_, err := i.svc.DeleteUser(params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (i *ElasticacheUser) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("ID", i.userId) | ||
properties.Set("UserName", i.userName) | ||
return properties | ||
} | ||
|
||
func (i *ElasticacheUser) String() string { | ||
return *i.userId | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late reply - would you mind adding properties for both resources as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@der-eismann I have added properties to both resources. Are these sufficient or are there additional properties you would like to see?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No these are fine, thanks!