Skip to content

Commit

Permalink
Use domains for tenant name in config.json and for display (#241)
Browse files Browse the repository at this point in the history
* Use domains for tenant name in config.json and for display. Use first selection for `tenant use` if no selection is made.

* One last spot using name
  • Loading branch information
chrisscott authored Apr 9, 2021
1 parent d0c12b5 commit 6c80cc1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions internal/cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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)
Expand All @@ -44,7 +44,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 {
Expand Down
8 changes: 4 additions & 4 deletions internal/cli/tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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)
Expand Down Expand Up @@ -66,10 +66,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)
}
Expand All @@ -79,7 +79,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
Expand Down

0 comments on commit 6c80cc1

Please sign in to comment.