forked from wavefrontHQ/go-wavefront-management-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ingestionpolicies.go
78 lines (65 loc) · 1.73 KB
/
ingestionpolicies.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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"`
Scope string `json:"scope"`
}
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)
}