forked from DependencyTrack/client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
policy_violation_analysis.go
65 lines (52 loc) · 1.88 KB
/
policy_violation_analysis.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
package dtrack
import (
"context"
"net/http"
"github.com/google/uuid"
)
type ViolationAnalysisState string
const (
ViolationAnalysisStateNotSet ViolationAnalysisState = "NOT_SET"
ViolationAnalysisStateApproved ViolationAnalysisState = "APPROVED"
ViolationAnalysisStateRejected ViolationAnalysisState = "REJECTED"
)
type ViolationAnalysis struct {
Comments []ViolationAnalysisComment `json:"analysisComments"`
State ViolationAnalysisState `json:"analysisState"`
Suppressed bool `json:"isSuppressed"`
}
type ViolationAnalysisComment struct {
Comment string `json:"comment"`
Commenter string `json:"commenter"`
Timestamp int `json:"timestamp"`
}
type ViolationAnalysisRequest struct {
Component uuid.UUID `json:"component"`
PolicyViolation uuid.UUID `json:"policyViolation"`
Comment string `json:"comment,omitempty"`
State ViolationAnalysisState `json:"analysisState,omitempty"`
Suppressed *bool `json:"isSuppressed,omitempty"`
}
type ViolationAnalysisService struct {
client *Client
}
func (vas ViolationAnalysisService) Get(ctx context.Context, componentUUID, policyViolationUUID uuid.UUID) (va ViolationAnalysis, err error) {
params := map[string]string{
"component": componentUUID.String(),
"policyViolation": policyViolationUUID.String(),
}
req, err := vas.client.newRequest(ctx, http.MethodGet, "/api/v1/violation/analysis", withParams(params))
if err != nil {
return
}
_, err = vas.client.doRequest(req, &va)
return
}
func (vas ViolationAnalysisService) Update(ctx context.Context, analysisReq ViolationAnalysisRequest) (va ViolationAnalysis, err error) {
req, err := vas.client.newRequest(ctx, http.MethodPut, "/api/v1/violation/analysis", withBody(analysisReq))
if err != nil {
return
}
_, err = vas.client.doRequest(req, &va)
return
}