Skip to content

Commit

Permalink
Feature/ingestion policies (#39)
Browse files Browse the repository at this point in the history
* 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
snltd and Robert Fisher authored Jan 26, 2021
1 parent aec889b commit 3b2e0dd
Show file tree
Hide file tree
Showing 17 changed files with 635 additions and 32 deletions.
5 changes: 4 additions & 1 deletion .gitignore
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
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ notifications:
email: false

# script always run to completion (set +e).
install:
- go get -t -v $(go list ./ ... | grep -v examples)
script:
- diff -u <(echo -n) <(gofmt -d .)
# Run all the tests with the race detector enabled
- go test -timeout 10m -v -race ./
# go vet is the official Go static analyzer
- go vet ./
- go vet ./
18 changes: 11 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Changelog for go-wavefront-management-api.

## [1.14.0]

* Add support for ingestion policies

## [1.12.0]

*Add IsLogIntegration field to ExternalLink type*
Expand All @@ -27,18 +31,18 @@ Bug fixes:

## [1.10.0]

*Add support for Service Accounts*
*Add support for Service Accounts*

## [1.9.0]

*Adds support for roles*
*Adds support for roles*

## [1.8.1]
*Fixes dashboard taggging after creation by adding SetTags functionality*

## [1.8.0]

*Add Support for CloudIntegrations*
*Add Support for CloudIntegrations*
- CloudWatch
- CloudTrail
- EC2
Expand All @@ -49,27 +53,27 @@ Bug fixes:
- Tesla
- Azure
- Azure Activity Log

*Add Support for Advanced Alert settings*

- CheckingFrequencyInMinutes
- EvaluateRealtimeData
- IncludeObsoleteMetrics

*Common client operations refactored into centralized location*
*Common client operations refactored into centralized location*
*Added support for skipTrash*

- Alerts
- Dashboards
- DerivedMetrics
- CloudIntegrations

*Fixed some failing tests*
*Fixed some failing tests*
*Add Annotations field to Events*

## [1.7.3]

- Fixing go.mod file
- Fixing go.mod file

## [1.7.2]

Expand Down
18 changes: 18 additions & 0 deletions fixtures/create-ingestion-policyresponse.json
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"
}
}
18 changes: 18 additions & 0 deletions fixtures/crud-ingestionpolicy-response.json
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"
}
}
30 changes: 30 additions & 0 deletions fixtures/crud-serviceaccount-response.json
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"
}
}
31 changes: 31 additions & 0 deletions fixtures/search-ingestionpolicy-response.json
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
}
}
}
54 changes: 54 additions & 0 deletions fixtures/search-serviceaccount-response.json
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
}
}
}
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ module github.com/WavefrontHQ/go-wavefront-management-api

go 1.13

require github.com/stretchr/testify v1.6.1
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/stretchr/testify v1.6.1
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
)
18 changes: 18 additions & 0 deletions go.sum
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=
77 changes: 77 additions & 0 deletions ingestionpolicies.go
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)
}
Loading

0 comments on commit 3b2e0dd

Please sign in to comment.