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

CLI-18: Error messages for tenants and apis commands #118

Merged
merged 3 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
43 changes: 24 additions & 19 deletions internal/cli/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"errors"
"fmt"
"strings"

"github.com/auth0/auth0-cli/internal/ansi"
Expand Down Expand Up @@ -66,7 +67,7 @@ Lists your existing APIs. To create one try:
})

if err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}

cli.renderer.ApiList(list.ResourceServers)
Expand Down Expand Up @@ -99,10 +100,10 @@ auth0 apis show <id>
input := prompt.TextInput(apiID, "Id:", "Id of the API.", true)

if err := prompt.AskOne(input, &inputs); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
} else {
return errors.New("missing API id")
return errors.New("Please include an API id")
}
} else {
inputs.ID = args[0]
Expand All @@ -117,7 +118,7 @@ auth0 apis show <id>
})

if err != nil {
return err
return fmt.Errorf("Unable to get an API with id %s: %w", inputs.ID, err)
}

cli.renderer.ApiShow(api)
Expand Down Expand Up @@ -153,7 +154,7 @@ auth0 apis create --name myapi --identifier http://my-api
true)

if err := prompt.AskOne(input, &flags); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
}

Expand All @@ -164,15 +165,15 @@ auth0 apis create --name myapi --identifier http://my-api
true)

if err := prompt.AskOne(input, &flags); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
}

if shouldPrompt(cmd, apiScopes) {
input := prompt.TextInput(apiScopes, "Scopes:", "Space-separated list of scopes.", false)

if err := prompt.AskOne(input, &flags); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
}

Expand All @@ -190,7 +191,7 @@ auth0 apis create --name myapi --identifier http://my-api
})

if err != nil {
return err
return fmt.Errorf("An unexpected error occurred while attempting to create an API with name %s and identifier %s : %w", flags.Name, flags.Identifier, err)
}

cli.renderer.ApiCreate(api)
Expand Down Expand Up @@ -230,10 +231,10 @@ auth0 apis update <id> --name myapi
input := prompt.TextInput(apiID, "Id:", "Id of the API.", true)

if err := prompt.AskOne(input, &inputs); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
} else {
return errors.New("missing API id")
return errors.New("Please include an API id")
}
} else {
inputs.ID = args[0]
Expand All @@ -243,15 +244,15 @@ auth0 apis update <id> --name myapi
input := prompt.TextInput(apiName, "Name:", "Name of the API.", true)

if err := prompt.AskOne(input, &inputs); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
}

if shouldPrompt(cmd, apiScopes) {
input := prompt.TextInput(apiScopes, "Scopes:", "Space-separated list of scopes.", false)

if err := prompt.AskOne(input, &inputs); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
}

Expand All @@ -266,7 +267,7 @@ auth0 apis update <id> --name myapi
})

if err != nil {
return err
return fmt.Errorf("An unexpected error occurred while trying to update an API with id %s: %w", inputs.ID, err)
}

cli.renderer.ApiUpdate(api)
Expand Down Expand Up @@ -302,10 +303,10 @@ auth0 apis delete <id>
input := prompt.TextInput(apiID, "Id:", "Id of the API.", true)

if err := prompt.AskOne(input, &inputs); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
} else {
return errors.New("missing API id")
return errors.New("Please include an API id")
}
} else {
inputs.ID = args[0]
Expand All @@ -318,7 +319,11 @@ auth0 apis delete <id>
}

return ansi.Spinner("Deleting API", func() error {
return cli.api.ResourceServer.Delete(inputs.ID)
err := cli.api.ResourceServer.Delete(inputs.ID)
if err != nil {
return fmt.Errorf("An unexpected error occurred while attempting to delete an API with id %s: %w", inputs.ID, err)
}
return nil
})
},
}
Expand Down Expand Up @@ -348,10 +353,10 @@ auth0 apis scopes list <id>
input := prompt.TextInput(apiID, "Id:", "Id of the API.", true)

if err := prompt.AskOne(input, &inputs); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
} else {
return errors.New("missing API id")
return errors.New("Please include an API id")
}
} else {
inputs.ID = args[0]
Expand All @@ -366,7 +371,7 @@ auth0 apis scopes list <id>
})

if err != nil {
return err
return fmt.Errorf("An unexpected error occurred while getting scopes for an API with id %s: %w", inputs.ID, err)
}

cli.renderer.ScopesList(api.GetName(), api.Scopes)
Expand Down
9 changes: 4 additions & 5 deletions internal/cli/tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func useTenantCmd(cli *cli) *cobra.Command {
if len(args) == 0 {
tens, err := cli.listTenants()
if err != nil {
return fmt.Errorf("unable to load tenants from config")
return fmt.Errorf("Unable to load tenants due to an unexpected error: %w", err)
}

tenNames := make([]string, len(tens))
Expand All @@ -42,21 +42,20 @@ func useTenantCmd(cli *cli) *cobra.Command {

input := prompt.SelectInput("tenant", "Tenant:", "Tenant to activate", tenNames, true)
if err := prompt.AskOne(input, &selectedTenant); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
} else {
requestedTenant := args[0]
t, ok := cli.config.Tenants[requestedTenant]
if !ok {
return fmt.Errorf("Unable to find tenant in config: %s", requestedTenant)

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
}

cli.config.DefaultTenant = selectedTenant
if err := cli.persistConfig(); err != nil {
return fmt.Errorf("persisting config: %w", err)
return fmt.Errorf("An error occurred while setting the default tenant: %w", err)
}
return nil
},
Expand Down