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

[A0CLI-24] Add connections list command #26

Merged
merged 3 commits into from
Jan 25, 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
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"}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be Connection ID?

}

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)
}