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

Use domains for tenant name in config.json and for display #241

Merged
merged 3 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
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 @@ -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)
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions internal/cli/tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks

if err := prompt.AskOne(input, &selectedTenant); err != nil {
return fmt.Errorf("An unexpected error occurred: %w", err)
}
Expand All @@ -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
Expand Down