-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to view a user's assigned roles
- Loading branch information
Showing
16 changed files
with
190 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
layout: default | ||
--- | ||
# auth0 users roles | ||
|
||
Manage a user's assigned roles. To learn more about roles and their behavior, read [Role-based Access Control](https://auth0.com/docs/manage-users/access-control/rbac). | ||
|
||
## Commands | ||
|
||
- [auth0 users roles show](auth0_users_roles_show.md) - Show a user's roles | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
layout: default | ||
--- | ||
# auth0 users roles show | ||
|
||
Display information about an existing user's assigned roles. | ||
|
||
## Usage | ||
``` | ||
auth0 users roles show [flags] | ||
``` | ||
|
||
## Examples | ||
|
||
``` | ||
auth0 users roles show | ||
auth0 users roles show <user-id> | ||
auth0 users roles show <user-id> --number 100 | ||
auth0 users roles show <user-id> -n 100 --json | ||
``` | ||
|
||
|
||
## Flags | ||
|
||
``` | ||
--json Output in json format. | ||
-n, --number int Number of user roles to retrieve. Maximum result number is 1000. (default 50) | ||
``` | ||
|
||
|
||
## InheritedFlags | ||
|
||
``` | ||
--debug Enable debug mode. | ||
--no-color Disable colors. | ||
--no-input Disable interactivity. | ||
--tenant string Specific tenant to use. | ||
``` | ||
|
||
|
||
## Related Commands | ||
|
||
- [auth0 users roles show](auth0_users_roles_show.md) - Show a user's roles | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/auth0/go-auth0/management" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
userRolesNumber = Flag{ | ||
Name: "Number", | ||
LongForm: "number", | ||
ShortForm: "n", | ||
Help: "Number of user roles to retrieve. Maximum result number is 1000.", | ||
} | ||
) | ||
|
||
func userRolesCmd(cli *cli) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "roles", | ||
Short: "Manage a user's roles", | ||
Long: "Manage a user's assigned roles. To learn more about roles and their behavior, read " + | ||
"[Role-based Access Control](https://auth0.com/docs/manage-users/access-control/rbac).", | ||
} | ||
|
||
cmd.SetUsageTemplate(resourceUsageTemplate()) | ||
cmd.AddCommand(showUserRolesCmd(cli)) | ||
|
||
return cmd | ||
} | ||
|
||
func showUserRolesCmd(cli *cli) *cobra.Command { | ||
var inputs struct { | ||
ID string | ||
Number int | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "show", | ||
Args: cobra.MaximumNArgs(1), | ||
Short: "Show a user's roles", | ||
Long: "Display information about an existing user's assigned roles.", | ||
Example: ` auth0 users roles show | ||
auth0 users roles show <user-id> | ||
auth0 users roles show <user-id> --number 100 | ||
auth0 users roles show <user-id> -n 100 --json`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) == 0 { | ||
if err := userID.Ask(cmd, &inputs.ID); err != nil { | ||
return err | ||
} | ||
} else { | ||
inputs.ID = args[0] | ||
} | ||
|
||
if inputs.Number < 1 || inputs.Number > 1000 { | ||
return fmt.Errorf("number flag invalid, please pass a number between 1 and 1000") | ||
} | ||
|
||
list, err := getWithPagination( | ||
cmd.Context(), | ||
inputs.Number, | ||
func(opts ...management.RequestOption) (result []interface{}, hasNext bool, err error) { | ||
userRoleList, err := cli.api.User.Roles(inputs.ID, opts...) | ||
if err != nil { | ||
return nil, false, err | ||
} | ||
|
||
var output []interface{} | ||
for _, userRole := range userRoleList.Roles { | ||
output = append(output, userRole) | ||
} | ||
|
||
return output, userRoleList.HasNext(), nil | ||
}, | ||
) | ||
if err != nil { | ||
return fmt.Errorf("failed to find roles for user with ID %s: %w", inputs.ID, err) | ||
} | ||
|
||
var userRoles []*management.Role | ||
for _, item := range list { | ||
userRoles = append(userRoles, item.(*management.Role)) | ||
} | ||
|
||
cli.renderer.UserRoleList(userRoles) | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") | ||
userRolesNumber.RegisterInt(cmd, &inputs.Number, defaultPageSize) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -464,6 +464,10 @@ tests: | |
email: [email protected] # Name is not being displayed, hence using email | ||
exit-code: 0 | ||
|
||
users roles show: | ||
command: auth0 users roles show $(cat ./test/integration/identifiers/user-id) | ||
exit-code: 0 | ||
|
||
# Test 'roles create' | ||
roles create and check data: | ||
command: auth0 roles create --name integration-test-role-new1 --description testRole --json --no-input | ||
|