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

Function removeUserRolesCmd

internal/cli/users_roles.go:193–253  ·  view source on GitHub ↗
(cli *cli)

Source from the content-addressed store, hash-verified

191}
192
193func removeUserRolesCmd(cli *cli) *cobra.Command {
194 var inputs userRolesInput
195
196 cmd := &cobra.Command{
197 Use: "remove",
198 Aliases: []string{"rm"},
199 Args: cobra.MaximumNArgs(1),
200 Short: "Remove roles from a user",
201 Long: "Remove existing roles from a user.",
202 Example: ` auth0 users roles remove <user-id>
203 auth0 users roles remove <user-id> --roles <role-id1,role-id2>
204 auth0 users roles rm <user-id> -r "rol_1eKJp3jV04SiU04h,rol_2eKJp3jV04SiU04h" --json
205 auth0 users roles rm <user-id> -r "rol_1eKJp3jV04SiU04h,rol_2eKJp3jV04SiU04h" --json-compact`,
206 RunE: func(cmd *cobra.Command, args []string) error {
207 if len(args) == 0 {
208 if err := userID.Ask(cmd, &inputs.ID); err != nil {
209 return err
210 }
211 } else {
212 inputs.ID = args[0]
213 }
214
215 if len(inputs.Roles) == 0 {
216 if err := cli.getUserRoles(cmd.Context(), &inputs, userRolesToRemovePickerOptions, pickUserRoles); err != nil {
217 return err
218 }
219 }
220
221 var rolesToRemove []*management.Role
222 for _, roleID := range inputs.Roles {
223 rolesToRemove = append(rolesToRemove, &management.Role{
224 ID: auth0.String(roleID),
225 })
226 }
227
228 if err := ansi.Waiting(func() (err error) {
229 return cli.api.User.RemoveRoles(cmd.Context(), inputs.ID, rolesToRemove)
230 }); err != nil {
231 return fmt.Errorf("failed to remove roles for user with ID %q: %w", inputs.ID, err)
232 }
233
234 var userRoleList *management.RoleList
235 if err := ansi.Waiting(func() (err error) {
236 userRoleList, err = cli.api.User.Roles(cmd.Context(), inputs.ID)
237 return err
238 }); err != nil {
239 return fmt.Errorf("failed to read roles for user with ID %q: %w", inputs.ID, err)
240 }
241
242 cli.renderer.UserRoleList(userRoleList.Roles)
243
244 return nil
245 },
246 }
247
248 userRoles.RegisterStringSlice(cmd, &inputs.Roles, nil)
249 cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.")
250 cmd.Flags().BoolVar(&cli.jsonCompact, "json-compact", false, "Output in compact json format.")

Callers 1

userRolesCmdFunction · 0.85

Calls 8

WaitingFunction · 0.92
getUserRolesMethod · 0.80
ErrorfMethod · 0.80
UserRoleListMethod · 0.80
RegisterStringSliceMethod · 0.80
RemoveRolesMethod · 0.65
RolesMethod · 0.65
AskMethod · 0.45

Tested by

no test coverage detected