From ae526b53f98f03748e0937cead3e164f60b7066e Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 26 Feb 2021 12:01:29 -0300 Subject: [PATCH 1/8] Cleanup apps commands --- internal/cli/{clients.go => apps.go} | 29 ++++++++++++------- .../cli/{clients_test.go => apps_test.go} | 0 2 files changed, 18 insertions(+), 11 deletions(-) rename internal/cli/{clients.go => apps.go} (92%) rename internal/cli/{clients_test.go => apps_test.go} (100%) diff --git a/internal/cli/clients.go b/internal/cli/apps.go similarity index 92% rename from internal/cli/clients.go rename to internal/cli/apps.go index 237e15c97..bd58321cf 100644 --- a/internal/cli/clients.go +++ b/internal/cli/apps.go @@ -11,10 +11,18 @@ import ( "gopkg.in/auth0.v5/management" ) +const ( + appID = "id" + appName = "name" + appType = "type" + appDescription = "description" +) + func appsCmd(cli *cli) *cobra.Command { cmd := &cobra.Command{ - Use: "apps", - Short: "Manage resources for apps", + Use: "apps", + Short: "Manage resources for applications", + Aliases: []string{"clients"}, } cmd.SetUsageTemplate(resourceUsageTemplate()) @@ -28,15 +36,15 @@ func appsCmd(cli *cli) *cobra.Command { func appsListCmd(cli *cli) *cobra.Command { cmd := &cobra.Command{ Use: "list", - Short: "List your existing apps", + Short: "List your applications", Long: `auth0 apps list -Lists your existing apps. To create one try: +Lists your existing applications. To create one try: auth0 apps create `, RunE: func(cmd *cobra.Command, args []string) error { var list *management.ClientList - err := ansi.Spinner("Loading apps", func() error { + err := ansi.Spinner("Loading applications", func() error { var err error list, err = cli.api.Client.List() return err @@ -60,15 +68,14 @@ func appsDeleteCmd(cli *cli) *cobra.Command { } cmd := &cobra.Command{ Use: "delete", - Short: "Delete an existing app", - Long: `auth0 apps delete --name appName - -auth0 apps delete --app-id myapp + Short: "Delete an application", + Long: `Delete an application: +auth0 apps delete --id id `, RunE: func(cmd *cobra.Command, args []string) error { - if !cmd.Flags().Changed("app-id") { + if !cmd.Flags().Changed("id") { qs := []*survey.Question{ { Name: "AppID", @@ -95,7 +102,7 @@ auth0 apps delete --app-id myapp }, } - cmd.Flags().StringVarP(&flags.AppID, "app-id", "i", "", "app-id of the app.") + cmd.Flags().StringVarP(&flags.AppID, "id", "i", "", "Id of the app.") return cmd } diff --git a/internal/cli/clients_test.go b/internal/cli/apps_test.go similarity index 100% rename from internal/cli/clients_test.go rename to internal/cli/apps_test.go From b1990b1ee684e27e1846534c2861c794070e04d4 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 26 Feb 2021 12:03:02 -0300 Subject: [PATCH 2/8] Refactor delete command --- internal/cli/apis.go | 8 +------- internal/cli/apps.go | 40 +++++++++++++++++++--------------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/internal/cli/apis.go b/internal/cli/apis.go index 871ef54da..3e1d300ce 100644 --- a/internal/cli/apis.go +++ b/internal/cli/apis.go @@ -300,15 +300,9 @@ auth0 apis delete --id id } } - err := ansi.Spinner("Deleting API", func() error { + return ansi.Spinner("Deleting API", func() error { return cli.api.ResourceServer.Delete(flags.ID) }) - - if err != nil { - return err - } - - return nil }, } diff --git a/internal/cli/apps.go b/internal/cli/apps.go index bd58321cf..07bfca84c 100644 --- a/internal/cli/apps.go +++ b/internal/cli/apps.go @@ -7,6 +7,7 @@ import ( "github.com/AlecAivazis/survey/v2" "github.com/auth0/auth0-cli/internal/ansi" "github.com/auth0/auth0-cli/internal/auth0" + "github.com/auth0/auth0-cli/internal/prompt" "github.com/spf13/cobra" "gopkg.in/auth0.v5/management" ) @@ -28,7 +29,7 @@ func appsCmd(cli *cli) *cobra.Command { cmd.SetUsageTemplate(resourceUsageTemplate()) cmd.AddCommand(appsListCmd(cli)) cmd.AddCommand(appsCreateCmd(cli)) - cmd.AddCommand(appsDeleteCmd(cli)) + cmd.AddCommand(deleteAppCmd(cli)) return cmd } @@ -62,10 +63,11 @@ Lists your existing applications. To create one try: return cmd } -func appsDeleteCmd(cli *cli) *cobra.Command { +func deleteAppCmd(cli *cli) *cobra.Command { var flags struct { - AppID string + ID string } + cmd := &cobra.Command{ Use: "delete", Short: "Delete an application", @@ -73,36 +75,32 @@ func appsDeleteCmd(cli *cli) *cobra.Command { auth0 apps delete --id id `, + PreRun: func(cmd *cobra.Command, args []string) { + prepareInteractivity(cmd) + }, RunE: func(cmd *cobra.Command, args []string) error { + if shouldPrompt(cmd, appID) { + input := prompt.TextInput(appID, "Id:", "Id of the application.", true) - if !cmd.Flags().Changed("id") { - qs := []*survey.Question{ - { - Name: "AppID", - Prompt: &survey.Input{ - Message: "AppID:", - Default: "My App", - Help: "ID of the application to delete.", - }, - }, - } - - err := survey.Ask(qs, &flags) - if err != nil { + if err := prompt.AskOne(input, &flags); err != nil { return err } } - c := &management.Client{ - ClientID: &flags.AppID, + + if !cli.force && canPrompt(cmd) { + if confirmed := prompt.Confirm("Are you sure you want to proceed?"); !confirmed { + return nil + } } return ansi.Spinner("Deleting application", func() error { - return cli.api.Client.Delete(*c.ClientID) + return cli.api.Client.Delete(flags.ID) }) }, } - cmd.Flags().StringVarP(&flags.AppID, "id", "i", "", "Id of the app.") + cmd.Flags().StringVarP(&flags.ID, appID, "i", "", "ID of the application.") + mustRequireFlags(cmd, appID) return cmd } From 0648f1389df0a2932d89ea357a6036d0c7f0605c Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 26 Feb 2021 12:47:04 -0300 Subject: [PATCH 3/8] Refactor the create command --- internal/cli/apis.go | 2 +- internal/cli/apps.go | 114 ++++++++++++++++++------------------------- 2 files changed, 49 insertions(+), 67 deletions(-) diff --git a/internal/cli/apis.go b/internal/cli/apis.go index 3e1d300ce..019517252 100644 --- a/internal/cli/apis.go +++ b/internal/cli/apis.go @@ -144,7 +144,7 @@ auth0 apis create --name myapi --identifier http://my-api if shouldPrompt(cmd, apiName) { input := prompt.TextInput( apiName, "Name:", - "Name of the API. You can change the API name later in the API settings.", + "Name of the API. You can change the name later in the API settings.", true) if err := prompt.AskOne(input, &flags); err != nil { diff --git a/internal/cli/apps.go b/internal/cli/apps.go index 07bfca84c..999fb63b7 100644 --- a/internal/cli/apps.go +++ b/internal/cli/apps.go @@ -4,7 +4,6 @@ import ( "fmt" "strings" - "github.com/AlecAivazis/survey/v2" "github.com/auth0/auth0-cli/internal/ansi" "github.com/auth0/auth0-cli/internal/auth0" "github.com/auth0/auth0-cli/internal/prompt" @@ -27,14 +26,14 @@ func appsCmd(cli *cli) *cobra.Command { } cmd.SetUsageTemplate(resourceUsageTemplate()) - cmd.AddCommand(appsListCmd(cli)) - cmd.AddCommand(appsCreateCmd(cli)) + cmd.AddCommand(listAppsCmd(cli)) + cmd.AddCommand(createAppCmd(cli)) cmd.AddCommand(deleteAppCmd(cli)) return cmd } -func appsListCmd(cli *cli) *cobra.Command { +func listAppsCmd(cli *cli) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "List your applications", @@ -105,75 +104,57 @@ auth0 apps delete --id id return cmd } -func appsCreateCmd(cli *cli) *cobra.Command { +func createAppCmd(cli *cli) *cobra.Command { var flags struct { - Name string - AppType string - Description string - Callbacks []string - TokenEndpointAuthMethod string + Name string + Type string + Description string + Callbacks []string + AuthMethod string } + cmd := &cobra.Command{ Use: "create", Short: "Create a new application", Long: `Create a new application: auth0 apps create --name myapp --type [native|spa|regular|m2m] - -- supported application type: - `, +`, RunE: func(cmd *cobra.Command, args []string) error { - // todo(jfatta) on non-interactive the cmd should fail on missing mandatory args (name, type) - if !cmd.Flags().Changed("name") { - qs := []*survey.Question{ - { - Name: "Name", - Prompt: &survey.Input{ - Message: "Name:", - Default: "My App", - Help: "Name of the client (also known as application). You can change the application name later in the application settings.", - }, - }, - } + if shouldPrompt(cmd, appName) { + input := prompt.TextInput( + appName, "Name:", + "Name of the application. You can change the name later in the application settings.", + true) - err := survey.Ask(qs, &flags) - if err != nil { + if err := prompt.AskOne(input, &flags); err != nil { return err } } - if !cmd.Flags().Changed("type") { - qs := []*survey.Question{ - { - Name: "AppType", - Prompt: &survey.Select{ - Message: "Type:", - Help: "\n- Native: Mobile, desktop, CLI and smart device apps running natively." + - "\n- Single Page Web Application: A JavaScript front-end app that uses an API." + - "\n- Regular Web Application: Traditional web app using redirects." + - "\n- Machine To Machine: CLIs, daemons or services running on your backend.", - Options: []string{"Native", "Single Page Web Application", "Regular Web Application", "Machine to Machine"}, - }, - }, - } - err := survey.Ask(qs, &flags) - if err != nil { + if shouldPrompt(cmd, appType) { + input := prompt.SelectInput( + appType, + "Type:", + "\n- Native: Mobile, desktop, CLI and smart device apps running natively."+ + "\n- Single Page Web Application: A JavaScript front-end app that uses an API."+ + "\n- Regular Web Application: Traditional web app using redirects."+ + "\n- Machine To Machine: CLIs, daemons or services running on your backend.", + []string{"Native", "Single Page Web Application", "Regular Web Application", "Machine to Machine"}, + true) + + if err := prompt.AskOne(input, &flags); err != nil { return err } } - if !cmd.Flags().Changed("description") { - qs := []*survey.Question{ - { - Name: "Description", - Prompt: &survey.Input{ - Message: "Description:", - Help: "A free text description of the application.", - }, - }, - } - err := survey.Ask(qs, &flags) - if err != nil { + if shouldPrompt(cmd, appDescription) { + input := prompt.TextInput( + appDescription, "Description:", + "Description of the application.", + false) + + if err := prompt.AskOne(input, &flags); err != nil { return err } } @@ -181,12 +162,12 @@ auth0 apps create --name myapp --type [native|spa|regular|m2m] c := &management.Client{ Name: &flags.Name, Description: &flags.Description, - AppType: auth0.String(apiAppTypeFor(flags.AppType)), + AppType: auth0.String(apiTypeFor(flags.Type)), Callbacks: apiCallbacksFor(flags.Callbacks), - TokenEndpointAuthMethod: apiTokenEndpointAuthMethodFor(flags.TokenEndpointAuthMethod), + TokenEndpointAuthMethod: apiAuthMethodFor(flags.AuthMethod), } - err := ansi.Spinner("Creating client", func() error { + err := ansi.Spinner("Creating application", func() error { return cli.api.Client.Create(c) }) @@ -197,24 +178,26 @@ auth0 apps create --name myapp --type [native|spa|regular|m2m] // note: c is populated with the rest of the client fields by the API during creation. revealClientSecret := auth0.StringValue(c.AppType) != "native" && auth0.StringValue(c.AppType) != "spa" cli.renderer.ClientCreate(c, revealClientSecret) + return nil }, } - cmd.Flags().StringVarP(&flags.Name, "name", "n", "", "Name of the client.") - cmd.Flags().StringVarP(&flags.AppType, "type", "t", "", "Type of the client:\n"+ + + cmd.Flags().StringVarP(&flags.Name, "name", "n", "", "Name of the application.") + cmd.Flags().StringVarP(&flags.Type, "type", "t", "", "Type of application:\n"+ "- native: mobile, desktop, CLI and smart device apps running natively.\n"+ "- spa (single page application): a JavaScript front-end app that uses an API.\n"+ "- regular: Traditional web app using redirects.\n"+ "- m2m (machine to machine): CLIs, daemons or services running on your backend.") - cmd.Flags().StringVarP(&flags.Description, "description", "d", "", "A free text description of the application. Max character count is 140.") + cmd.Flags().StringVarP(&flags.Description, "description", "d", "", "Description of the application. Max character count is 140.") cmd.Flags().StringSliceVarP(&flags.Callbacks, "callbacks", "c", nil, "After the user authenticates we will only call back to any of these URLs. You can specify multiple valid URLs by comma-separating them (typically to handle different environments like QA or testing). Make sure to specify the protocol (https://) otherwise the callback may fail in some cases. With the exception of custom URI schemes for native apps, all callbacks should use protocol https://.") - - cmd.Flags().StringVar(&flags.TokenEndpointAuthMethod, "auth-method", "", "Defines the requested authentication method for the token endpoint. Possible values are 'None' (public application without a client secret), 'Post' (application uses HTTP POST parameters) or 'Basic' (application uses HTTP Basic).") + cmd.Flags().StringVar(&flags.AuthMethod, "auth-method", "", "Defines the requested authentication method for the token endpoint. Possible values are 'None' (public application without a client secret), 'Post' (application uses HTTP POST parameters) or 'Basic' (application uses HTTP Basic).") + mustRequireFlags(cmd, appName, appType) return cmd } -func apiAppTypeFor(v string) string { +func apiTypeFor(v string) string { switch strings.ToLower(v) { case "native": return "native" @@ -236,10 +219,9 @@ func apiCallbacksFor(s []string) []interface{} { res[i] = v } return res - } -func apiTokenEndpointAuthMethodFor(v string) *string { +func apiAuthMethodFor(v string) *string { switch strings.ToLower(v) { case "none": return auth0.String("none") From 6d450e825f3de8ddb5fca2550640bed5caaa3054 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 26 Feb 2021 13:18:24 -0300 Subject: [PATCH 4/8] Add apps update --- internal/cli/apis.go | 2 +- internal/cli/apps.go | 119 +++++++++++++++++++++++++++++++++--- internal/display/clients.go | 29 ++++++--- 3 files changed, 133 insertions(+), 17 deletions(-) diff --git a/internal/cli/apis.go b/internal/cli/apis.go index 019517252..a2abe1cc8 100644 --- a/internal/cli/apis.go +++ b/internal/cli/apis.go @@ -265,7 +265,7 @@ auth0 apis update --id id --name myapi cmd.Flags().StringVarP(&flags.ID, apiID, "i", "", "ID of the API.") cmd.Flags().StringVarP(&flags.Name, apiName, "n", "", "Name of the API.") cmd.Flags().StringVarP(&flags.Scopes, apiScopes, "s", "", "Space-separated list of scopes.") - mustRequireFlags(cmd, apiID, apiName) + mustRequireFlags(cmd, apiID) return cmd } diff --git a/internal/cli/apps.go b/internal/cli/apps.go index 999fb63b7..33047e09f 100644 --- a/internal/cli/apps.go +++ b/internal/cli/apps.go @@ -28,6 +28,7 @@ func appsCmd(cli *cli) *cobra.Command { cmd.SetUsageTemplate(resourceUsageTemplate()) cmd.AddCommand(listAppsCmd(cli)) cmd.AddCommand(createAppCmd(cli)) + cmd.AddCommand(updateAppCmd(cli)) cmd.AddCommand(deleteAppCmd(cli)) return cmd @@ -54,7 +55,7 @@ Lists your existing applications. To create one try: return err } - cli.renderer.ClientList(list.Clients) + cli.renderer.ApplicationList(list.Clients) return nil }, } @@ -120,6 +121,9 @@ func createAppCmd(cli *cli) *cobra.Command { auth0 apps create --name myapp --type [native|spa|regular|m2m] `, + PreRun: func(cmd *cobra.Command, args []string) { + prepareInteractivity(cmd) + }, RunE: func(cmd *cobra.Command, args []string) error { if shouldPrompt(cmd, appName) { input := prompt.TextInput( @@ -149,17 +153,14 @@ auth0 apps create --name myapp --type [native|spa|regular|m2m] } if shouldPrompt(cmd, appDescription) { - input := prompt.TextInput( - appDescription, "Description:", - "Description of the application.", - false) + input := prompt.TextInput(appDescription, "Description:", "Description of the application.", false) if err := prompt.AskOne(input, &flags); err != nil { return err } } - c := &management.Client{ + a := &management.Client{ Name: &flags.Name, Description: &flags.Description, AppType: auth0.String(apiTypeFor(flags.Type)), @@ -168,7 +169,7 @@ auth0 apps create --name myapp --type [native|spa|regular|m2m] } err := ansi.Spinner("Creating application", func() error { - return cli.api.Client.Create(c) + return cli.api.Client.Create(a) }) if err != nil { @@ -176,8 +177,8 @@ auth0 apps create --name myapp --type [native|spa|regular|m2m] } // note: c is populated with the rest of the client fields by the API during creation. - revealClientSecret := auth0.StringValue(c.AppType) != "native" && auth0.StringValue(c.AppType) != "spa" - cli.renderer.ClientCreate(c, revealClientSecret) + revealClientSecret := auth0.StringValue(a.AppType) != "native" && auth0.StringValue(a.AppType) != "spa" + cli.renderer.ApplicationCreate(a, revealClientSecret) return nil }, @@ -197,6 +198,106 @@ auth0 apps create --name myapp --type [native|spa|regular|m2m] return cmd } +func updateAppCmd(cli *cli) *cobra.Command { + var flags struct { + ID string + Name string + Type string + Description string + Callbacks []string + AuthMethod string + } + + cmd := &cobra.Command{ + Use: "create", + Short: "Update a new application", + Long: `Update a new application: + +auth0 apps update --id id --name myapp --type [native|spa|regular|m2m] +`, + PreRun: func(cmd *cobra.Command, args []string) { + prepareInteractivity(cmd) + }, + RunE: func(cmd *cobra.Command, args []string) error { + if shouldPrompt(cmd, appID) { + input := prompt.TextInput(appID, "Id:", "Id of the application.", true) + + if err := prompt.AskOne(input, &flags); err != nil { + return err + } + } + + if shouldPrompt(cmd, appName) { + input := prompt.TextInput(appName, "Name:", "Name of the application", true) + + if err := prompt.AskOne(input, &flags); err != nil { + return err + } + } + + if shouldPrompt(cmd, appType) { + input := prompt.SelectInput( + appType, + "Type:", + "\n- Native: Mobile, desktop, CLI and smart device apps running natively."+ + "\n- Single Page Web Application: A JavaScript front-end app that uses an API."+ + "\n- Regular Web Application: Traditional web app using redirects."+ + "\n- Machine To Machine: CLIs, daemons or services running on your backend.", + []string{"Native", "Single Page Web Application", "Regular Web Application", "Machine to Machine"}, + true) + + if err := prompt.AskOne(input, &flags); err != nil { + return err + } + } + + if shouldPrompt(cmd, appDescription) { + input := prompt.TextInput(appDescription, "Description:", "Description of the application.", false) + + if err := prompt.AskOne(input, &flags); err != nil { + return err + } + } + + a := &management.Client{ + Name: &flags.Name, + Description: &flags.Description, + AppType: auth0.String(apiTypeFor(flags.Type)), + Callbacks: apiCallbacksFor(flags.Callbacks), + TokenEndpointAuthMethod: apiAuthMethodFor(flags.AuthMethod), + } + + err := ansi.Spinner("Updating application", func() error { + return cli.api.Client.Update(flags.ID, c) + }) + + if err != nil { + return err + } + + // note: c is populated with the rest of the client fields by the API during creation. + revealClientSecret := auth0.StringValue(a.AppType) != "native" && auth0.StringValue(a.AppType) != "spa" + cli.renderer.ApplicationUpdate(a, revealClientSecret) + + return nil + }, + } + + cmd.Flags().StringVarP(&flags.ID, appID, "i", "", "ID of the application.") + cmd.Flags().StringVarP(&flags.Name, "name", "n", "", "Name of the application.") + cmd.Flags().StringVarP(&flags.Type, "type", "t", "", "Type of application:\n"+ + "- native: mobile, desktop, CLI and smart device apps running natively.\n"+ + "- spa (single page application): a JavaScript front-end app that uses an API.\n"+ + "- regular: Traditional web app using redirects.\n"+ + "- m2m (machine to machine): CLIs, daemons or services running on your backend.") + cmd.Flags().StringVarP(&flags.Description, "description", "d", "", "Description of the application. Max character count is 140.") + cmd.Flags().StringSliceVarP(&flags.Callbacks, "callbacks", "c", nil, "After the user authenticates we will only call back to any of these URLs. You can specify multiple valid URLs by comma-separating them (typically to handle different environments like QA or testing). Make sure to specify the protocol (https://) otherwise the callback may fail in some cases. With the exception of custom URI schemes for native apps, all callbacks should use protocol https://.") + cmd.Flags().StringVar(&flags.AuthMethod, "auth-method", "", "Defines the requested authentication method for the token endpoint. Possible values are 'None' (public application without a client secret), 'Post' (application uses HTTP POST parameters) or 'Basic' (application uses HTTP Basic).") + mustRequireFlags(cmd, appID) + + return cmd +} + func apiTypeFor(v string) string { switch strings.ToLower(v) { case "native": diff --git a/internal/display/clients.go b/internal/display/clients.go index 25391fcb1..face736cd 100644 --- a/internal/display/clients.go +++ b/internal/display/clients.go @@ -53,8 +53,8 @@ func (v *clientView) AsTableRow() []string { } -func (r *Renderer) ClientList(clients []*management.Client) { - r.Heading(ansi.Bold(r.Tenant), "clients\n") +func (r *Renderer) ApplicationList(clients []*management.Client) { + r.Heading(ansi.Bold(r.Tenant), "applications\n") var res []View for _, c := range clients { if auth0.StringValue(c.Name) == deprecatedAppName { @@ -62,7 +62,7 @@ func (r *Renderer) ClientList(clients []*management.Client) { } res = append(res, &clientView{ Name: auth0.StringValue(c.Name), - Type: appTypeFor(c.AppType), + Type: typeFor(c.AppType), ClientID: auth0.StringValue(c.ClientID), ClientSecret: auth0.StringValue(c.ClientSecret), Callbacks: callbacksFor(c.Callbacks), @@ -72,15 +72,15 @@ func (r *Renderer) ClientList(clients []*management.Client) { r.Results(res) } -func (r *Renderer) ClientCreate(client *management.Client, revealSecrets bool) { - r.Heading(ansi.Bold(r.Tenant), "client created\n") +func (r *Renderer) ApplicationCreate(client *management.Client, revealSecrets bool) { + r.Heading(ansi.Bold(r.Tenant), "application created\n") // note(jfatta): list and create uses the same view for now, // eventually we might want to show different columns for each command: v := &clientView{ revealSecret: revealSecrets, Name: auth0.StringValue(client.Name), - Type: appTypeFor(client.AppType), + Type: typeFor(client.AppType), ClientID: auth0.StringValue(client.ClientID), ClientSecret: auth0.StringValue(client.ClientSecret), Callbacks: callbacksFor(client.Callbacks), @@ -91,10 +91,25 @@ func (r *Renderer) ClientCreate(client *management.Client, revealSecrets bool) { r.Infof("\nQuickstarts: %s", quickstartsURIFor(client.AppType)) } +func (r *Renderer) ApplicationUpdate(client *management.Client, revealSecrets bool) { + r.Heading(ansi.Bold(r.Tenant), "application updated\n") + + v := &clientView{ + revealSecret: revealSecrets, + Name: auth0.StringValue(client.Name), + Type: typeFor(client.AppType), + ClientID: auth0.StringValue(client.ClientID), + ClientSecret: auth0.StringValue(client.ClientSecret), + Callbacks: callbacksFor(client.Callbacks), + } + + r.Results([]View{v}) +} + // TODO(cyx): determine if there's a better way to filter this out. const deprecatedAppName = "All Applications" -func appTypeFor(v *string) string { +func typeFor(v *string) string { switch { case v == nil: return "generic" From 702f0bcad2385f59037a67402e5dbab3835dc78e Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 26 Feb 2021 13:19:21 -0300 Subject: [PATCH 5/8] Fix identifier name --- internal/cli/apps.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cli/apps.go b/internal/cli/apps.go index 33047e09f..86e43385e 100644 --- a/internal/cli/apps.go +++ b/internal/cli/apps.go @@ -268,7 +268,7 @@ auth0 apps update --id id --name myapp --type [native|spa|regular|m2m] } err := ansi.Spinner("Updating application", func() error { - return cli.api.Client.Update(flags.ID, c) + return cli.api.Client.Update(flags.ID, a) }) if err != nil { From 55c2bb02f05b9f8f497bf4015e44a57d13ac4ec1 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 26 Feb 2021 13:25:58 -0300 Subject: [PATCH 6/8] Fix command name --- internal/cli/apps.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cli/apps.go b/internal/cli/apps.go index 86e43385e..a69fe214a 100644 --- a/internal/cli/apps.go +++ b/internal/cli/apps.go @@ -209,7 +209,7 @@ func updateAppCmd(cli *cli) *cobra.Command { } cmd := &cobra.Command{ - Use: "create", + Use: "update", Short: "Update a new application", Long: `Update a new application: From a6d343096a60faf5f8e25acd8d07b23e8ca93762 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 26 Feb 2021 13:31:09 -0300 Subject: [PATCH 7/8] Fix test --- internal/cli/apps_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cli/apps_test.go b/internal/cli/apps_test.go index 9157c12f6..c0624d33e 100644 --- a/internal/cli/apps_test.go +++ b/internal/cli/apps_test.go @@ -42,7 +42,7 @@ func TestClientsListCmd(t *testing.T) { api: &auth0.API{Client: clientAPI}, } - cmd := appsListCmd(cli) + cmd := listAppsCmd(cli) if err := cmd.Execute(); err != nil { t.Fatal(err) From 47b56454d354f595b00548f00e3145c7b85324b1 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 26 Feb 2021 16:05:02 -0300 Subject: [PATCH 8/8] Rename typeFor to appTypeFor --- internal/display/clients.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/display/clients.go b/internal/display/clients.go index face736cd..ee20b36e3 100644 --- a/internal/display/clients.go +++ b/internal/display/clients.go @@ -62,7 +62,7 @@ func (r *Renderer) ApplicationList(clients []*management.Client) { } res = append(res, &clientView{ Name: auth0.StringValue(c.Name), - Type: typeFor(c.AppType), + Type: appTypeFor(c.AppType), ClientID: auth0.StringValue(c.ClientID), ClientSecret: auth0.StringValue(c.ClientSecret), Callbacks: callbacksFor(c.Callbacks), @@ -80,7 +80,7 @@ func (r *Renderer) ApplicationCreate(client *management.Client, revealSecrets bo v := &clientView{ revealSecret: revealSecrets, Name: auth0.StringValue(client.Name), - Type: typeFor(client.AppType), + Type: appTypeFor(client.AppType), ClientID: auth0.StringValue(client.ClientID), ClientSecret: auth0.StringValue(client.ClientSecret), Callbacks: callbacksFor(client.Callbacks), @@ -97,7 +97,7 @@ func (r *Renderer) ApplicationUpdate(client *management.Client, revealSecrets bo v := &clientView{ revealSecret: revealSecrets, Name: auth0.StringValue(client.Name), - Type: typeFor(client.AppType), + Type: appTypeFor(client.AppType), ClientID: auth0.StringValue(client.ClientID), ClientSecret: auth0.StringValue(client.ClientSecret), Callbacks: callbacksFor(client.Callbacks), @@ -109,7 +109,7 @@ func (r *Renderer) ApplicationUpdate(client *management.Client, revealSecrets bo // TODO(cyx): determine if there's a better way to filter this out. const deprecatedAppName = "All Applications" -func typeFor(v *string) string { +func appTypeFor(v *string) string { switch { case v == nil: return "generic"