@@ -9,17 +9,36 @@ import (
99)
1010
1111type Policy struct {
12- UUID uuid.UUID
13- Name string `json:"name"`
14- Operator string `json:"operator"`
15- ViolationState string `json:"violationState"`
16- PolicyConditions []PolicyCondition `json:"policyConditions"`
12+ UUID uuid.UUID `json:"uuid,omitempty"`
13+ Name string `json:"name"`
14+ Operator PolicyOperator `json:"operator"`
15+ ViolationState PolicyViolationState `json:"violationState"`
16+ PolicyConditions []PolicyCondition `json:"policyConditions,omitempty"`
17+ IncludeChildren bool `json:"includeChildren,omitempty"`
18+ Global bool `json:"global,omitempty"`
19+ Projects []Project `json:"projects,omitempty"`
20+ Tags []Tag `json:"tags,omitempty"`
1721}
1822
1923type PolicyService struct {
2024 client * Client
2125}
2226
27+ type PolicyOperator string
28+
29+ const (
30+ PolicyOperatorAll PolicyOperator = "ALL"
31+ PolicyOperatorAny PolicyOperator = "ANY"
32+ )
33+
34+ type PolicyViolationState string
35+
36+ const (
37+ PolicyViolationStateInfo PolicyViolationState = "INFO"
38+ PolicyViolationStateWarn PolicyViolationState = "WARN"
39+ PolicyViolationStateFail PolicyViolationState = "FAIL"
40+ )
41+
2342func (ps PolicyService ) Get (ctx context.Context , policyUUID uuid.UUID ) (p Policy , err error ) {
2443 req , err := ps .client .newRequest (ctx , http .MethodGet , fmt .Sprintf ("/api/v1/policy/%s" , policyUUID ))
2544 if err != nil {
@@ -44,3 +63,73 @@ func (ps PolicyService) GetAll(ctx context.Context, po PageOptions) (p Page[Poli
4463 p .TotalCount = res .TotalCount
4564 return
4665}
66+
67+ func (ps PolicyService ) Create (ctx context.Context , policy Policy ) (p Policy , err error ) {
68+ req , err := ps .client .newRequest (ctx , http .MethodPut , "/api/v1/policy" , withBody (policy ))
69+ if err != nil {
70+ return
71+ }
72+
73+ _ , err = ps .client .doRequest (req , & p )
74+ return
75+ }
76+
77+ func (ps PolicyService ) Delete (ctx context.Context , policyUUID uuid.UUID ) (err error ) {
78+ req , err := ps .client .newRequest (ctx , http .MethodDelete , fmt .Sprintf ("/api/v1/policy/%s" , policyUUID ))
79+ if err != nil {
80+ return
81+ }
82+
83+ _ , err = ps .client .doRequest (req , nil )
84+ return
85+ }
86+
87+ func (ps PolicyService ) Update (ctx context.Context , policy Policy ) (p Policy , err error ) {
88+ req , err := ps .client .newRequest (ctx , http .MethodPost , "/api/v1/policy" , withBody (policy ))
89+ if err != nil {
90+ return
91+ }
92+
93+ _ , err = ps .client .doRequest (req , & p )
94+ return
95+ }
96+
97+ func (ps PolicyService ) AddProject (ctx context.Context , policyUUID , projectUUID uuid.UUID ) (p Policy , err error ) {
98+ req , err := ps .client .newRequest (ctx , http .MethodPost , fmt .Sprintf ("/api/v1/policy/%s/project/%s" , policyUUID , projectUUID ))
99+ if err != nil {
100+ return
101+ }
102+
103+ _ , err = ps .client .doRequest (req , & p )
104+ return
105+ }
106+
107+ func (ps PolicyService ) DeleteProject (ctx context.Context , policyUUID , projectUUID uuid.UUID ) (p Policy , err error ) {
108+ req , err := ps .client .newRequest (ctx , http .MethodDelete , fmt .Sprintf ("/api/v1/policy/%s/project/%s" , policyUUID , projectUUID ))
109+ if err != nil {
110+ return
111+ }
112+
113+ _ , err = ps .client .doRequest (req , & p )
114+ return
115+ }
116+
117+ func (ps PolicyService ) AddTag (ctx context.Context , policyUUID uuid.UUID , tagName string ) (p Policy , err error ) {
118+ req , err := ps .client .newRequest (ctx , http .MethodPost , fmt .Sprintf ("/api/v1/policy/%s/tag/%s" , policyUUID , tagName ))
119+ if err != nil {
120+ return
121+ }
122+
123+ _ , err = ps .client .doRequest (req , & p )
124+ return
125+ }
126+
127+ func (ps PolicyService ) DeleteTag (ctx context.Context , policyUUID uuid.UUID , tagName string ) (p Policy , err error ) {
128+ req , err := ps .client .newRequest (ctx , http .MethodDelete , fmt .Sprintf ("/api/v1/policy/%s/tag/%s" , policyUUID , tagName ))
129+ if err != nil {
130+ return
131+ }
132+
133+ _ , err = ps .client .doRequest (req , & p )
134+ return
135+ }
0 commit comments