Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix apps shown in multi select when no app-id is passed #648

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 32 additions & 43 deletions internal/cli/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func useAppCmd(cli *cli) *cobra.Command {
inputs.ID = ""
} else {
if len(args) == 0 {
err := appID.Pick(cmd, &inputs.ID, cli.appPickerOptions)
err := appID.Pick(cmd, &inputs.ID, cli.appPickerOptions())
if err != nil {
return err
}
Expand Down Expand Up @@ -270,7 +270,7 @@ func showAppCmd(cli *cli) *cobra.Command {
auth0 apps show <app-id> -r --json`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
err := appID.Pick(cmd, &inputs.ID, cli.appPickerOptions)
err := appID.Pick(cmd, &inputs.ID, cli.appPickerOptions())
if err != nil {
return err
}
Expand Down Expand Up @@ -319,7 +319,7 @@ func deleteAppCmd(cli *cli) *cobra.Command {
auth0 apps delete <app-id> --force`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
err := appID.Pick(cmd, &inputs.ID, cli.appPickerOptions)
err := appID.Pick(cmd, &inputs.ID, cli.appPickerOptions())
if err != nil {
return err
}
Expand Down Expand Up @@ -536,7 +536,7 @@ func updateAppCmd(cli *cli) *cobra.Command {
var current *management.Client

if len(args) == 0 {
err := appID.Pick(cmd, &inputs.ID, cli.appPickerOptions)
err := appID.Pick(cmd, &inputs.ID, cli.appPickerOptions())
if err != nil {
return err
}
Expand Down Expand Up @@ -727,7 +727,7 @@ func openAppCmd(cli *cli) *cobra.Command {
auth0 apps open <app-id>`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
err := appID.Pick(cmd, &inputs.ID, cli.appPickerOptions)
err := appID.Pick(cmd, &inputs.ID, cli.appPickerOptions())
if err != nil {
return err
}
Expand Down Expand Up @@ -868,48 +868,37 @@ func stringSliceToPtr(s []string) *[]string {
return &s
}

func (c *cli) appPickerOptions() (pickerOptions, error) {
list, err := c.api.Client.List()
if err != nil {
return nil, err
}

tenant, err := c.getTenant()
if err != nil {
return nil, err
}

// NOTE(cyx): To keep the contract for this simple, we'll rely on the
// implicit knowledge that the default value for the picker is the
// first option. With that in mind, we'll use the state in
// tenant.DefaultAppID to determine which should be chosen as the
// default.
var (
priorityOpts, opts pickerOptions
)
for _, c := range list.Clients {
// Empty type means the default client that we shouldn't display.
// TODO(sergiught): We only need to exclude generic app types for
// the auth0 qs download command. Fix this in separate PR.
if c.GetAppType() == "" {
continue
func (c *cli) appPickerOptions(requestOpts ...management.RequestOption) pickerOptionsFunc {
requestOpts = append(requestOpts, management.Parameter("is_global", "false"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this PR we can follow up with another one where we can remove the "All Applications" hack removal from the apps display pkg to skip showing the global client.


return func() (pickerOptions, error) {
clientList, err := c.api.Client.List(requestOpts...)
if err != nil {
return nil, err
}

tenant, err := c.getTenant()
if err != nil {
return nil, err
}

value := c.GetClientID()
label := fmt.Sprintf("%s %s", c.GetName(), ansi.Faint("("+value+")"))
opt := pickerOption{value: value, label: label}
var priorityOpts, opts pickerOptions
for _, client := range clientList.Clients {
value := client.GetClientID()
label := fmt.Sprintf("%s %s", client.GetName(), ansi.Faint("("+value+")"))
option := pickerOption{value: value, label: label}

// check if this is currently the default application.
if tenant.DefaultAppID == c.GetClientID() {
priorityOpts = append(priorityOpts, opt)
} else {
opts = append(opts, opt)
if tenant.DefaultAppID == client.GetClientID() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 There's very minimal usage of the default app id at the moment within the cli, could be something we might want to remove or enhance support for.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to leave it as it is for now.

priorityOpts = append(priorityOpts, option)
} else {
opts = append(opts, option)
}
}
}

if len(opts)+len(priorityOpts) == 0 {
return nil, errNoApps
}
if len(opts)+len(priorityOpts) == 0 {
return nil, errNoApps
}

return append(priorityOpts, opts...), nil
return append(priorityOpts, opts...), nil
}
}
6 changes: 5 additions & 1 deletion internal/cli/quickstarts.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,11 @@ func (i *qsInputs) fromArgs(cmd *cobra.Command, args []string, cli *cli) error {
}

if len(args) == 0 {
if err := qsClientID.Pick(cmd, &i.ClientID, cli.appPickerOptions); err != nil {
if err := qsClientID.Pick(
cmd,
&i.ClientID,
cli.appPickerOptions(management.Parameter("app_type", "native,spa,regular_web,non_interactive")),
); err != nil {
return err
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (c *cli) customDomainPickerOptions() (pickerOptions, error) {
}

func (c *cli) appPickerWithCreateOption() (pickerOptions, error) {
options, err := c.appPickerOptions()
options, err := c.appPickerOptions()()
if err != nil {
return nil, err
}
Expand Down