@@ -16,6 +16,7 @@ import (
16
16
"github.com/cloudflare/cloudflare-go/v4/internal/param"
17
17
"github.com/cloudflare/cloudflare-go/v4/internal/requestconfig"
18
18
"github.com/cloudflare/cloudflare-go/v4/option"
19
+ "github.com/cloudflare/cloudflare-go/v4/packages/pagination"
19
20
"github.com/cloudflare/cloudflare-go/v4/shared"
20
21
)
21
22
@@ -44,9 +45,11 @@ func NewInsightService(opts ...option.RequestOption) (r *InsightService) {
44
45
return
45
46
}
46
47
47
- // Archive Security Center Insight
48
- func (r * InsightService ) Dismiss (ctx context.Context , issueID string , params InsightDismissParams , opts ... option.RequestOption ) (res * InsightDismissResponse , err error ) {
48
+ // Get Security Center Insights
49
+ func (r * InsightService ) List (ctx context.Context , params InsightListParams , opts ... option.RequestOption ) (res * pagination.V4PagePagination [InsightListResponse ], err error ) {
50
+ var raw * http.Response
49
51
opts = append (r .Options [:], opts ... )
52
+ opts = append ([]option.RequestOption {option .WithResponseInto (& raw )}, opts ... )
50
53
var accountOrZone string
51
54
var accountOrZoneID param.Field [string ]
52
55
if params .AccountID .Value != "" && params .ZoneID .Value != "" {
@@ -65,18 +68,26 @@ func (r *InsightService) Dismiss(ctx context.Context, issueID string, params Ins
65
68
accountOrZone = "zones"
66
69
accountOrZoneID = params .ZoneID
67
70
}
68
- if issueID == "" {
69
- err = errors .New ("missing required issue_id parameter" )
70
- return
71
+ path := fmt .Sprintf ("%s/%s/security-center/insights" , accountOrZone , accountOrZoneID )
72
+ cfg , err := requestconfig .NewRequestConfig (ctx , http .MethodGet , path , params , & res , opts ... )
73
+ if err != nil {
74
+ return nil , err
71
75
}
72
- path := fmt .Sprintf ("%s/%s/security-center/insights/%s/dismiss" , accountOrZone , accountOrZoneID , issueID )
73
- err = requestconfig .ExecuteNewRequest (ctx , http .MethodPut , path , params , & res , opts ... )
74
- return
76
+ err = cfg .Execute ()
77
+ if err != nil {
78
+ return nil , err
79
+ }
80
+ res .SetPageConfig (cfg , raw )
81
+ return res , nil
75
82
}
76
83
77
84
// Get Security Center Insights
78
- func (r * InsightService ) Get (ctx context.Context , params InsightGetParams , opts ... option.RequestOption ) (res * InsightGetResponse , err error ) {
79
- var env InsightGetResponseEnvelope
85
+ func (r * InsightService ) ListAutoPaging (ctx context.Context , params InsightListParams , opts ... option.RequestOption ) * pagination.V4PagePaginationAutoPager [InsightListResponse ] {
86
+ return pagination .NewV4PagePaginationAutoPager (r .List (ctx , params , opts ... ))
87
+ }
88
+
89
+ // Archive Security Center Insight
90
+ func (r * InsightService ) Dismiss (ctx context.Context , issueID string , params InsightDismissParams , opts ... option.RequestOption ) (res * InsightDismissResponse , err error ) {
80
91
opts = append (r .Options [:], opts ... )
81
92
var accountOrZone string
82
93
var accountOrZoneID param.Field [string ]
@@ -96,70 +107,29 @@ func (r *InsightService) Get(ctx context.Context, params InsightGetParams, opts
96
107
accountOrZone = "zones"
97
108
accountOrZoneID = params .ZoneID
98
109
}
99
- path := fmt .Sprintf ("%s/%s/security-center/insights" , accountOrZone , accountOrZoneID )
100
- err = requestconfig .ExecuteNewRequest (ctx , http .MethodGet , path , params , & env , opts ... )
101
- if err != nil {
110
+ if issueID == "" {
111
+ err = errors .New ("missing required issue_id parameter" )
102
112
return
103
113
}
104
- res = & env .Result
114
+ path := fmt .Sprintf ("%s/%s/security-center/insights/%s/dismiss" , accountOrZone , accountOrZoneID , issueID )
115
+ err = requestconfig .ExecuteNewRequest (ctx , http .MethodPut , path , params , & res , opts ... )
105
116
return
106
117
}
107
118
108
- type InsightDismissResponse struct {
109
- Errors []shared.ResponseInfo `json:"errors,required"`
110
- Messages []shared.ResponseInfo `json:"messages,required"`
111
- // Whether the API call was successful
112
- Success InsightDismissResponseSuccess `json:"success,required"`
113
- JSON insightDismissResponseJSON `json:"-"`
114
- }
115
-
116
- // insightDismissResponseJSON contains the JSON metadata for the struct
117
- // [InsightDismissResponse]
118
- type insightDismissResponseJSON struct {
119
- Errors apijson.Field
120
- Messages apijson.Field
121
- Success apijson.Field
122
- raw string
123
- ExtraFields map [string ]apijson.Field
124
- }
125
-
126
- func (r * InsightDismissResponse ) UnmarshalJSON (data []byte ) (err error ) {
127
- return apijson .UnmarshalRoot (data , r )
128
- }
129
-
130
- func (r insightDismissResponseJSON ) RawJSON () string {
131
- return r .raw
132
- }
133
-
134
- // Whether the API call was successful
135
- type InsightDismissResponseSuccess bool
136
-
137
- const (
138
- InsightDismissResponseSuccessTrue InsightDismissResponseSuccess = true
139
- )
140
-
141
- func (r InsightDismissResponseSuccess ) IsKnown () bool {
142
- switch r {
143
- case InsightDismissResponseSuccessTrue :
144
- return true
145
- }
146
- return false
147
- }
148
-
149
- type InsightGetResponse struct {
119
+ type InsightListResponse struct {
150
120
// Total number of results
151
- Count int64 `json:"count"`
152
- Issues []InsightGetResponseIssue `json:"issues"`
121
+ Count int64 `json:"count"`
122
+ Issues []InsightListResponseIssue `json:"issues"`
153
123
// Current page within paginated list of results
154
124
Page int64 `json:"page"`
155
125
// Number of results per page of results
156
- PerPage int64 `json:"per_page"`
157
- JSON insightGetResponseJSON `json:"-"`
126
+ PerPage int64 `json:"per_page"`
127
+ JSON insightListResponseJSON `json:"-"`
158
128
}
159
129
160
- // insightGetResponseJSON contains the JSON metadata for the struct
161
- // [InsightGetResponse ]
162
- type insightGetResponseJSON struct {
130
+ // insightListResponseJSON contains the JSON metadata for the struct
131
+ // [InsightListResponse ]
132
+ type insightListResponseJSON struct {
163
133
Count apijson.Field
164
134
Issues apijson.Field
165
135
Page apijson.Field
@@ -168,32 +138,32 @@ type insightGetResponseJSON struct {
168
138
ExtraFields map [string ]apijson.Field
169
139
}
170
140
171
- func (r * InsightGetResponse ) UnmarshalJSON (data []byte ) (err error ) {
141
+ func (r * InsightListResponse ) UnmarshalJSON (data []byte ) (err error ) {
172
142
return apijson .UnmarshalRoot (data , r )
173
143
}
174
144
175
- func (r insightGetResponseJSON ) RawJSON () string {
145
+ func (r insightListResponseJSON ) RawJSON () string {
176
146
return r .raw
177
147
}
178
148
179
- type InsightGetResponseIssue struct {
180
- ID string `json:"id"`
181
- Dismissed bool `json:"dismissed"`
182
- IssueClass string `json:"issue_class"`
183
- IssueType intel.IssueType `json:"issue_type"`
184
- Payload interface {} `json:"payload"`
185
- ResolveLink string `json:"resolve_link"`
186
- ResolveText string `json:"resolve_text"`
187
- Severity InsightGetResponseIssuesSeverity `json:"severity"`
188
- Since time.Time `json:"since" format:"date-time"`
189
- Subject string `json:"subject"`
190
- Timestamp time.Time `json:"timestamp" format:"date-time"`
191
- JSON insightGetResponseIssueJSON `json:"-"`
149
+ type InsightListResponseIssue struct {
150
+ ID string `json:"id"`
151
+ Dismissed bool `json:"dismissed"`
152
+ IssueClass string `json:"issue_class"`
153
+ IssueType intel.IssueType `json:"issue_type"`
154
+ Payload interface {} `json:"payload"`
155
+ ResolveLink string `json:"resolve_link"`
156
+ ResolveText string `json:"resolve_text"`
157
+ Severity InsightListResponseIssuesSeverity `json:"severity"`
158
+ Since time.Time `json:"since" format:"date-time"`
159
+ Subject string `json:"subject"`
160
+ Timestamp time.Time `json:"timestamp" format:"date-time"`
161
+ JSON insightListResponseIssueJSON `json:"-"`
192
162
}
193
163
194
- // insightGetResponseIssueJSON contains the JSON metadata for the struct
195
- // [InsightGetResponseIssue ]
196
- type insightGetResponseIssueJSON struct {
164
+ // insightListResponseIssueJSON contains the JSON metadata for the struct
165
+ // [InsightListResponseIssue ]
166
+ type insightListResponseIssueJSON struct {
197
167
ID apijson.Field
198
168
Dismissed apijson.Field
199
169
IssueClass apijson.Field
@@ -209,43 +179,72 @@ type insightGetResponseIssueJSON struct {
209
179
ExtraFields map [string ]apijson.Field
210
180
}
211
181
212
- func (r * InsightGetResponseIssue ) UnmarshalJSON (data []byte ) (err error ) {
182
+ func (r * InsightListResponseIssue ) UnmarshalJSON (data []byte ) (err error ) {
213
183
return apijson .UnmarshalRoot (data , r )
214
184
}
215
185
216
- func (r insightGetResponseIssueJSON ) RawJSON () string {
186
+ func (r insightListResponseIssueJSON ) RawJSON () string {
217
187
return r .raw
218
188
}
219
189
220
- type InsightGetResponseIssuesSeverity string
190
+ type InsightListResponseIssuesSeverity string
221
191
222
192
const (
223
- InsightGetResponseIssuesSeverityLow InsightGetResponseIssuesSeverity = "Low"
224
- InsightGetResponseIssuesSeverityModerate InsightGetResponseIssuesSeverity = "Moderate"
225
- InsightGetResponseIssuesSeverityCritical InsightGetResponseIssuesSeverity = "Critical"
193
+ InsightListResponseIssuesSeverityLow InsightListResponseIssuesSeverity = "Low"
194
+ InsightListResponseIssuesSeverityModerate InsightListResponseIssuesSeverity = "Moderate"
195
+ InsightListResponseIssuesSeverityCritical InsightListResponseIssuesSeverity = "Critical"
226
196
)
227
197
228
- func (r InsightGetResponseIssuesSeverity ) IsKnown () bool {
198
+ func (r InsightListResponseIssuesSeverity ) IsKnown () bool {
229
199
switch r {
230
- case InsightGetResponseIssuesSeverityLow , InsightGetResponseIssuesSeverityModerate , InsightGetResponseIssuesSeverityCritical :
200
+ case InsightListResponseIssuesSeverityLow , InsightListResponseIssuesSeverityModerate , InsightListResponseIssuesSeverityCritical :
231
201
return true
232
202
}
233
203
return false
234
204
}
235
205
236
- type InsightDismissParams struct {
237
- // The Account ID to use for this endpoint. Mutually exclusive with the Zone ID.
238
- AccountID param. Field [ string ] `path:"account_id "`
239
- // The Zone ID to use for this endpoint. Mutually exclusive with the Account ID.
240
- ZoneID param. Field [ string ] `path:"zone_id "`
241
- Dismiss param. Field [ bool ] `json:"dismiss "`
206
+ type InsightDismissResponse struct {
207
+ Errors []shared. ResponseInfo `json:"errors,required"`
208
+ Messages []shared. ResponseInfo `json:"messages,required "`
209
+ // Whether the API call was successful
210
+ Success InsightDismissResponseSuccess `json:"success,required "`
211
+ JSON insightDismissResponseJSON `json:"- "`
242
212
}
243
213
244
- func (r InsightDismissParams ) MarshalJSON () (data []byte , err error ) {
245
- return apijson .MarshalRoot (r )
214
+ // insightDismissResponseJSON contains the JSON metadata for the struct
215
+ // [InsightDismissResponse]
216
+ type insightDismissResponseJSON struct {
217
+ Errors apijson.Field
218
+ Messages apijson.Field
219
+ Success apijson.Field
220
+ raw string
221
+ ExtraFields map [string ]apijson.Field
222
+ }
223
+
224
+ func (r * InsightDismissResponse ) UnmarshalJSON (data []byte ) (err error ) {
225
+ return apijson .UnmarshalRoot (data , r )
226
+ }
227
+
228
+ func (r insightDismissResponseJSON ) RawJSON () string {
229
+ return r .raw
246
230
}
247
231
248
- type InsightGetParams struct {
232
+ // Whether the API call was successful
233
+ type InsightDismissResponseSuccess bool
234
+
235
+ const (
236
+ InsightDismissResponseSuccessTrue InsightDismissResponseSuccess = true
237
+ )
238
+
239
+ func (r InsightDismissResponseSuccess ) IsKnown () bool {
240
+ switch r {
241
+ case InsightDismissResponseSuccessTrue :
242
+ return true
243
+ }
244
+ return false
245
+ }
246
+
247
+ type InsightListParams struct {
249
248
// The Account ID to use for this endpoint. Mutually exclusive with the Zone ID.
250
249
AccountID param.Field [string ] `path:"account_id"`
251
250
// The Zone ID to use for this endpoint. Mutually exclusive with the Account ID.
@@ -267,53 +266,22 @@ type InsightGetParams struct {
267
266
SubjectNeq param.Field [[]string ] `query:"subject~neq"`
268
267
}
269
268
270
- // URLQuery serializes [InsightGetParams ]'s query parameters as `url.Values`.
271
- func (r InsightGetParams ) URLQuery () (v url.Values ) {
269
+ // URLQuery serializes [InsightListParams ]'s query parameters as `url.Values`.
270
+ func (r InsightListParams ) URLQuery () (v url.Values ) {
272
271
return apiquery .MarshalWithSettings (r , apiquery.QuerySettings {
273
272
ArrayFormat : apiquery .ArrayQueryFormatRepeat ,
274
273
NestedFormat : apiquery .NestedQueryFormatDots ,
275
274
})
276
275
}
277
276
278
- type InsightGetResponseEnvelope struct {
279
- Errors []shared.ResponseInfo `json:"errors,required"`
280
- Messages []shared.ResponseInfo `json:"messages,required"`
281
- // Whether the API call was successful
282
- Success InsightGetResponseEnvelopeSuccess `json:"success,required"`
283
- Result InsightGetResponse `json:"result"`
284
- JSON insightGetResponseEnvelopeJSON `json:"-"`
285
- }
286
-
287
- // insightGetResponseEnvelopeJSON contains the JSON metadata for the struct
288
- // [InsightGetResponseEnvelope]
289
- type insightGetResponseEnvelopeJSON struct {
290
- Errors apijson.Field
291
- Messages apijson.Field
292
- Success apijson.Field
293
- Result apijson.Field
294
- raw string
295
- ExtraFields map [string ]apijson.Field
296
- }
297
-
298
- func (r * InsightGetResponseEnvelope ) UnmarshalJSON (data []byte ) (err error ) {
299
- return apijson .UnmarshalRoot (data , r )
300
- }
301
-
302
- func (r insightGetResponseEnvelopeJSON ) RawJSON () string {
303
- return r .raw
277
+ type InsightDismissParams struct {
278
+ // The Account ID to use for this endpoint. Mutually exclusive with the Zone ID.
279
+ AccountID param.Field [string ] `path:"account_id"`
280
+ // The Zone ID to use for this endpoint. Mutually exclusive with the Account ID.
281
+ ZoneID param.Field [string ] `path:"zone_id"`
282
+ Dismiss param.Field [bool ] `json:"dismiss"`
304
283
}
305
284
306
- // Whether the API call was successful
307
- type InsightGetResponseEnvelopeSuccess bool
308
-
309
- const (
310
- InsightGetResponseEnvelopeSuccessTrue InsightGetResponseEnvelopeSuccess = true
311
- )
312
-
313
- func (r InsightGetResponseEnvelopeSuccess ) IsKnown () bool {
314
- switch r {
315
- case InsightGetResponseEnvelopeSuccessTrue :
316
- return true
317
- }
318
- return false
285
+ func (r InsightDismissParams ) MarshalJSON () (data []byte , err error ) {
286
+ return apijson .MarshalRoot (r )
319
287
}
0 commit comments