forked from spaceapegames/go-wavefront
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add support for ingestion policies * remove unused fields from struct * tidy modules and use go.mod * add service account tests * teach service accounts about ingestion policies * better variable names * add example test * ignore vim swap files * fix updating * address issues raised in review Co-authored-by: Robert Fisher <services@id264.net>
- Loading branch information
Showing
17 changed files
with
635 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# Ignore binary | ||
# Ignore binary | ||
cmd/wavefront/wavefront | ||
# Ignore vendored library packages | ||
vendor/*/ | ||
.idea/* | ||
|
||
# Vim swap files | ||
.*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"status": { | ||
"result": "OK", | ||
"message": "string", | ||
"code": 200 | ||
}, | ||
"response": { | ||
"sampledUserAccounts": [], | ||
"userAccountCount": 0, | ||
"sampledServiceAccounts": [], | ||
"serviceAccountCount": 0, | ||
"name": "test-policy", | ||
"id": "test-policy-1607616352537", | ||
"customer": "test", | ||
"lastUpdatedMs": 1607616352549, | ||
"lastUpdatedAccountId": "example@wavefront.com" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"status": { | ||
"result": "OK", | ||
"message": "", | ||
"code": 200 | ||
}, | ||
"response": { | ||
"sampledUserAccounts": [], | ||
"userAccountCount": 0, | ||
"sampledServiceAccounts": [], | ||
"serviceAccountCount": 0, | ||
"name": "newname", | ||
"id": "test-policy-1607616352537", | ||
"customer": "test", | ||
"lastUpdatedMs": 1607694702333, | ||
"lastUpdatedAccountId": "example@wavefront.com" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"status": { | ||
"result": "OK", | ||
"message": "", | ||
"code": 200 | ||
}, | ||
"response": { | ||
"tokens": [], | ||
"userGroups": [ | ||
{ | ||
"id": "a7d2e651-cec1-4154-a5e8-1946f57ef5b3", | ||
"name": "Everyone", | ||
"permissions": [], | ||
"customer": "test", | ||
"properties": { | ||
"nameEditable": false, | ||
"permissionsEditable": true, | ||
"usersEditable": false, | ||
"rolesEditable": true | ||
}, | ||
"description": "System group which contains all users", | ||
"roles": [] | ||
} | ||
], | ||
"roles": [], | ||
"active": true, | ||
"groups": [], | ||
"identifier": "sa::some_account" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"status": { | ||
"result": "OK", | ||
"message": "", | ||
"code": 200 | ||
}, | ||
"response": { | ||
"items": [ | ||
{ | ||
"sampledUserAccounts": [], | ||
"userAccountCount": 0, | ||
"sampledServiceAccounts": [], | ||
"serviceAccountCount": 0, | ||
"name": "test-policy", | ||
"id": "someid", | ||
"customer": "test", | ||
"lastUpdatedMs": 1589893291432, | ||
"lastUpdatedAccountId": "example@wavefront.com" | ||
} | ||
], | ||
"offset": 0, | ||
"limit": 10, | ||
"totalItems": 1, | ||
"moreItems": false, | ||
"sort": { | ||
"ascending": true, | ||
"field": "name", | ||
"default": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"status": { | ||
"result": "OK", | ||
"message": "", | ||
"code": 200 | ||
}, | ||
"response": { | ||
"items": [ | ||
{ | ||
"tokens": [ | ||
{ | ||
"tokenID": "abcdef01-2345-6789-0abc-def012345678", | ||
"tokenName": "some_token" | ||
} | ||
], | ||
"userGroups": [ | ||
{ | ||
"id": "01234567-8901-2345-6789-012345678901", | ||
"name": "Everyone", | ||
"permissions": [], | ||
"customer": "test", | ||
"properties": { | ||
"nameEditable": false, | ||
"permissionsEditable": true, | ||
"usersEditable": false, | ||
"rolesEditable": true | ||
}, | ||
"description": "System group which contains all users" | ||
} | ||
], | ||
"ingestionPolicy": { | ||
"name": "some-policy", | ||
"id": "some-policy-1579800000000", | ||
"customer": "test", | ||
"description": "example ingestion policy", | ||
"lastUpdatedMs": 1579800000000, | ||
"lastUpdatedAccountId": "someone@example.com" | ||
}, | ||
"active": true, | ||
"groups": [], | ||
"identifier": "sa::someid" | ||
} | ||
], | ||
"offset": 0, | ||
"limit": 10, | ||
"totalItems": 1, | ||
"moreItems": false, | ||
"sort": { | ||
"ascending": true, | ||
"field": "identifier", | ||
"default": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,28 @@ | ||
github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w= | ||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= | ||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= | ||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= | ||
github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw= | ||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | ||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= | ||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | ||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= | ||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= | ||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= | ||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ= | ||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package wavefront | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
const basePolicyPath = "/api/v2/usage/ingestionpolicy" | ||
|
||
type IngestionPolicy struct { | ||
ID string `json:"id,omitempty"` | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
UserAccountCount int `json:"userAccountCount"` | ||
ServiceAccountCount int `json:"serviceAccountCount"` | ||
} | ||
|
||
type IngestionPolicies struct { | ||
client Wavefronter | ||
} | ||
|
||
func (c *Client) IngestionPolicies() *IngestionPolicies { | ||
return &IngestionPolicies{client: c} | ||
} | ||
|
||
func (p IngestionPolicies) Find(conditions []*SearchCondition) ( | ||
results []*IngestionPolicy, err error) { | ||
err = doSearch(conditions, "ingestionpolicy", p.client, &results) | ||
return | ||
} | ||
|
||
func (p IngestionPolicies) Get(policy *IngestionPolicy) error { | ||
if policy.ID == "" { | ||
return fmt.Errorf("id must be specified") | ||
} | ||
|
||
return doRest( | ||
"GET", | ||
fmt.Sprintf("%s/%s", basePolicyPath, policy.ID), | ||
p.client, | ||
doResponse(policy)) | ||
} | ||
|
||
func (p IngestionPolicies) Create(policy *IngestionPolicy) error { | ||
if policy.Name == "" { | ||
return fmt.Errorf("ingestion policy name must be specified") | ||
} | ||
return doRest( | ||
"POST", | ||
basePolicyPath, | ||
p.client, | ||
doPayload(policy), | ||
doResponse(policy)) | ||
} | ||
|
||
func (p IngestionPolicies) Update(policy *IngestionPolicy) error { | ||
if policy.ID == "" { | ||
return fmt.Errorf("id must be specified") | ||
} | ||
|
||
return doRest( | ||
"PUT", | ||
fmt.Sprintf("%s/%s", basePolicyPath, policy.ID), | ||
p.client, | ||
doPayload(policy), | ||
doResponse(policy)) | ||
} | ||
|
||
func (p IngestionPolicies) Delete(policy *IngestionPolicy) error { | ||
if policy.ID == "" { | ||
return fmt.Errorf("id must be specified") | ||
} | ||
|
||
return doRest( | ||
"DELETE", | ||
fmt.Sprintf("%s/%s", basePolicyPath, policy.ID), | ||
p.client) | ||
} |
Oops, something went wrong.