-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from auth0/add-client-list-cmd
Add client list command
- Loading branch information
Showing
4 changed files
with
90 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func clientsCmd(cli *cli) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "clients", | ||
Short: "manage resources for clients.", | ||
} | ||
|
||
cmd.SetUsageTemplate(resourceUsageTemplate()) | ||
cmd.AddCommand(listClientsCmd(cli)) | ||
|
||
return cmd | ||
} | ||
|
||
func listClientsCmd(cli *cli) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "list", | ||
Short: "Lists your existing clients", | ||
Long: `$ auth0 client list | ||
Lists your existing clients. To create one try: | ||
$ auth0 clients create | ||
`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
list, err := cli.api.Client.List() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cli.renderer.ClientList(list.Clients) | ||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package display | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/auth0/auth0-cli/internal/ansi" | ||
"gopkg.in/auth0.v5" | ||
"gopkg.in/auth0.v5/management" | ||
) | ||
|
||
func (r *Renderer) ClientList(clients []*management.Client) { | ||
r.Heading(ansi.Bold(r.Tenant), "clients") | ||
|
||
for _, c := range clients { | ||
if auth0.StringValue(c.Name) == deprecatedAppName { | ||
continue | ||
} | ||
|
||
fmt.Fprintf(r.Writer, "- %s (%s)\n", auth0.StringValue(c.Name), appTypeFor(c.AppType)) | ||
fmt.Fprintf(r.Writer, " client id: %s\n", ansi.Faint(auth0.StringValue(c.ClientID))) | ||
fmt.Fprintln(r.Writer) | ||
} | ||
} | ||
|
||
// TODO(cyx): determine if there's a better way to filter this out. | ||
const deprecatedAppName = "All Applications" | ||
|
||
func appTypeFor(v *string) string { | ||
switch { | ||
case v == nil: | ||
return "generic" | ||
|
||
case *v == "non_interactive": | ||
return "machine to machine" | ||
|
||
case *v == "native": | ||
return "native" | ||
|
||
case *v == "spa": | ||
return "single page application" | ||
|
||
case *v == "regular_web": | ||
return "regular web application" | ||
|
||
default: | ||
return *v | ||
} | ||
} |