From ad0838faf630be129e8939c95e9868cd2ab3f623 Mon Sep 17 00:00:00 2001 From: John Hanrahan Date: Wed, 3 Feb 2021 14:59:43 -0800 Subject: [PATCH 1/2] add method to get primary agent keys --- api.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/api.go b/api.go index 036776a..784c1ba 100644 --- a/api.go +++ b/api.go @@ -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 +} From 9bf03de9a6c067f56e2cc208779e41728684ea79 Mon Sep 17 00:00:00 2001 From: John Hanrahan Date: Wed, 3 Feb 2021 15:17:22 -0800 Subject: [PATCH 2/2] add test --- api_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/api_test.go b/api_test.go index f2af46a..edac802 100644 --- a/api_test.go +++ b/api_test.go @@ -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") + } +}