diff --git a/internal/auth/auth.go b/internal/auth/auth.go index 413f94654..cf100a3c3 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -33,7 +33,7 @@ const ( deviceCodeEndpoint = "https://auth0.auth0.com/oauth/device/code" oauthTokenEndpoint = "https://auth0.auth0.com/oauth/token" // TODO(jfatta) extend the scope as we extend the CLI: - scope = "openid create:actions create:clients create:resource_servers create:connections create:hooks create:rules delete:actions delete:clients delete:connections delete:hooks delete:rules read:actions read:clients read:resource_servers read:connections read:hooks read:logs read:rules update:actions update:clients update:connections update:hooks update:rules" + scope = "openid create:actions create:clients create:resource_servers create:connections create:hooks create:rules delete:actions delete:clients delete:connections delete:hooks delete:rules read:actions read:clients read:resource_servers read:connections read:hooks read:logs read:rules update:actions update:clients update:resource_servers update:connections update:hooks update:rules" audiencePath = "/api/v2/" ) diff --git a/internal/cli/apis.go b/internal/cli/apis.go index e06b3ea15..839a31819 100644 --- a/internal/cli/apis.go +++ b/internal/cli/apis.go @@ -15,6 +15,7 @@ func apisCmd(cli *cli) *cobra.Command { cmd.SetUsageTemplate(resourceUsageTemplate()) cmd.AddCommand(listApisCmd(cli)) cmd.AddCommand(createApiCmd(cli)) + cmd.AddCommand(updateApiCmd(cli)) return cmd } @@ -42,7 +43,7 @@ Lists your existing APIs. To create one try: return err } - cli.renderer.ApisList(list.ResourceServers) + cli.renderer.ApiList(list.ResourceServers) return nil }, } @@ -89,3 +90,41 @@ auth0 apis create --name myapi --identifier http://my-api return cmd } + +func updateApiCmd(cli *cli) *cobra.Command { + var flags struct { + id string + name string + } + + cmd := &cobra.Command{ + Use: "update", + Short: "Update an API", + Long: `Updates an API: + +auth0 apis update --id id --name myapi +`, + RunE: func(cmd *cobra.Command, args []string) error { + api := &management.ResourceServer{Name: &flags.name} + manager := &management.ResourceServerManager{Management: cli.api} + + err := ansi.Spinner("Updating API", func() error { + return manager.Update(flags.id, api) + }) + + if err != nil { + return err + } + + cli.renderer.ApiUpdate(api) + return nil + }, + } + + cmd.Flags().StringVarP(&flags.id, "id", "i", "", "ID of the API.") + cmd.Flags().StringVarP(&flags.name, "name", "n", "", "Name of the API.") + + mustRequireFlags(cmd, "id", "name") + + return cmd +} diff --git a/internal/display/apis.go b/internal/display/apis.go index 9d95ad424..10d4a31b2 100644 --- a/internal/display/apis.go +++ b/internal/display/apis.go @@ -20,17 +20,13 @@ func (v *apiView) AsTableRow() []string { return []string{ansi.Faint(v.ID), v.Name, v.Identifier} } -func (r *Renderer) ApisList(apis []*management.ResourceServer) { +func (r *Renderer) ApiList(apis []*management.ResourceServer) { r.Heading(ansi.Bold(r.Tenant), "APIs\n") var res []View for _, api := range apis { - res = append(res, &apiView{ - ID: auth0.StringValue(api.ID), - Name: auth0.StringValue(api.Name), - Identifier: auth0.StringValue(api.Identifier), - }) + res = append(res, makeView(api)) } r.Results(res) @@ -38,12 +34,18 @@ func (r *Renderer) ApisList(apis []*management.ResourceServer) { func (r *Renderer) ApiCreate(api *management.ResourceServer) { r.Heading(ansi.Bold(r.Tenant), "API created\n") + r.Results([]View{makeView(api)}) +} + +func (r *Renderer) ApiUpdate(api *management.ResourceServer) { + r.Heading(ansi.Bold(r.Tenant), "API updated\n") + r.Results([]View{makeView(api)}) +} - v := &apiView{ +func makeView(api *management.ResourceServer) *apiView { + return &apiView{ ID: auth0.StringValue(api.ID), Name: auth0.StringValue(api.Name), Identifier: auth0.StringValue(api.Identifier), } - - r.Results([]View{v}) }