Skip to content

Commit

Permalink
refactor(iam): remove adapting nested users and groups (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikpivkin authored Jun 7, 2024
1 parent c92585c commit 8a7f09c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 44 deletions.
12 changes: 0 additions & 12 deletions internal/adapters/cloud/aws/iam/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,9 @@ func (a *adapter) adaptGroup(apiGroup iamtypes.Group, state *state.State) (*iam.
}
}

var users []iam.User
if state != nil {
for _, user := range state.AWS.IAM.Users {
for _, userGroup := range user.Groups {
if userGroup.Name.EqualTo(*apiGroup.GroupName) {
users = append(users, user)
}
}
}
}

return &iam.Group{
Metadata: metadata,
Name: types.String(*apiGroup.GroupName, metadata),
Users: users,
Policies: policies,
}, nil
}
32 changes: 0 additions & 32 deletions internal/adapters/cloud/aws/iam/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,34 +75,6 @@ func (a *adapter) getMFADevices(user iamtypes.User) ([]iam.MFADevice, error) {
return devices, nil
}

func (a *adapter) getUserGroups(apiUser iamtypes.User) []iam.Group {
var groups []iam.Group

input := &iamapi.ListGroupsForUserInput{
UserName: apiUser.UserName,
}
for {
output, err := a.api.ListGroupsForUser(a.Context(), input)
if err != nil {
a.Debug("Failed to locate groups attached to user '%s': %s", *apiUser.UserName, err)
break
}
for _, apiGroup := range output.Groups {
group, err := a.adaptGroup(apiGroup, nil)
if err != nil {
a.Debug("Failed to adapt group attached to user '%s': %s", *apiUser.UserName, err)
continue
}
groups = append(groups, *group)
}
if !output.IsTruncated {
break
}
input.Marker = output.Marker
}
return groups
}

func (a *adapter) getUserPolicies(apiUser iamtypes.User) []iam.Policy {
var policies []iam.Policy
input := &iamapi.ListAttachedUserPoliciesInput{
Expand Down Expand Up @@ -192,10 +164,7 @@ func (a *adapter) adaptUser(apiUser iamtypes.User) (*iam.User, error) {

metadata := a.CreateMetadataFromARN(*apiUser.Arn)

groups := a.getUserGroups(apiUser)

policies := a.getUserPolicies(apiUser)

keys, err := a.getUserKeys(apiUser)
if err != nil {
return nil, err
Expand All @@ -219,7 +188,6 @@ func (a *adapter) adaptUser(apiUser iamtypes.User) (*iam.User, error) {
return &iam.User{
Metadata: metadata,
Name: username,
Groups: groups,
Policies: policies,
AccessKeys: keys,
MFADevices: mfaDevices,
Expand Down

0 comments on commit 8a7f09c

Please sign in to comment.