forked from nscuro/dtrack-client
-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
policy_condition.go
85 lines (71 loc) · 3.49 KB
/
policy_condition.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
package dtrack
import (
"context"
"fmt"
"net/http"
"github.com/google/uuid"
)
type PolicyCondition struct {
UUID uuid.UUID `json:"uuid,omitempty"`
Policy *Policy `json:"policy,omitempty"`
Operator PolicyConditionOperator `json:"operator"`
Subject PolicyConditionSubject `json:"subject"`
Value string `json:"value"`
}
type PolicyConditionService struct {
client *Client
}
type PolicyConditionOperator string
const (
PolicyConditionOperatorIs PolicyConditionOperator = "IS"
PolicyConditionOperatorIsNot PolicyConditionOperator = "IS_NOT"
PolicyConditionOperatorMatches PolicyConditionOperator = "MATCHES"
PolicyConditionOperatorNoMatch PolicyConditionOperator = "NO_MATCH"
PolicyConditionOperatorNumericGreaterThan PolicyConditionOperator = "NUMERIC_GREATER_THAN"
PolicyConditionOperatorNumericLessThan PolicyConditionOperator = "NUMERIC_LESS_THAN"
PolicyConditionOperatorNumericEqual PolicyConditionOperator = "NUMERIC_EQUAL"
PolicyConditionOperatorNumericNotEqual PolicyConditionOperator = "NUMERIC_NOT_EQUAL"
PolicyConditionOperatorNumericGreaterThanOrEqual PolicyConditionOperator = "NUMERIC_GREATER_THAN_OR_EQUAL"
PolicyConditionOperatorNumericLesserThanOrEqual PolicyConditionOperator = "NUMERIC_LESSER_THAN_OR_EQUAL"
PolicyConditionOperatorContainsAll PolicyConditionOperator = "CONTAINS_ALL"
PolicyConditionOperatorContainsAny PolicyConditionOperator = "CONTAINS_ANY"
)
type PolicyConditionSubject string
const (
PolicyConditionSubjectAge PolicyConditionSubject = "AGE"
PolicyConditionSubjectCoordinates PolicyConditionSubject = "COORDINATES"
PolicyConditionSubjectCPE PolicyConditionSubject = "CPE"
PolicyConditionSubjectLicense PolicyConditionSubject = "LICENSE"
PolicyConditionSubjectLicenseGroup PolicyConditionSubject = "LICENSE_GROUP"
PolicyConditionSubjectPackageURL PolicyConditionSubject = "PACKAGE_URL"
PolicyConditionSubjectSeverity PolicyConditionSubject = "SEVERITY"
PolicyConditionSubjectSWIDTagID PolicyConditionSubject = "SWID_TAGID"
PolicyConditionSubjectVersion PolicyConditionSubject = "VERSION"
PolicyConditionSubjectComponentHash PolicyConditionSubject = "COMPONENT_HASH"
PolicyConditionSubjectCWE PolicyConditionSubject = "CWE"
PolicyConditionSubjectVulnerabilityID PolicyConditionSubject = "VULNERABILITY_ID"
)
func (pcs PolicyConditionService) Create(ctx context.Context, policyUUID uuid.UUID, policyCondition PolicyCondition) (p PolicyCondition, err error) {
req, err := pcs.client.newRequest(ctx, http.MethodPut, fmt.Sprintf("/api/v1/policy/%s/condition", policyUUID), withBody(policyCondition))
if err != nil {
return
}
_, err = pcs.client.doRequest(req, &p)
return
}
func (pcs PolicyConditionService) Update(ctx context.Context, policyCondition PolicyCondition) (p PolicyCondition, err error) {
req, err := pcs.client.newRequest(ctx, http.MethodPost, "/api/v1/policy/condition", withBody(policyCondition))
if err != nil {
return
}
_, err = pcs.client.doRequest(req, &p)
return
}
func (pcs PolicyConditionService) Delete(ctx context.Context, policyConditionUUID uuid.UUID) (err error) {
req, err := pcs.client.newRequest(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/policy/condition/%s", policyConditionUUID))
if err != nil {
return
}
_, err = pcs.client.doRequest(req, nil)
return
}