-
Notifications
You must be signed in to change notification settings - Fork 610
/
content_scanning.go
189 lines (160 loc) · 6.76 KB
/
content_scanning.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package cloudflare
import (
"context"
"fmt"
"net/http"
"github.com/goccy/go-json"
)
type ContentScanningStatusResult struct {
Value string `json:"value"`
Modified string `json:"modified"`
}
type ContentScanningEnableParams struct{}
type ContentScanningEnableResponse struct {
Response
Result *ContentScanningStatusResult `json:"result"` // nil
}
type ContentScanningDisableParams struct{}
type ContentScanningDisableResponse struct {
Response
Result *ContentScanningStatusResult `json:"result"` // nil
}
type ContentScanningStatusParams struct{}
type ContentScanningStatusResponse struct {
Response
Result *ContentScanningStatusResult `json:"result"` // object or nil
}
type ContentScanningCustomExpression struct {
ID string `json:"id"`
Payload string `json:"payload"`
}
type ContentScanningListCustomExpressionsParams struct{}
type ContentScanningListCustomExpressionsResponse struct {
Response
Result []ContentScanningCustomExpression `json:"result"`
}
type ContentScanningCustomPayload struct {
Payload string `json:"payload"`
}
type ContentScanningAddCustomExpressionsParams struct {
Payloads []ContentScanningCustomPayload
}
type ContentScanningAddCustomExpressionsResponse struct {
Response
Result []ContentScanningCustomExpression `json:"result"`
}
type ContentScanningDeleteCustomExpressionsParams struct {
ID string
}
type ContentScanningDeleteCustomExpressionsResponse struct {
Response
Result []ContentScanningCustomExpression `json:"result"`
}
// ContentScanningEnable enables Content Scanning.
//
// API reference: https://developers.cloudflare.com/api/resources/content_scanning/methods/enable/
func (api *API) ContentScanningEnable(ctx context.Context, rc *ResourceContainer, params ContentScanningEnableParams) (ContentScanningEnableResponse, error) {
if rc.Identifier == "" {
return ContentScanningEnableResponse{}, ErrMissingZoneID
}
uri := fmt.Sprintf("/zones/%s/content-upload-scan/enable", rc.Identifier)
res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil)
if err != nil {
return ContentScanningEnableResponse{}, err
}
result := ContentScanningEnableResponse{}
if err := json.Unmarshal(res, &result); err != nil {
return ContentScanningEnableResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return result, nil
}
// ContentScanningDisable disables Content Scanning.
//
// API reference: https://developers.cloudflare.com/api/resources/content_scanning/methods/disable/
func (api *API) ContentScanningDisable(ctx context.Context, rc *ResourceContainer, params ContentScanningDisableParams) (ContentScanningDisableResponse, error) {
if rc.Identifier == "" {
return ContentScanningDisableResponse{}, ErrMissingZoneID
}
uri := fmt.Sprintf("/zones/%s/content-upload-scan/disable", rc.Identifier)
res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil)
if err != nil {
return ContentScanningDisableResponse{}, err
}
result := ContentScanningDisableResponse{}
if err := json.Unmarshal(res, &result); err != nil {
return ContentScanningDisableResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return result, nil
}
// ContentScanningStatus reads the status of Content Scanning.
//
// API reference: https://developers.cloudflare.com/api/resources/content_scanning/subresources/settings/methods/get/
func (api *API) ContentScanningStatus(ctx context.Context, rc *ResourceContainer, params ContentScanningStatusParams) (ContentScanningStatusResponse, error) {
if rc.Identifier == "" {
return ContentScanningStatusResponse{}, ErrMissingZoneID
}
uri := fmt.Sprintf("/zones/%s/content-upload-scan/settings", rc.Identifier)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return ContentScanningStatusResponse{}, err
}
result := ContentScanningStatusResponse{}
if err := json.Unmarshal(res, &result); err != nil {
return ContentScanningStatusResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return result, nil
}
// ContentScanningListCustomExpressions retrieves the list of existing custom scan expressions for Content Scanning
//
// API reference: https://developers.cloudflare.com/api/resources/content_scanning/subresources/payloads/methods/list/
func (api *API) ContentScanningListCustomExpressions(ctx context.Context, rc *ResourceContainer, params ContentScanningListCustomExpressionsParams) ([]ContentScanningCustomExpression, error) {
if rc.Identifier == "" {
return []ContentScanningCustomExpression{}, ErrMissingZoneID
}
uri := fmt.Sprintf("/zones/%s/content-upload-scan/payloads", rc.Identifier)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return []ContentScanningCustomExpression{}, err
}
result := ContentScanningListCustomExpressionsResponse{}
if err := json.Unmarshal(res, &result); err != nil {
return []ContentScanningCustomExpression{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return result.Result, nil
}
// ContentScanningAddCustomExpressions add new custom scan expressions for Content Scanning
//
// API reference: https://developers.cloudflare.com/api/resources/content_scanning/subresources/payloads/methods/list/
func (api *API) ContentScanningAddCustomExpressions(ctx context.Context, rc *ResourceContainer, params ContentScanningAddCustomExpressionsParams) ([]ContentScanningCustomExpression, error) {
if rc.Identifier == "" {
return []ContentScanningCustomExpression{}, ErrMissingZoneID
}
uri := fmt.Sprintf("/zones/%s/content-upload-scan/payloads", rc.Identifier)
res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params.Payloads)
if err != nil {
return []ContentScanningCustomExpression{}, err
}
result := ContentScanningAddCustomExpressionsResponse{}
if err := json.Unmarshal(res, &result); err != nil {
return []ContentScanningCustomExpression{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return result.Result, nil
}
// ContentScanningDeleteCustomExpressions delete custom scan expressions for Content Scanning
//
// API reference: https://developers.cloudflare.com/api/resources/content_scanning/subresources/payloads/methods/delete/
func (api *API) ContentScanningDeleteCustomExpression(ctx context.Context, rc *ResourceContainer, params ContentScanningDeleteCustomExpressionsParams) ([]ContentScanningCustomExpression, error) {
if rc.Identifier == "" {
return []ContentScanningCustomExpression{}, ErrMissingZoneID
}
uri := fmt.Sprintf("/zones/%s/content-upload-scan/payloads/%s", rc.Identifier, params.ID)
res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil)
if err != nil {
return []ContentScanningCustomExpression{}, err
}
result := ContentScanningDeleteCustomExpressionsResponse{}
if err := json.Unmarshal(res, &result); err != nil {
return []ContentScanningCustomExpression{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return result.Result, nil
}