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

refactor(iam): remove adapting nested users and groups #168

Merged
merged 1 commit into from
Jun 7, 2024
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
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