forked from spaceapegames/go-wavefront
-
Notifications
You must be signed in to change notification settings - Fork 12
/
metrics_policy.go
94 lines (82 loc) · 2.97 KB
/
metrics_policy.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package wavefront
// MetricsPolicy represents the global metrics policy for a given Wavefront domain
type MetricsPolicy struct {
PolicyRules []PolicyRule `json:"policyRules,omitempty"`
Customer string `json:"customer,omitempty"`
UpdaterId string `json:"updaterId,omitempty"`
UpdatedEpochMillis int `json:"updatedEpochMillis,omitempty"`
}
type PolicyRule struct {
Accounts []PolicyUser `json:"accounts,omitempty"`
UserGroups []PolicyUserGroup `json:"userGroups,omitempty"`
Roles []Role `json:"roles,omitempty"`
Name string `json:"name,omitempty"`
Tags []PolicyTag `json:"tags,omitempty"`
Description string `json:"description,omitempty"`
Prefixes []string `json:"prefixes,omitempty"`
TagsAnded bool `json:"tagsAnded,omitempty"`
AccessType string `json:"accessType,omitempty"`
}
type UpdateMetricsPolicyRequest struct {
PolicyRules []PolicyRuleRequest `json:"policyRules,omitempty"`
}
type PolicyRuleRequest struct {
AccountIds []string `json:"accounts,omitempty"`
UserGroupIds []string `json:"userGroups,omitempty"`
RoleIds []string `json:"roles,omitempty"`
Name string `json:"name,omitempty"`
Tags []PolicyTag `json:"tags,omitempty"`
Description string `json:"description,omitempty"`
Prefixes []string `json:"prefixes,omitempty"`
TagsAnded bool `json:"tagsAnded,omitempty"`
AccessType string `json:"accessType,omitempty"`
}
type PolicyTag struct {
Key string `json:"key,omitempty"`
Value string `json:"value,omitempty"`
}
type PolicyUser struct {
// Unique ID for the user
ID string `json:"id,omitempty"`
// Name of the user
Name string `json:"name,omitempty"`
}
type PolicyUserGroup struct {
// Unique ID for the user group
ID string `json:"id,omitempty"`
// Name of the user group
Name string `json:"name,omitempty"`
// Description of the Group purpose
Description string `json:"description,omitempty"`
}
// MetricsPolicyAPI is used to perform MetricsPolicy-related operations against the Wavefront API
type MetricsPolicyAPI struct {
// client is the Wavefront client used to perform Dashboard-related operations
client Wavefronter
}
const baseMetricsPolicyPath = "/api/v2/metricspolicy"
// MetricsPolicyAPI is used to return a client for MetricsPolicy-related operations
func (c *Client) MetricsPolicyAPI() *MetricsPolicyAPI {
return &MetricsPolicyAPI{client: c}
}
func (m *MetricsPolicyAPI) Get() (*MetricsPolicy, error) {
metricsPolicy := MetricsPolicy{}
err := doRest(
"GET",
baseMetricsPolicyPath,
m.client,
doResponse(&metricsPolicy),
)
return &metricsPolicy, err
}
func (m *MetricsPolicyAPI) Update(policyRules *UpdateMetricsPolicyRequest) (*MetricsPolicy, error) {
metricsPolicy := MetricsPolicy{}
err := doRest(
"PUT",
baseMetricsPolicyPath,
m.client,
doPayload(policyRules),
doResponse(&metricsPolicy),
)
return &metricsPolicy, err
}