From f66171178dcc87ac46859028bf8374e3a2e35c21 Mon Sep 17 00:00:00 2001 From: Chris Scott Date: Fri, 9 Apr 2021 15:08:50 -0400 Subject: [PATCH 1/2] Use domains for tenant name in config.json and for display. Use first selection for `tenant use` if no selection is made. --- internal/cli/cli.go | 8 ++++---- internal/cli/login.go | 10 +++++----- internal/cli/logout.go | 4 ++-- internal/cli/tenants.go | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/internal/cli/cli.go b/internal/cli/cli.go index b01ffc500..a558b2b20 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -222,7 +222,7 @@ func (c *cli) addTenant(ten tenant) error { // If there's no existing DefaultTenant yet, might as well set the // first successfully logged in tenant during onboarding. if c.config.DefaultTenant == "" { - c.config.DefaultTenant = ten.Name + c.config.DefaultTenant = ten.Domain } // If we're dealing with an empty file, we'll need to initialize this @@ -231,7 +231,7 @@ func (c *cli) addTenant(ten tenant) error { c.config.Tenants = map[string]tenant{} } - c.config.Tenants[ten.Name] = ten + c.config.Tenants[ten.Domain] = ten if err := c.persistConfig(); err != nil { return fmt.Errorf("unexpected error persisting config: %w", err) @@ -305,7 +305,7 @@ func (c *cli) setDefaultAppID(id string) error { tenant.DefaultAppID = id - c.config.Tenants[tenant.Name] = tenant + c.config.Tenants[tenant.Domain] = tenant if err := c.persistConfig(); err != nil { return fmt.Errorf("Unexpected error persisting config: %w", err) } @@ -333,7 +333,7 @@ func (c *cli) setFirstCommandRun(clientID string, command string) error { } } - c.config.Tenants[tenant.Name] = tenant + c.config.Tenants[tenant.Domain] = tenant if err := c.persistConfig(); err != nil { return fmt.Errorf("Unexpected error persisting config: %w", err) diff --git a/internal/cli/login.go b/internal/cli/login.go index 80f682974..7081902c3 100644 --- a/internal/cli/login.go +++ b/internal/cli/login.go @@ -62,11 +62,11 @@ func RunLogin(ctx context.Context, cli *cli, expired bool) error { } cli.renderer.Infof("Successfully logged in.") - cli.renderer.Infof("Tenant: %s\n", res.Tenant) + cli.renderer.Infof("Tenant: %s\n", res.Domain) // store the refresh token secretsStore := &auth.Keyring{} - err = secretsStore.Set(auth.SecretsNamespace, res.Tenant, res.RefreshToken) + err = secretsStore.Set(auth.SecretsNamespace, res.Domain, res.RefreshToken) if err != nil { // log the error but move on cli.renderer.Warnf("Could not store the refresh token locally, please expect to login again once your access token expired. See https://github.com/auth0/auth0-cli/blob/main/KNOWN-ISSUES.md.") @@ -84,12 +84,12 @@ func RunLogin(ctx context.Context, cli *cli, expired bool) error { return fmt.Errorf("Unexpected error adding tenant to config: %w", err) } - if cli.config.DefaultTenant != res.Tenant { - promptText := fmt.Sprintf("Your default tenant is %s. Do you want to change it to %s?", cli.config.DefaultTenant, res.Tenant) + if cli.config.DefaultTenant != res.Domain { + promptText := fmt.Sprintf("Your default tenant is %s. Do you want to change it to %s?", cli.config.DefaultTenant, res.Domain) if confirmed := prompt.Confirm(promptText); !confirmed { return nil } - cli.config.DefaultTenant = res.Tenant + cli.config.DefaultTenant = res.Domain if err := cli.persistConfig(); err != nil { return fmt.Errorf("An error occurred while setting the default tenant: %w", err) } diff --git a/internal/cli/logout.go b/internal/cli/logout.go index 7fb476220..5eb082192 100644 --- a/internal/cli/logout.go +++ b/internal/cli/logout.go @@ -30,7 +30,7 @@ func logoutCmd(cli *cli) *cobra.Command { tenNames := make([]string, len(tens)) for i, t := range tens { - tenNames[i] = t.Name + tenNames[i] = t.Domain } input := prompt.SelectInput("tenant", "Tenant:", "Tenant to logout", tenNames, tenNames[0], true) @@ -43,7 +43,7 @@ func logoutCmd(cli *cli) *cobra.Command { if !ok { return fmt.Errorf("Unable to find tenant %s; run 'auth0 tenants use' to see your configured tenants or run 'auth0 login' to configure a new tenant", requestedTenant) } - selectedTenant = t.Name + selectedTenant = t.Domain } if err := cli.removeTenant(selectedTenant); err != nil { diff --git a/internal/cli/tenants.go b/internal/cli/tenants.go index 6103e202a..1eacd9c92 100644 --- a/internal/cli/tenants.go +++ b/internal/cli/tenants.go @@ -34,7 +34,7 @@ func listTenantCmd(cli *cli) *cobra.Command { tenNames := make([]string, len(tens)) for i, t := range tens { - tenNames[i] = t.Name + tenNames[i] = t.Domain } cli.renderer.ShowTenants(tenNames) @@ -63,10 +63,10 @@ func useTenantCmd(cli *cli) *cobra.Command { tenNames := make([]string, len(tens)) for i, t := range tens { - tenNames[i] = t.Name + tenNames[i] = t.Domain } - input := prompt.SelectInput("tenant", "Tenant:", "Tenant to activate", tenNames, "", true) + input := prompt.SelectInput("tenant", "Tenant:", "Tenant to activate", tenNames, tenNames[0], true) if err := prompt.AskOne(input, &selectedTenant); err != nil { return fmt.Errorf("An unexpected error occurred: %w", err) } @@ -76,7 +76,7 @@ func useTenantCmd(cli *cli) *cobra.Command { if !ok { return fmt.Errorf("Unable to find tenant %s; run 'auth0 tenants use' to see your configured tenants or run 'auth0 login' to configure a new tenant", requestedTenant) } - selectedTenant = t.Name + selectedTenant = t.Domain } cli.config.DefaultTenant = selectedTenant From fb31b03c8042928f328f0c13ed47f59d627353c6 Mon Sep 17 00:00:00 2001 From: Chris Scott Date: Fri, 9 Apr 2021 16:12:51 -0400 Subject: [PATCH 2/2] One last spot using name --- internal/cli/cli.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cli/cli.go b/internal/cli/cli.go index a558b2b20..3c3186a18 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -137,7 +137,7 @@ func (c *cli) setup(ctx context.Context) error { Client: http.DefaultClient, } - res, err := tr.Refresh(ctx, t.Name) + res, err := tr.Refresh(ctx, t.Domain) if err != nil { // ask and guide the user through the login process: c.renderer.Errorf("failed to renew access token, %s", err)