Skip to content

Commit 81e55a7

Browse files
committed
Add GetClientKeys
1 parent 85f3897 commit 81e55a7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

keys.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ func (c *Client) UpdateClientKey(o Organization, p Project, k Key, name string)
5050
err := c.do("PUT", fmt.Sprintf("projects/%s/%s/keys/%s", *o.Slug, *p.Slug, k.ID), &key, &req)
5151
return key, err
5252
}
53+
54+
//GetClientKeys fetches all client keys of the given project
55+
func (c *Client) GetClientKeys(o Organization, p Project) ([]Key, error) {
56+
var keys []Key
57+
err := c.do("GET", fmt.Sprintf("projects/%s/%s/keys", *o.Slug, *p.Slug), &keys, nil)
58+
return keys, err
59+
}

keys_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ func TestKeysResource(t *testing.T) {
2727
if key.Label != "Test client key" {
2828
t.Error("Key does not have correct label")
2929
}
30+
t.Run("List client keys", func(t *testing.T) {
31+
keys, err := client.GetClientKeys(org, project)
32+
if err != nil {
33+
t.Error(err)
34+
}
35+
if len(keys) != 2 {
36+
t.Errorf("Expected 2 keys, got %d", len(keys))
37+
}
38+
})
3039
t.Run("Update name of client key", func(t *testing.T) {
3140

3241
key, err = client.UpdateClientKey(org, project, key, "This is a new name")

0 commit comments

Comments
 (0)