Skip to content

Commit

Permalink
Add connections and connections list.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisscott committed Jan 25, 2021
1 parent e605506 commit 16400bd
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
40 changes: 40 additions & 0 deletions internal/cli/connections.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
37 changes: 37 additions & 0 deletions internal/display/connections.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 16400bd

Please sign in to comment.