Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rename
hydra clients list
command
Renames the command to `hydra list client` and changes CLI flags. BREAKING CHANGE: Command `hydra clients list` is now `hydra list client`. Please notice that the pagination flags have changed to `--page-token` and `page-size`!
- Loading branch information
Showing
29 changed files
with
718 additions
and
180 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 was deleted.
Oops, something went wrong.
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
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
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,20 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/ory/hydra/cmd/cliclient" | ||
"github.com/ory/x/cmdx" | ||
) | ||
|
||
func NewListCmd(root *cobra.Command) *cobra.Command { | ||
var cmd = &cobra.Command{ | ||
Use: "list", | ||
Aliases: []string{"ls"}, | ||
Short: "List resources", | ||
} | ||
cmd.AddCommand(NewListClientsCmd(root)) | ||
cliclient.RegisterClientFlags(cmd.PersistentFlags()) | ||
cmdx.RegisterFormatFlags(cmd.PersistentFlags()) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/ory/hydra/cmd/cliclient" | ||
"github.com/ory/x/cmdx" | ||
) | ||
|
||
func NewListClientsCmd(root *cobra.Command) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "clients", | ||
Short: "List OAuth 2.0 Clients", | ||
Long: `This command list an OAuth 2.0 Clients.`, | ||
Args: cobra.NoArgs, | ||
Example: fmt.Sprintf("%s ls identities --%s eyJwYWdlIjoxfQ --%s 10", root.Use, cmdx.FlagPageToken, cmdx.FlagPageSize), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
m, err := cliclient.NewClient(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
pageToken, pageSize, err := cmdx.ParseTokenPaginationArgs(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
list, resp, err := m.AdminApi.ListOAuth2Clients(cmd.Context()).PageSize(int64(pageSize)).PageToken(pageToken).Execute() | ||
if err != nil { | ||
return cmdx.PrintOpenAPIError(cmd, err) | ||
} | ||
|
||
var collection outputOAuth2ClientCollection | ||
for k := range list { | ||
collection.clients = append(collection.clients, list[k]) | ||
} | ||
|
||
interfaceList := make([]interface{}, len(list)) | ||
for k := range collection.clients { | ||
interfaceList[k] = interface{}(&list[k]) | ||
} | ||
|
||
result := &cmdx.PaginatedList{Items: interfaceList, Collection: collection} | ||
result.NextPageToken = getPageToken(resp) | ||
result.IsLastPage = result.NextPageToken == "" | ||
cmdx.PrintTable(cmd, result) | ||
return nil | ||
}, | ||
} | ||
cmdx.RegisterTokenPaginationFlags(cmd) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cmd_test | ||
|
||
import ( | ||
"github.com/ory/hydra/client" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/tidwall/gjson" | ||
|
||
"github.com/ory/hydra/cmd" | ||
"github.com/ory/x/cmdx" | ||
) | ||
|
||
func TestListClient(t *testing.T) { | ||
c := cmd.NewListClientsCmd(new(cobra.Command)) | ||
reg := setup(t, c) | ||
|
||
expected1 := createClient(t, reg, nil) | ||
expected2 := createClient(t, reg, nil) | ||
|
||
t.Run("case=lists both clients", func(t *testing.T) { | ||
actual := gjson.Parse(cmdx.ExecNoErr(t, c)) | ||
assert.Len(t, actual.Get("items").Array(), 2) | ||
|
||
for _, e := range []*client.Client{expected1, expected2} { | ||
assert.Contains(t, actual.Raw, e.GetID()) | ||
} | ||
}) | ||
|
||
t.Run("case=lists both clients with pagination", func(t *testing.T) { | ||
actualFirst := gjson.Parse(cmdx.ExecNoErr(t, c, "--format", "json", "--page-size", "1")) | ||
assert.Len(t, actualFirst.Get("items").Array(), 1) | ||
|
||
require.NotEmpty(t, actualFirst.Get("next_page_token").String(), actualFirst.Raw) | ||
assert.False(t, actualFirst.Get("is_last_page").Bool(), actualFirst.Raw) | ||
|
||
actualSecond := gjson.Parse(cmdx.ExecNoErr(t, c, "--format", "json", "--page-size", "1", "--page-token", actualFirst.Get("next_page_token").String())) | ||
assert.Len(t, actualSecond.Array(), 1) | ||
|
||
assert.NotEmpty(t, actualFirst.Get("items.0.client_id").String()) | ||
assert.NotEqualValues(t, actualFirst.Get("items.0.client_id").String(), actualSecond.Get("items.0.client_id").String()) | ||
}) | ||
} |
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
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
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
Oops, something went wrong.