Skip to content

Commit

Permalink
Merge pull request #17 from signalsciences/AddAgentKeys
Browse files Browse the repository at this point in the history
add method to get primary agent keys
  • Loading branch information
jhanrahan-sigsci authored Feb 4, 2021
2 parents cf3f852 + 9bf03de commit 7a26569
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
33 changes: 33 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2591,3 +2591,36 @@ func (sc *Client) GetSiteTemplateRuleByID(corpName, siteName, id string) (SiteTe
}
return getResponseSiteTemplateBody(resp)
}

// PrimaryAgentKey contains the secret and access keys used by the agents
type PrimaryAgentKey struct {
Name string
AccessKey string
SecretKey string
}

type primaryAgentKeyResp struct {
Name string `json:"name"`
AccessKey string `json:"accessKey"`
SecretKey string `json:"secretKey"`
}

// GetSitePrimaryAgentKey retrieve the primary agent keys
func (sc *Client) GetSitePrimaryAgentKey(corpName, siteName string) (PrimaryAgentKey, error) {
resp, err := sc.doRequest("GET", fmt.Sprintf("/v0/corps/%s/sites/%s/keys", corpName, siteName), "")
if err != nil {
return PrimaryAgentKey{}, err
}
var responseBody primaryAgentKeyResp
if err = json.Unmarshal(resp, &responseBody); err != nil {
return PrimaryAgentKey{}, err
}

primaryKey := PrimaryAgentKey{
Name: responseBody.Name,
SecretKey: responseBody.SecretKey,
AccessKey: responseBody.AccessKey,
}

return primaryKey, nil
}
20 changes: 20 additions & 0 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1260,3 +1260,23 @@ func TestCRUDSiteMonitor(t *testing.T) {
t.Fatal(err)
}
}

func TestClient_GetSitePrimaryAgentKey(t *testing.T) {
sc := NewTokenClient(testcreds.email, testcreds.token)
corp := testcreds.corp
site := testcreds.site

keysResponse, err := sc.GetSitePrimaryAgentKey(corp, site)
if err != nil {
t.Fatal(err)
}
if keysResponse.Name != site {
t.Error("primary key name should be the same as site name")
}
if keysResponse.AccessKey == "" {
t.Error("Expected access key to be populated")
}
if keysResponse.SecretKey == "" {
t.Error("Expected secret key to be populated")
}
}

0 comments on commit 7a26569

Please sign in to comment.