Skip to content

Commit

Permalink
v2: add support for listing all keys
Browse files Browse the repository at this point in the history
Updates tailscale/corp#22783

Signed-off-by: Percy Wegmann <[email protected]>
  • Loading branch information
oxtoacart committed Sep 16, 2024
1 parent e89a1ab commit 7465ac7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions v2/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ func (kr *KeysResource) Get(ctx context.Context, id string) (*Key, error) {

// List returns every [Key] within the tailnet. The only fields set for each [Key] will be its identifier.
// The keys returned are relative to the user that owns the API key used to authenticate the client.
func (kr *KeysResource) List(ctx context.Context) ([]Key, error) {
req, err := kr.buildRequest(ctx, http.MethodGet, kr.buildTailnetURL("keys"))
//
// Specify all to list both user and tailnet level keys.
func (kr *KeysResource) List(ctx context.Context, all bool) ([]Key, error) {
url := kr.buildTailnetURL("keys")
if all {
url.RawQuery = "all=true"
}
req, err := kr.buildRequest(ctx, http.MethodGet, url)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion v2/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestClient_Keys(t *testing.T) {
"keys": expected,
}

actual, err := client.Keys().List(context.Background())
actual, err := client.Keys().List(context.Background(), false)
assert.NoError(t, err)
assert.EqualValues(t, expected, actual)
assert.Equal(t, http.MethodGet, server.Method)
Expand Down

0 comments on commit 7465ac7

Please sign in to comment.