diff --git a/internal/cli/connections.go b/internal/cli/connections.go new file mode 100644 index 000000000..6090c3838 --- /dev/null +++ b/internal/cli/connections.go @@ -0,0 +1,40 @@ +package cli + +import ( + "github.com/spf13/cobra" +) + +func connectionsCmd(cli *cli) *cobra.Command { + cmd := &cobra.Command{ + Use: "connections", + Short: "manage resources for connections.", + } + + cmd.SetUsageTemplate(resourceUsageTemplate()) + cmd.AddCommand(listConnectionsCmd(cli)) + + return cmd +} + +func listConnectionsCmd(cli *cli) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Short: "Lists your existing connections", + Long: `$ auth0 connections list +Lists your existing connections. To create one try: + + $ auth0 connections create +`, + RunE: func(cmd *cobra.Command, args []string) error { + list, err := cli.api.Connection.List() + if err != nil { + return err + } + + cli.renderer.ConnectionList(list.Connections) + return nil + }, + } + + return cmd +} diff --git a/internal/cli/root.go b/internal/cli/root.go index 73ef279b2..5e7bd5b47 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -56,6 +56,7 @@ func Execute() { rootCmd.AddCommand(logsCmd(cli)) rootCmd.AddCommand(actionsCmd(cli)) rootCmd.AddCommand(rulesCmd(cli)) + rootCmd.AddCommand(connectionsCmd(cli)) // TODO(cyx): backport this later on using latest auth0/v5. // rootCmd.AddCommand(actionsCmd(cli)) diff --git a/internal/display/connections.go b/internal/display/connections.go new file mode 100644 index 000000000..6e80bc45c --- /dev/null +++ b/internal/display/connections.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 connectionView struct { + Name string + Strategy string + ConnectionID string +} + +func (v *connectionView) AsTableHeader() []string { + return []string{"Name", "Type", "ClientID"} +} + +func (v *connectionView) AsTableRow() []string { + return []string{v.Name, v.Strategy, ansi.Faint(v.ConnectionID)} +} + +func (r *Renderer) ConnectionList(connections []*management.Connection) { + r.Heading(ansi.Bold(r.Tenant), "connections\n") + + var res []View + for _, c := range connections { + res = append(res, &connectionView{ + Name: auth0.StringValue(c.Name), + Strategy: auth0.StringValue(c.Strategy), + ConnectionID: auth0.StringValue(c.ID), + }) + + } + + r.Results(res) +}