This repository has been archived by the owner on Dec 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
policy_violation.go
81 lines (65 loc) · 2.11 KB
/
policy_violation.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
package dtrack
import (
"context"
"fmt"
"net/http"
"strconv"
"github.com/google/uuid"
)
type PolicyViolation struct {
UUID uuid.UUID
Component Component `json:"component"`
Project Project `json:"project"`
PolicyCondition *PolicyCondition `json:"policyCondition,omitempty"`
Type string `json:"type"`
Text string `json:"text"`
Analysis *ViolationAnalysis `json:"analysis,omitempty"`
}
type PolicyViolationService struct {
client *Client
}
func (pvs PolicyViolationService) GetAll(ctx context.Context, suppressed bool, po PageOptions) (p Page[PolicyViolation], err error) {
params := map[string]string{
"suppressed": strconv.FormatBool(suppressed),
}
req, err := pvs.client.newRequest(ctx, http.MethodGet, "/api/v1/violation", withParams(params), withPageOptions(po))
if err != nil {
return
}
res, err := pvs.client.doRequest(req, &p.Items)
if err != nil {
return
}
p.TotalCount = res.TotalCount
return
}
func (pvs PolicyViolationService) GetAllForProject(ctx context.Context, projectUUID uuid.UUID, suppressed bool, po PageOptions) (p Page[PolicyViolation], err error) {
params := map[string]string{
"suppressed": strconv.FormatBool(suppressed),
}
req, err := pvs.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/violation/project/%s", projectUUID), withParams(params), withPageOptions(po))
if err != nil {
return
}
res, err := pvs.client.doRequest(req, &p.Items)
if err != nil {
return
}
p.TotalCount = res.TotalCount
return
}
func (pvs PolicyViolationService) GetAllForComponent(ctx context.Context, componentUUID uuid.UUID, suppressed bool, po PageOptions) (p Page[PolicyViolation], err error) {
params := map[string]string{
"suppressed": strconv.FormatBool(suppressed),
}
req, err := pvs.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/violation/component/%s", componentUUID), withParams(params), withPageOptions(po))
if err != nil {
return
}
res, err := pvs.client.doRequest(req, &p.Items)
if err != nil {
return
}
p.TotalCount = res.TotalCount
return
}