-
Notifications
You must be signed in to change notification settings - Fork 243
/
standard.go
148 lines (121 loc) · 4.11 KB
/
standard.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package pagerduty
import (
"context"
"github.com/google/go-querystring/query"
)
const (
standardPath = "/standards"
)
// Standard defines a PagerDuty resource standard.
type Standard struct {
Active bool `json:"active"`
Description string `json:"description,omitempty"`
Exclusions []StandardInclusionExclusion `json:"exclusions,omitempty"`
ID string `json:"id,omitempty"`
Inclusions []StandardInclusionExclusion `json:"inclusions,omitempty"`
Name string `json:"name,omitempty"`
ResourceType string `json:"resource_type,omitempty"`
Type string `json:"type,omitempty"`
}
type StandardInclusionExclusion struct {
Type string `json:"type,omitempty"`
ID string `json:"id,omitempty"`
}
// ListStandardsResponse is the data structure returned from calling the ListStandards API endpoint.
type ListStandardsResponse struct {
Standards []Standard `json:"standards"`
}
// ListStandardsOptions is the data structure used when calling the ListStandards API endpoint.
type ListStandardsOptions struct {
Active bool `url:"active,omitempty"`
// ResourceType query for a specific resource type.
// Allowed value: technical_service
ResourceType string `url:"resource_type,omitempty"`
}
type ResourceStandardScore struct {
ResourceID string `json:"resource_id,omitempty"`
ResourceType string `json:"resource_type,omitempty"`
Score *ResourceScore `json:"score,omitempty"`
Standards []ResourceStandard `json:"standards,omitempty"`
}
type ResourceScore struct {
Passing int `json:"passing,omitempty"`
Total int `json:"total,omitempty"`
}
type ResourceStandard struct {
Active bool `json:"active"`
Description string `json:"description,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Pass bool `json:"pass"`
Type string `json:"type,omitempty"`
}
type ListMultiResourcesStandardScoresResponse struct {
Resources []ResourceStandardScore `json:"resources,omitempty"`
}
type ListMultiResourcesStandardScoresOptions struct {
// Ids of resources to apply the standards. Maximum of 100 items
IDs []string `url:"ids,omitempty,brackets"`
}
// ListStandards lists all the existing standards.
func (c *Client) ListStandards(ctx context.Context, o ListStandardsOptions) (*ListStandardsResponse, error) {
v, err := query.Values(o)
if err != nil {
return nil, err
}
resp, err := c.get(ctx, standardPath+"?"+v.Encode(), nil)
if err != nil {
return nil, err
}
var result ListStandardsResponse
if err = c.decodeJSON(resp, &result); err != nil {
return nil, err
}
return &result, nil
}
// UpdateStandard updates an existing standard.
func (c *Client) UpdateStandard(ctx context.Context, id string, s Standard) (*Standard, error) {
resp, err := c.put(ctx, standardPath+"/"+id, s, nil)
if err != nil {
return nil, err
}
var result Standard
if err = c.decodeJSON(resp, &result); err != nil {
return nil, err
}
return &result, nil
}
// ListResourceStandardScores
//
// rt - Resource type
// Allowed values: technical_services
func (c *Client) ListResourceStandardScores(ctx context.Context, id string, rt string) (*ResourceStandardScore, error) {
resp, err := c.get(ctx, standardPath+"/scores/"+rt+"/"+id, nil)
if err != nil {
return nil, err
}
var result ResourceStandardScore
if err = c.decodeJSON(resp, &result); err != nil {
return nil, err
}
return &result, nil
}
// ListMultiResourcesStandardScores
//
// rt - Resource type
// Allowed values: technical_services
func (c *Client) ListMultiResourcesStandardScores(ctx context.Context, rt string, o ListMultiResourcesStandardScoresOptions) (*ListMultiResourcesStandardScoresResponse, error) {
v, err := query.Values(o)
if err != nil {
return nil, err
}
resp, err := c.get(ctx, standardPath+"/scores/"+rt+"?"+v.Encode(), nil)
if err != nil {
return nil, err
}
var result ListMultiResourcesStandardScoresResponse
if err = c.decodeJSON(resp, &result); err != nil {
return nil, err
}
return &result, nil
}