Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ type DSN struct {

// Key is a DSN that sentry has made
type Key struct {
ID string `json:"id,omitempty"`
Label string `json:"label,omitempty"`
Name string `json:"name,omitempty"`
DSN DSN `json:"dsn,omitempty"`
Secret string `json:"secret,omitempty"`
ID string `json:"id,omitempty"`
DateCreated time.Time `json:"dateCreated,omitempty"`
Public string `json:"public,omitempty"`
RateLimit *KeyRateLimit `json:"rateLimit,omitempty"`
Expand Down Expand Up @@ -58,6 +59,13 @@ func (c *Client) UpdateClientKey(o Organization, p Project, k Key, name string)
return key, err
}

// GetClientKey fetches a client key of the given project, org and key ID
func (c *Client) GetClientKey(o Organization, p Project, keyId string) (Key, error) {
var key Key
err := c.do("GET", fmt.Sprintf("projects/%s/%s/keys/%s", *o.Slug, *p.Slug, keyId), &key, nil)
return key, err
}

// GetClientKeys fetches all client keys of the given project
func (c *Client) GetClientKeys(o Organization, p Project) ([]Key, error) {
var keys []Key
Expand Down
25 changes: 23 additions & 2 deletions keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"testing"
)

const (
testClientKeyName = "Test client key"
)

func TestKeysResource(t *testing.T) {
t.Parallel()

Expand All @@ -21,13 +25,16 @@ func TestKeysResource(t *testing.T) {
defer cleanupproj()

t.Run("Create a new key for project", func(t *testing.T) {
key, err := client.CreateClientKey(org, project, "Test client key")
key, err := client.CreateClientKey(org, project, testClientKeyName)
if err != nil {
t.Error(err)
}
if key.Label != "Test client key" {
if key.Label != testClientKeyName {
t.Error("Key does not have correct label")
}
if key.Label != testClientKeyName {
t.Error("Key does not have correct name")
}
if key.RateLimit != nil {
t.Error("freshly created keys should not have rate limiting")
}
Expand Down Expand Up @@ -70,6 +77,20 @@ func TestKeysResource(t *testing.T) {
}
})
})
t.Run("Get client key", func(t *testing.T) {
key, err := client.GetClientKey(org, project, key.ID)
if err != nil {
t.Error(err)
}

if key.ID != key.ID {
t.Error("Failed to fetch key")
}

if key.Name != testClientKeyName {
t.Error("Key does not have correct name")
}
})
})

}