Skip to content

Commit 22291b7

Browse files
authored
Merge branch 'main' into flags-poc
2 parents 6142d56 + a5ce24e commit 22291b7

File tree

8 files changed

+107
-21
lines changed

8 files changed

+107
-21
lines changed

.goreleaser.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ builds:
1010
- linux
1111
- windows
1212
binary: auth0
13+
ldflags:
14+
- -X github.com/auth0/auth0-cli/internal/buildinfo.Version={{.Version}}
15+
- -X github.com/auth0/auth0-cli/internal/buildinfo.Revision={{.Commit}}
16+
- -X github.com/auth0/auth0-cli/internal/buildinfo.BuildUser=goreleaser'
17+
- -X github.com/auth0/auth0-cli/internal/buildinfo.BuildDate={{.Date}}'
1318
archives:
1419
- replacements:
1520
darwin: Darwin

internal/auth/secrets_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package auth
2+
3+
import (
4+
"testing"
5+
6+
"github.com/zalando/go-keyring"
7+
)
8+
9+
func TestSecrets(t *testing.T) {
10+
t.Run("fail: not found", func(t *testing.T) {
11+
// init underlying keychain manager
12+
keyring.MockInit()
13+
14+
kr := &Keyring{}
15+
_, err := kr.Get("mynamespace", "foo")
16+
17+
if got, want := err, keyring.ErrNotFound; got != want {
18+
t.Fatalf("wanted error: %v, got: %v", want, got)
19+
}
20+
})
21+
22+
t.Run("succeed: get secret", func(t *testing.T) {
23+
// init underlying keychain manager
24+
keyring.MockInit()
25+
26+
// set with the underlying manager:
27+
err := keyring.Set("mynamespace", "foo", "bar")
28+
if err != nil {
29+
t.Fatal(err)
30+
}
31+
32+
kr := &Keyring{}
33+
v, err := kr.Get("mynamespace", "foo")
34+
if err != nil {
35+
t.Fatal(err)
36+
}
37+
38+
if got, want := v, "bar"; got != want {
39+
t.Fatalf("wanted error: %v, got: %v", want, got)
40+
}
41+
})
42+
43+
t.Run("succeed: set secret", func(t *testing.T) {
44+
// init underlying keychain manager
45+
keyring.MockInit()
46+
47+
kr := &Keyring{}
48+
err := kr.Set("mynamespace", "foo", "bar")
49+
if err != nil {
50+
t.Fatal(err)
51+
}
52+
53+
// get with the underlying manager:
54+
v, err := keyring.Get("mynamespace", "foo")
55+
if err != nil {
56+
t.Fatal(err)
57+
}
58+
59+
if got, want := v, "bar"; got != want {
60+
t.Fatalf("wanted secret: %v, got: %v", want, got)
61+
}
62+
})
63+
}
File renamed without changes.

