Skip to content

Commit

Permalink
Merge branch 'main' into flags-poc
Browse files Browse the repository at this point in the history
  • Loading branch information
Widcket authored Mar 12, 2021
2 parents 6142d56 + a5ce24e commit 22291b7
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ builds:
- linux
- windows
binary: auth0
ldflags:
- -X github.com/auth0/auth0-cli/internal/buildinfo.Version={{.Version}}
- -X github.com/auth0/auth0-cli/internal/buildinfo.Revision={{.Commit}}
- -X github.com/auth0/auth0-cli/internal/buildinfo.BuildUser=goreleaser'
- -X github.com/auth0/auth0-cli/internal/buildinfo.BuildDate={{.Date}}'
archives:
- replacements:
darwin: Darwin
Expand Down
63 changes: 63 additions & 0 deletions internal/auth/secrets_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package auth

import (
"testing"

"github.com/zalando/go-keyring"
)

func TestSecrets(t *testing.T) {
t.Run("fail: not found", func(t *testing.T) {
// init underlying keychain manager
keyring.MockInit()

kr := &Keyring{}
_, err := kr.Get("mynamespace", "foo")

if got, want := err, keyring.ErrNotFound; got != want {
t.Fatalf("wanted error: %v, got: %v", want, got)
}
})

t.Run("succeed: get secret", func(t *testing.T) {
// init underlying keychain manager
keyring.MockInit()

// set with the underlying manager:
err := keyring.Set("mynamespace", "foo", "bar")
if err != nil {
t.Fatal(err)
}

kr := &Keyring{}
v, err := kr.Get("mynamespace", "foo")
if err != nil {
t.Fatal(err)
}

if got, want := v, "bar"; got != want {
t.Fatalf("wanted error: %v, got: %v", want, got)
}
})

t.Run("succeed: set secret", func(t *testing.T) {
// init underlying keychain manager
keyring.MockInit()

kr := &Keyring{}
err := kr.Set("mynamespace", "foo", "bar")
if err != nil {
t.Fatal(err)
}

// get with the underlying manager:
v, err := keyring.Get("mynamespace", "foo")
if err != nil {
t.Fatal(err)
}

if got, want := v, "bar"; got != want {
t.Fatalf("wanted secret: %v, got: %v", want, got)
}
})
}
File renamed without changes.
6 changes: 3 additions & 3 deletions internal/cli/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ auth0 apps show <id>
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
if canPrompt(cmd) {
input := prompt.TextInput(appID, "Id:", "Id of the application.", true)
input := prompt.TextInput(appID, "Client Id:", "Id of the application.", true)

if err := prompt.AskOne(input, &inputs); err != nil {
return fmt.Errorf("An unexpected error occurred: %w", err)
Expand Down Expand Up @@ -161,7 +161,7 @@ auth0 apps delete <id>
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
if canPrompt(cmd) {
input := prompt.TextInput(appID, "Id:", "Id of the application.", true)
input := prompt.TextInput(appID, "Client Id:", "Id of the application.", true)

if err := prompt.AskOne(input, &inputs); err != nil {
return fmt.Errorf("An unexpected error occurred: %w", err)
Expand Down Expand Up @@ -318,7 +318,7 @@ auth0 apps update <id> --name myapp --type [native|spa|regular|m2m]
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
if canPrompt(cmd) {
input := prompt.TextInput(appID, "Id:", "Id of the application.", true)
input := prompt.TextInput(appID, "Client Id:", "Id of the application.", true)

if err := prompt.AskOne(input, &inputs); err != nil {
return fmt.Errorf("An unexpected error occurred: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/auth0/auth0-cli/internal/ansi"
"github.com/auth0/auth0-cli/internal/auth"
"github.com/auth0/auth0-cli/internal/auth0"
"github.com/auth0/auth0-cli/internal/build-info"
"github.com/auth0/auth0-cli/internal/buildinfo"
"github.com/auth0/auth0-cli/internal/display"
"github.com/lestrrat-go/jwx/jwt"
"github.com/spf13/cobra"
Expand Down
41 changes: 31 additions & 10 deletions internal/cli/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"gopkg.in/auth0.v5/management"
)

func getLatestLogs(cli *cli, n int) ([]*management.Log, error) {
func getLatestLogs(cli *cli, n int, clientID string) ([]*management.Log, error) {
page := 0
perPage := n

Expand All @@ -20,11 +20,16 @@ func getLatestLogs(cli *cli, n int) ([]*management.Log, error) {
perPage = 1000
}

return cli.api.Log.List(
queryParams := []management.RequestOption{
management.Parameter("sort", "date:-1"),
management.Parameter("page", fmt.Sprintf("%d", page)),
management.Parameter("per_page", fmt.Sprintf("%d", perPage)),
)
management.Parameter("per_page", fmt.Sprintf("%d", perPage))}

if clientID != "" {
queryParams = append(queryParams, management.Query(fmt.Sprintf(`client_id:"%s"`, clientID)))
}

return cli.api.Log.List(queryParams...)
}

func logsCmd(cli *cli) *cobra.Command {
Expand All @@ -34,15 +39,25 @@ func logsCmd(cli *cli) *cobra.Command {
NoColor bool
}

var inputs struct {
ClientID string
}

cmd := &cobra.Command{
Use: "logs",
Use: "logs [client-id]",
Args: cobra.MaximumNArgs(1),
Short: "Show the tenant logs",
Long: `auth0 logs
Show the tenant logs.
Long: `Show the tenant logs:
auth0 logs [client-id]
`,
RunE: func(cmd *cobra.Command, args []string) error {
inputs.ClientID = ""
if len(args) == 1 {
inputs.ClientID = args[0]
}
lastLogID := ""
list, err := getLatestLogs(cli, flags.Num)
list, err := getLatestLogs(cli, flags.Num, inputs.ClientID)
if err != nil {
return fmt.Errorf("An unexpected error occurred while getting logs: %v", err)
}
Expand All @@ -68,12 +83,18 @@ Show the tenant logs.
defer close(logsCh)

for {
list, err = cli.api.Log.List(
queryParams := []management.RequestOption{
management.Query(fmt.Sprintf("log_id:[%s TO *]", lastLogID)),
management.Parameter("page", "0"),
management.Parameter("per_page", "100"),
management.Parameter("sort", "date:-1"),
)
}

if inputs.ClientID != "" {
queryParams = append(queryParams, management.Query(fmt.Sprintf(`client_id:"%s"`, inputs.ClientID)))
}

list, err = cli.api.Log.List(queryParams...)
if err != nil {
cli.renderer.Errorf("An unexpected error occurred while getting logs: %v", err)
return
Expand Down
5 changes: 3 additions & 2 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package cli

import (
"context"
"os"

"github.com/auth0/auth0-cli/internal/ansi"
"github.com/auth0/auth0-cli/internal/build-info"
"github.com/auth0/auth0-cli/internal/buildinfo"
"github.com/auth0/auth0-cli/internal/display"
"github.com/spf13/cobra"
"os"
)

// Execute is the primary entrypoint of the CLI app.
Expand Down
6 changes: 1 addition & 5 deletions internal/display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,7 @@ func (r *Renderer) Result(data View) {
for _, pair := range v.KeyValues() {
k := pair[0]
v := pair[1]

// NOTE(cyx): We can either nuke it or annotate with `<none>`. For now we're choosing to nuke it.
if v != "" {
kvs = append(kvs, []string{k, v})
}
kvs = append(kvs, []string{k, v})
}
writeTable(r.ResultWriter, nil, kvs)
}
Expand Down

0 comments on commit 22291b7

Please sign in to comment.