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

feat: apis list #18

Merged
merged 5 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
deviceCodeEndpoint = "https://auth0.auth0.com/oauth/device/code"
oauthTokenEndpoint = "https://auth0.auth0.com/oauth/token"
// TODO(jfatta) extend the scope as we extend the CLI:
scope = "openid read:roles read:clients read:logs read:rules"
scope = "openid read:roles read:clients read:resource_servers read:logs read:rules"
audiencePath = "/api/v2/"
)

Expand Down
42 changes: 42 additions & 0 deletions internal/cli/apis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cli

import (
"github.com/spf13/cobra"
"gopkg.in/auth0.v5/management"
)

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(management.IncludeTotals(false))

if err != nil {
return err
}

cli.renderer.ApisList(list.ResourceServers)
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 @@ -52,6 +52,7 @@ func Execute() {

rootCmd.AddCommand(loginCmd(cli))
rootCmd.AddCommand(clientsCmd(cli))
rootCmd.AddCommand(apisCmd(cli))
rootCmd.AddCommand(logsCmd(cli))
rootCmd.AddCommand(rulesCmd(cli))

Expand Down
37 changes: 37 additions & 0 deletions internal/display/apis.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 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: appTypeFor(api.Name),
Identifier: auth0.StringValue(api.Identifier),
})
}

r.Results(res)
}