internal/cli/apps.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ auth0 apps show <id>
109109
RunE: func(cmd *cobra.Command, args []string) error {
110110
if len(args) == 0 {
111111
if canPrompt(cmd) {
112-
input := prompt.TextInput(appID, "Id:", "Id of the application.", true)
112+
input := prompt.TextInput(appID, "Client Id:", "Id of the application.", true)
113113

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

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

323323
if err := prompt.AskOne(input, &inputs); err != nil {
324324
return fmt.Errorf("An unexpected error occurred: %w", err)

internal/cli/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/auth0/auth0-cli/internal/ansi"
1818
"github.com/auth0/auth0-cli/internal/auth"
1919
"github.com/auth0/auth0-cli/internal/auth0"
20-
"github.com/auth0/auth0-cli/internal/build-info"
20+
"github.com/auth0/auth0-cli/internal/buildinfo"
2121
"github.com/auth0/auth0-cli/internal/display"
2222
"github.com/lestrrat-go/jwx/jwt"
2323
"github.com/spf13/cobra"

internal/cli/logs.go

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"gopkg.in/auth0.v5/management"
1111
)
1212

13-
func getLatestLogs(cli *cli, n int) ([]*management.Log, error) {
13+
func getLatestLogs(cli *cli, n int, clientID string) ([]*management.Log, error) {
1414
page := 0
1515
perPage := n
1616

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

23-
return cli.api.Log.List(
23+
queryParams := []management.RequestOption{
2424
management.Parameter("sort", "date:-1"),
2525
management.Parameter("page", fmt.Sprintf("%d", page)),
26-
management.Parameter("per_page", fmt.Sprintf("%d", perPage)),
27-
)
26+
management.Parameter("per_page", fmt.Sprintf("%d", perPage))}
27+
28+
if clientID != "" {
29+
queryParams = append(queryParams, management.Query(fmt.Sprintf(`client_id:"%s"`, clientID)))
30+
}
31+
32+
return cli.api.Log.List(queryParams...)
2833
}
2934

3035
func logsCmd(cli *cli) *cobra.Command {
@@ -34,15 +39,25 @@ func logsCmd(cli *cli) *cobra.Command {
3439
NoColor bool
3540
}
3641

42+
var inputs struct {
43+
ClientID string
44+
}
45+
3746
cmd := &cobra.Command{
38-
Use: "logs",
47+
Use: "logs [client-id]",
48+
Args: cobra.MaximumNArgs(1),
3949
Short: "Show the tenant logs",
40-
Long: `auth0 logs
41-
Show the tenant logs.
50+
Long: `Show the tenant logs:
51+
52+
auth0 logs [client-id]
4253
`,
4354
RunE: func(cmd *cobra.Command, args []string) error {
55+
inputs.ClientID = ""
56+
if len(args) == 1 {
57+
inputs.ClientID = args[0]
58+
}
4459
lastLogID := ""
45-
list, err := getLatestLogs(cli, flags.Num)
60+
list, err := getLatestLogs(cli, flags.Num, inputs.ClientID)
4661
if err != nil {
4762
return fmt.Errorf("An unexpected error occurred while getting logs: %v", err)
4863
}
@@ -68,12 +83,18 @@ Show the tenant logs.
6883
defer close(logsCh)
6984

7085
for {
71-
list, err = cli.api.Log.List(
86+
queryParams := []management.RequestOption{
7287
management.Query(fmt.Sprintf("log_id:[%s TO *]", lastLogID)),
7388
management.Parameter("page", "0"),
7489
management.Parameter("per_page", "100"),
7590
management.Parameter("sort", "date:-1"),
76-
)
91+
}
92+
93+
if inputs.ClientID != "" {
94+
queryParams = append(queryParams, management.Query(fmt.Sprintf(`client_id:"%s"`, inputs.ClientID)))
95+
}
96+
97+
list, err = cli.api.Log.List(queryParams...)
7798
if err != nil {
7899
cli.renderer.Errorf("An unexpected error occurred while getting logs: %v", err)
79100
return

internal/cli/root.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package cli
22

33
import (
44
"context"
5+
"os"
6+
57
"github.com/auth0/auth0-cli/internal/ansi"
6-
"github.com/auth0/auth0-cli/internal/build-info"
8+
"github.com/auth0/auth0-cli/internal/buildinfo"
79
"github.com/auth0/auth0-cli/internal/display"
810
"github.com/spf13/cobra"
9-
"os"
1011
)
1112

1213
// Execute is the primary entrypoint of the CLI app.

internal/display/display.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,7 @@ func (r *Renderer) Result(data View) {
113113
for _, pair := range v.KeyValues() {
114114
k := pair[0]
115115
v := pair[1]
116-
117-
// NOTE(cyx): We can either nuke it or annotate with `<none>`. For now we're choosing to nuke it.
118-
if v != "" {
119-
kvs = append(kvs, []string{k, v})
120-
}
116+
kvs = append(kvs, []string{k, v})
121117
}
122118
writeTable(r.ResultWriter, nil, kvs)
123119
}

0 commit comments

Comments
 (0)