MCPcopy Create free account
hub / github.com/auth0/auth0-cli / userRolesToAddPickerOptions

Function userRolesToAddPickerOptions

internal/cli/users_roles.go:295–319  ·  view source on GitHub ↗
(ctx context.Context, cli *cli, userID string)

Source from the content-addressed store, hash-verified

293}
294
295func userRolesToAddPickerOptions(ctx context.Context, cli *cli, userID string) ([]string, error) {
296 currentUserRoleList, err := cli.api.User.Roles(ctx, userID, management.PerPage(100))
297 if err != nil {
298 return nil, fmt.Errorf("failed to read the current roles for user with ID %q: %w", userID, err)
299 }
300
301 var roleList *management.RoleList
302 roleList, err = cli.api.Role.List(ctx)
303 if err != nil {
304 return nil, fmt.Errorf("failed to list all roles: %w", err)
305 }
306
307 if len(roleList.Roles) == len(currentUserRoleList.Roles) {
308 return nil, fmt.Errorf("the user with ID %q has all roles assigned already", userID)
309 }
310
311 var options []string
312 for _, role := range roleList.Roles {
313 if !containsRole(currentUserRoleList.Roles, role.GetID()) {
314 options = append(options, fmt.Sprintf("%s (Name: %s)", role.GetID(), role.GetName()))
315 }
316 }
317
318 return options, nil
319}
320
321func userRolesToRemovePickerOptions(ctx context.Context, cli *cli, userID string) ([]string, error) {
322 currentUserRoleList, err := cli.api.User.Roles(ctx, userID, management.PerPage(100))

Callers 1

Calls 5

containsRoleFunction · 0.85
ErrorfMethod · 0.80
RolesMethod · 0.65
ListMethod · 0.65
GetNameMethod · 0.65

Tested by 1