From ffeace1a71e9862685885810ef74f60843f10328 Mon Sep 17 00:00:00 2001 From: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com> Date: Mon, 13 Feb 2023 18:33:05 +0100 Subject: [PATCH] Fix appPickerOptions to stop skipping generic apps --- internal/cli/apps.go | 75 ++++++++++++++++--------------------- internal/cli/quickstarts.go | 6 ++- internal/cli/test.go | 2 +- 3 files changed, 38 insertions(+), 45 deletions(-) diff --git a/internal/cli/apps.go b/internal/cli/apps.go index 960861e41..9d2e12f23 100644 --- a/internal/cli/apps.go +++ b/internal/cli/apps.go @@ -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 } @@ -270,7 +270,7 @@ func showAppCmd(cli *cli) *cobra.Command { auth0 apps show -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 } @@ -319,7 +319,7 @@ func deleteAppCmd(cli *cli) *cobra.Command { auth0 apps delete --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 } @@ -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 } @@ -727,7 +727,7 @@ func openAppCmd(cli *cli) *cobra.Command { auth0 apps open `, 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 } @@ -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")) + + 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() { + 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 + } } diff --git a/internal/cli/quickstarts.go b/internal/cli/quickstarts.go index ad90c3bca..96bd572e6 100644 --- a/internal/cli/quickstarts.go +++ b/internal/cli/quickstarts.go @@ -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 { diff --git a/internal/cli/test.go b/internal/cli/test.go index fbbe1c6ff..2de91a9ef 100644 --- a/internal/cli/test.go +++ b/internal/cli/test.go @@ -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 }