diff --git a/internal/cli/apis.go b/internal/cli/apis.go new file mode 100644 index 000000000..ea51856a6 --- /dev/null +++ b/internal/cli/apis.go @@ -0,0 +1,41 @@ +package cli + +import ( + "github.com/spf13/cobra" +) + +func apisCmd(cli *cli) *cobra.Command { + cmd := &cobra.Command{ + Use: "apis", + Short: "manage resources for APIs.", + } + + cmd.SetUsageTemplate(resourceUsageTemplate()) + cmd.AddCommand(listApisCmd(cli)) + + return cmd +} + +func listApisCmd(cli *cli) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Short: "Lists your existing APIs", + Long: `$ auth0 apis list +Lists your existing APIs. To create one try: + + $ auth0 apis create +`, + RunE: func(cmd *cobra.Command, args []string) error { + list, err := cli.api.ResourceServer.List() + + if err != nil { + return err + } + + cli.renderer.ApisList(list.ResourceServers) + return nil + }, + } + + return cmd +} diff --git a/internal/cli/root.go b/internal/cli/root.go index cd6949050..73ef279b2 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -52,6 +52,7 @@ func Execute() { rootCmd.AddCommand(loginCmd(cli)) rootCmd.AddCommand(clientsCmd(cli)) + rootCmd.AddCommand(apisCmd(cli)) rootCmd.AddCommand(logsCmd(cli)) rootCmd.AddCommand(actionsCmd(cli)) rootCmd.AddCommand(rulesCmd(cli)) diff --git a/internal/display/apis.go b/internal/display/apis.go new file mode 100644 index 000000000..208db8ecc --- /dev/null +++ b/internal/display/apis.go @@ -0,0 +1,37 @@ +package display + +import ( + "github.com/auth0/auth0-cli/internal/ansi" + "gopkg.in/auth0.v5" + "gopkg.in/auth0.v5/management" +) + +type apiView struct { + ID string + Name string + Identifier string +} + +func (v *apiView) AsTableHeader() []string { + return []string{"ID", "Name", "Identifier"} +} + +func (v *apiView) AsTableRow() []string { + return []string{ansi.Faint(v.ID), v.Name, v.Identifier} +} + +func (r *Renderer) ApisList(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), + }) + } + + r.Results(res) +}