Skip to content

Commit c2ed03f

Browse files
committed
refactor: removed errVerb argument from the modifyUserRoles function, it's too much and a generic error can be returned
1 parent 6d45e91 commit c2ed03f

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

internal/cmd/iam/resolve.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func resolveRoleIDs(ctx context.Context, client *qcloudapi.Client, accountID str
8282
// modifyUserRoles calls AssignUserRoles with the given add/delete IDs, then
8383
// fetches and prints the resulting role list. errVerb is used in the error
8484
// message ("failed to <errVerb> roles").
85-
func modifyUserRoles(s *state.State, cmd *cobra.Command, client *qcloudapi.Client, accountID string, user *iamv1.User, addIDs, removeIDs []string, errVerb string) error {
85+
func modifyUserRoles(s *state.State, cmd *cobra.Command, client *qcloudapi.Client, accountID string, user *iamv1.User, addIDs, removeIDs []string) error {
8686
ctx := cmd.Context()
8787

8888
_, err := client.IAM().AssignUserRoles(ctx, &iamv1.AssignUserRolesRequest{
@@ -92,7 +92,7 @@ func modifyUserRoles(s *state.State, cmd *cobra.Command, client *qcloudapi.Clien
9292
RoleIdsToDelete: removeIDs,
9393
})
9494
if err != nil {
95-
return fmt.Errorf("failed to %s roles: %w", errVerb, err)
95+
return fmt.Errorf("failed to modify roles: %w", err)
9696
}
9797

9898
rolesResp, err := client.IAM().ListUserRoles(ctx, &iamv1.ListUserRolesRequest{

internal/cmd/iam/user_assign_role.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ qcloud iam user assign-role user@example.com --role admin,viewer`,
6161
return err
6262
}
6363

64-
return modifyUserRoles(s, cmd, client, accountID, user, roleIDs, nil, "assign")
64+
return modifyUserRoles(s, cmd, client, accountID, user, roleIDs, nil)
6565
},
6666
}.CobraCommand(s)
6767
}

internal/cmd/iam/user_remove_role.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ qcloud iam user remove-role user@example.com --role admin --role viewer`,
5858
return err
5959
}
6060

61-
return modifyUserRoles(s, cmd, client, accountID, user, nil, roleIDs, "remove")
61+
return modifyUserRoles(s, cmd, client, accountID, user, nil, roleIDs)
6262
},
6363
}.CobraCommand(s)
6464
}

0 commit comments

Comments
 (0)