diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9bb80cf68..f65d435fc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,7 +9,7 @@ From the top-level directory: ``` $ make build -$ ./auth0 --help +$ ./out/auth0 --help ``` ## Adding a new command @@ -41,7 +41,7 @@ We use vendoring, so the last step is required. > This is only possible if you're a repository maintainer. -The release is driven by a Github **workflow** triggered when a new **tag** is **created**. The workflow will run the checks and trigger _Goreleaser_ to: +The release is driven by a GitHub **workflow** triggered when a new **tag** is **created**. The workflow will run the checks and trigger _Goreleaser_ to: - create the Release with the proper description (changelog) - upload the binaries for the different architectures - update https://github.com/auth0/homebrew-auth0-cli with the latest binary reference diff --git a/docs/auth0_apis_list.md b/docs/auth0_apis_list.md index 98a739fa6..aedec1fe4 100644 --- a/docs/auth0_apis_list.md +++ b/docs/auth0_apis_list.md @@ -24,7 +24,7 @@ auth0 apis list [flags] ``` --json Output in json format. - -n, --number int Number of apps to retrieve (default 50) + -n, --number int Number of APIs to retrieve. Minimum 1, maximum 1000. (default 50) ``` diff --git a/docs/auth0_apps_list.md b/docs/auth0_apps_list.md index a5789b903..e8bacaa6d 100644 --- a/docs/auth0_apps_list.md +++ b/docs/auth0_apps_list.md @@ -25,7 +25,7 @@ auth0 apps list [flags] ``` --json Output in json format. - -n, --number int Number of apps to retrieve (default 50) + -n, --number int Number of apps to retrieve. Minimum 1, maximum 1000. (default 50) -r, --reveal-secrets Display the application secrets ('signing_keys', 'client_secret') as part of the command output. ``` diff --git a/docs/auth0_orgs_list.md b/docs/auth0_orgs_list.md index b3af6ca13..62ddf1c94 100644 --- a/docs/auth0_orgs_list.md +++ b/docs/auth0_orgs_list.md @@ -24,7 +24,7 @@ auth0 orgs list [flags] ``` --json Output in json format. - -n, --number int Number of apps to retrieve (default 50) + -n, --number int Number of organizations to retrieve. Minimum 1, maximum 1000. (default 50) ``` diff --git a/docs/auth0_orgs_members_list.md b/docs/auth0_orgs_members_list.md index b67062619..a179c625e 100644 --- a/docs/auth0_orgs_members_list.md +++ b/docs/auth0_orgs_members_list.md @@ -24,7 +24,7 @@ auth0 orgs members list [flags] ``` --json Output in json format. - -n, --number int Number of apps to retrieve (default 50) + -n, --number int Number of organization members to retrieve. Minimum 1, maximum 1000. (default 50) ``` diff --git a/docs/auth0_orgs_roles_list.md b/docs/auth0_orgs_roles_list.md index 012913dc2..f4eced8c9 100644 --- a/docs/auth0_orgs_roles_list.md +++ b/docs/auth0_orgs_roles_list.md @@ -24,7 +24,7 @@ auth0 orgs roles list [flags] ``` --json Output in json format. - -n, --number int Number of apps to retrieve (default 50) + -n, --number int Number of organization roles to retrieve. Minimum 1, maximum 1000. (default 50) ``` diff --git a/docs/auth0_orgs_roles_members_list.md b/docs/auth0_orgs_roles_members_list.md index 829ac4fb7..3293f414e 100644 --- a/docs/auth0_orgs_roles_members_list.md +++ b/docs/auth0_orgs_roles_members_list.md @@ -26,7 +26,7 @@ auth0 orgs roles members list [flags] ``` --json Output in json format. - -n, --number int Number of apps to retrieve (default 50) + -n, --number int Number of members to retrieve. Minimum 1, maximum 1000. (default 50) -r, --role-id string Role Identifier. ``` diff --git a/docs/auth0_roles_list.md b/docs/auth0_roles_list.md index e8dc2a708..fd85db8d7 100644 --- a/docs/auth0_roles_list.md +++ b/docs/auth0_roles_list.md @@ -24,7 +24,7 @@ auth0 roles list [flags] ``` --json Output in json format. - -n, --number int Number of apps to retrieve (default 50) + -n, --number int Number of roles to retrieve. Minimum 1, maximum 1000. (default 50) ``` diff --git a/docs/auth0_roles_permissions_list.md b/docs/auth0_roles_permissions_list.md index b5d06e917..e7c1ada00 100644 --- a/docs/auth0_roles_permissions_list.md +++ b/docs/auth0_roles_permissions_list.md @@ -15,14 +15,16 @@ auth0 roles permissions list [flags] ``` auth0 roles permissions list auth0 roles permissions ls - auth0 roles permissions ls --json + auth0 roles permissions ls --number 100 + auth0 roles permissions ls -n 100 --json ``` ## Flags ``` - --json Output in json format. + --json Output in json format. + -n, --number int Number of permissions to retrieve. Minimum 1, maximum 1000. (default 50) ``` diff --git a/docs/auth0_users_search.md b/docs/auth0_users_search.md index e56204b52..0654dddb3 100644 --- a/docs/auth0_users_search.md +++ b/docs/auth0_users_search.md @@ -25,7 +25,7 @@ auth0 users search [flags] ``` --json Output in json format. - -n, --number int Number of users, that match the search criteria, to retrieve. Maximum result number is 1000. If limit is hit, please refine the search query. (default 50) + -n, --number int Number of users, that match the search criteria, to retrieve. Minimum 1, maximum 1000. If limit is hit, refine the search query. (default 50) -q, --query string Query in Lucene query syntax. See https://auth0.com/docs/users/user-search/user-search-query-syntax for more details. -s, --sort string Field to sort by. Use 'field:order' where 'order' is '1' for ascending and '-1' for descending. e.g. 'created_at:1'. ``` diff --git a/internal/ansi/ansi.go b/internal/ansi/ansi.go index b5ea92070..6491153ea 100644 --- a/internal/ansi/ansi.go +++ b/internal/ansi/ansi.go @@ -48,7 +48,7 @@ func Color() aurora.Aurora { // Initialize re-instantiates the Aurora instance // This initialization step is necessary because the parsing of the -// --no-color flag is done fairly late in the application cycle +// --no-color flag is done fairly late in the application cycle. func Initialize(shouldDisableColors bool) { DisableColors = shouldDisableColors color = Color() diff --git a/internal/cli/apis.go b/internal/cli/apis.go index abee9b8ff..82303e5ad 100644 --- a/internal/cli/apis.go +++ b/internal/cli/apis.go @@ -54,6 +54,12 @@ var ( Help: "Whether Refresh Tokens can be issued for this API (true) or not (false).", AlwaysPrompt: true, } + apiNumber = Flag{ + Name: "Number", + LongForm: "number", + ShortForm: "n", + Help: "Number of APIs to retrieve. Minimum 1, maximum 1000.", + } ) func apisCmd(cli *cli) *cobra.Command { @@ -107,6 +113,10 @@ func listApisCmd(cli *cli) *cobra.Command { auth0 apis ls --number 100 auth0 apis ls -n 100 --json`, RunE: func(cmd *cobra.Command, args []string) error { + 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, @@ -139,7 +149,7 @@ func listApisCmd(cli *cli) *cobra.Command { } cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") - number.RegisterInt(cmd, &inputs.Number, defaultPageSize) + apiNumber.RegisterInt(cmd, &inputs.Number, defaultPageSize) return cmd } diff --git a/internal/cli/apps.go b/internal/cli/apps.go index 90b2a6014..dbb114854 100644 --- a/internal/cli/apps.go +++ b/internal/cli/apps.go @@ -119,11 +119,11 @@ var ( ShortForm: "r", Help: "Display the application secrets ('signing_keys', 'client_secret') as part of the command output.", } - number = Flag{ + appNumber = Flag{ Name: "Number", LongForm: "number", ShortForm: "n", - Help: "Number of apps to retrieve", + Help: "Number of apps to retrieve. Minimum 1, maximum 1000.", } ) @@ -216,6 +216,10 @@ func listAppsCmd(cli *cli) *cobra.Command { auth0 apps list --reveal-secrets --number 100 auth0 apps ls -r -n 100 --json`, RunE: func(cmd *cobra.Command, args []string) error { + 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, @@ -244,7 +248,7 @@ func listAppsCmd(cli *cli) *cobra.Command { cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") revealSecrets.RegisterBool(cmd, &inputs.RevealSecrets, false) - number.RegisterInt(cmd, &inputs.Number, defaultPageSize) + appNumber.RegisterInt(cmd, &inputs.Number, defaultPageSize) return cmd } diff --git a/internal/cli/organizations.go b/internal/cli/organizations.go index f99f41dc8..57bb2a2b0 100644 --- a/internal/cli/organizations.go +++ b/internal/cli/organizations.go @@ -77,6 +77,13 @@ var ( Help: "Role Identifier.", IsRequired: true, } + + // Purposefully not setting the Help value on the Flag because overridden where appropriate. + organizationNumber = Flag{ + Name: "Number", + LongForm: "number", + ShortForm: "n", + } ) func organizationsCmd(cli *cli) *cobra.Command { @@ -117,6 +124,10 @@ func listOrganizationsCmd(cli *cli) *cobra.Command { auth0 orgs ls --json auth0 orgs ls -n 100`, RunE: func(cmd *cobra.Command, args []string) error { + 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, @@ -149,7 +160,8 @@ func listOrganizationsCmd(cli *cli) *cobra.Command { } cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") - number.RegisterInt(cmd, &inputs.Number, defaultPageSize) + organizationNumber.Help = "Number of organizations to retrieve. Minimum 1, maximum 1000." + organizationNumber.RegisterInt(cmd, &inputs.Number, defaultPageSize) return cmd } @@ -507,6 +519,10 @@ func listMembersOrganizationCmd(cli *cli) *cobra.Command { auth0 orgs members list --number 100 auth0 orgs members ls -n 100 --json`, RunE: func(cmd *cobra.Command, args []string) error { + if inputs.Number < 1 || inputs.Number > 1000 { + return fmt.Errorf("number flag invalid, please pass a number between 1 and 1000") + } + if len(args) == 0 { err := organizationID.Pick(cmd, &inputs.ID, cli.organizationPickerOptions) if err != nil { @@ -526,7 +542,8 @@ func listMembersOrganizationCmd(cli *cli) *cobra.Command { }, } - number.RegisterInt(cmd, &inputs.Number, defaultPageSize) + organizationNumber.Help = "Number of organization members to retrieve. Minimum 1, maximum 1000." + organizationNumber.RegisterInt(cmd, &inputs.Number, defaultPageSize) cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") cmd.SetUsageTemplate(resourceUsageTemplate()) @@ -565,6 +582,9 @@ func listRolesOrganizationCmd(cli *cli) *cobra.Command { auth0 orgs roles list --number 100 auth0 orgs roles ls -n 100 --json`, RunE: func(cmd *cobra.Command, args []string) error { + if inputs.Number < 1 || inputs.Number > 1000 { + return fmt.Errorf("number flag invalid, please pass a number between 1 and 1000") + } if len(args) == 0 { err := organizationID.Pick(cmd, &inputs.OrgID, cli.organizationPickerOptions) if err != nil { @@ -588,7 +608,8 @@ func listRolesOrganizationCmd(cli *cli) *cobra.Command { }, } - number.RegisterInt(cmd, &inputs.Number, defaultPageSize) + organizationNumber.Help = "Number of organization roles to retrieve. Minimum 1, maximum 1000." + organizationNumber.RegisterInt(cmd, &inputs.Number, defaultPageSize) cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") @@ -628,6 +649,10 @@ func listMembersRolesOrganizationCmd(cli *cli) *cobra.Command { auth0 orgs roles members ls -r role -n 100 auth0 orgs roles members ls -r role -n 100 --json`, RunE: func(cmd *cobra.Command, args []string) error { + if inputs.Number < 1 || inputs.Number > 1000 { + return fmt.Errorf("number flag invalid, please pass a number between 1 and 1000") + } + if len(args) == 0 { err := organizationID.Pick(cmd, &inputs.OrgID, cli.organizationPickerOptions) if err != nil { @@ -661,7 +686,8 @@ func listMembersRolesOrganizationCmd(cli *cli) *cobra.Command { cmd.SetUsageTemplate(resourceUsageTemplate()) cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") roleIdentifier.RegisterString(cmd, &inputs.RoleID, "") - number.RegisterInt(cmd, &inputs.Number, defaultPageSize) + organizationNumber.Help = "Number of members to retrieve. Minimum 1, maximum 1000." + organizationNumber.RegisterInt(cmd, &inputs.Number, defaultPageSize) return cmd } diff --git a/internal/cli/roles.go b/internal/cli/roles.go index 6d1a4a368..ef784993b 100644 --- a/internal/cli/roles.go +++ b/internal/cli/roles.go @@ -29,6 +29,12 @@ var ( ShortForm: "d", Help: "Description of the role.", } + roleNumber = Flag{ + Name: "Number", + LongForm: "number", + ShortForm: "n", + Help: "Number of roles to retrieve. Minimum 1, maximum 1000.", + } ) func rolesCmd(cli *cli) *cobra.Command { @@ -66,6 +72,10 @@ func listRolesCmd(cli *cli) *cobra.Command { auth0 roles ls --number 100 auth0 roles ls -n 100 --json`, RunE: func(cmd *cobra.Command, args []string) error { + 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, @@ -98,7 +108,7 @@ func listRolesCmd(cli *cli) *cobra.Command { } cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") - number.RegisterInt(cmd, &inputs.Number, defaultPageSize) + roleNumber.RegisterInt(cmd, &inputs.Number, defaultPageSize) return cmd } diff --git a/internal/cli/roles_permissions.go b/internal/cli/roles_permissions.go index ee8fbc576..5dd603f13 100644 --- a/internal/cli/roles_permissions.go +++ b/internal/cli/roles_permissions.go @@ -8,8 +8,6 @@ import ( "github.com/auth0/go-auth0" "github.com/auth0/go-auth0/management" "github.com/spf13/cobra" - - "github.com/auth0/auth0-cli/internal/ansi" ) var ( @@ -28,6 +26,13 @@ var ( Help: "Permissions.", IsRequired: true, } + + roleAPIPermissionsNumber = Flag{ + Name: "Number", + LongForm: "number", + ShortForm: "n", + Help: "Number of permissions to retrieve. Minimum 1, maximum 1000.", + } ) func rolePermissionsCmd(cli *cli) *cobra.Command { @@ -48,7 +53,8 @@ func rolePermissionsCmd(cli *cli) *cobra.Command { func listRolePermissionsCmd(cli *cli) *cobra.Command { var inputs struct { - ID string + ID string + Number int } cmd := &cobra.Command{ @@ -59,8 +65,13 @@ func listRolePermissionsCmd(cli *cli) *cobra.Command { Long: "List existing permissions defined in a role. To add a permission, run: `auth0 roles permissions add`.", Example: ` auth0 roles permissions list auth0 roles permissions ls - auth0 roles permissions ls --json`, + auth0 roles permissions ls --number 100 + auth0 roles permissions ls -n 100 --json`, RunE: func(cmd *cobra.Command, args []string) error { + if inputs.Number < 1 || inputs.Number > 1000 { + return fmt.Errorf("number flag invalid, please pass a number between 1 and 1000") + } + if len(args) == 0 { err := roleID.Pick(cmd, &inputs.ID, cli.rolePickerOptions) if err != nil { @@ -70,22 +81,38 @@ func listRolePermissionsCmd(cli *cli) *cobra.Command { inputs.ID = args[0] } - var list *management.PermissionList + list, err := getWithPagination( + cmd.Context(), + inputs.Number, + func(opts ...management.RequestOption) (result []interface{}, hasNext bool, err error) { + permissionsList, err := cli.api.Role.Permissions(inputs.ID, opts...) + if err != nil { + return nil, false, err + } + + for _, role := range permissionsList.Permissions { + result = append(result, role) + } + return result, permissionsList.HasNext(), nil + }, + ) - if err := ansi.Waiting(func() error { - var err error - list, err = cli.api.Role.Permissions(inputs.ID) - return err - }); err != nil { - return fmt.Errorf("An unexpected error occurred: %w", err) + if err != nil { + return fmt.Errorf("Failed to get permissions for role '%s': %w", inputs.ID, err) + } + + var permissions []*management.Permission + for _, item := range list { + permissions = append(permissions, item.(*management.Permission)) } - cli.renderer.RolePermissionList(list.Permissions) + cli.renderer.RolePermissionList(permissions) return nil }, } cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") + roleAPIPermissionsNumber.RegisterInt(cmd, &inputs.Number, defaultPageSize) return cmd } diff --git a/internal/cli/users.go b/internal/cli/users.go index d97a462d1..d43fc0952 100644 --- a/internal/cli/users.go +++ b/internal/cli/users.go @@ -72,7 +72,7 @@ var ( Name: "Number", LongForm: "number", ShortForm: "n", - Help: "Number of users, that match the search criteria, to retrieve. Maximum result number is 1000. If limit is hit, please refine the search query.", + Help: "Number of users, that match the search criteria, to retrieve. Minimum 1, maximum 1000. If limit is hit, refine the search query.", } userImportTemplate = Flag{ Name: "Template",