Skip to content

Commit 5ae8ffb

Browse files
committedJan 30, 2025
feat(api): api update (#3862)
1 parent 5becccc commit 5ae8ffb

File tree

3 files changed

+113
-29
lines changed

3 files changed

+113
-29
lines changed
 

‎.stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 1508
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-bc60197588d3f199481d8107cd85189ef798eaf150d8c55e809be937c0542507.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-af20b95a31279c374d10db6b99abfb69221518a5339ac1864f4a87a18c358701.yml

‎alerting/policy.go

+104-12
Original file line numberDiff line numberDiff line change
@@ -138,37 +138,129 @@ func (r *PolicyService) Get(ctx context.Context, policyID string, query PolicyGe
138138
return
139139
}
140140

141-
type Mechanism map[string][]MechanismItem
141+
// List of IDs that will be used when dispatching a notification. IDs for email
142+
// type will be the email address.
143+
type Mechanism struct {
144+
Email []MechanismEmail `json:"email"`
145+
Pagerduty []MechanismPagerduty `json:"pagerduty"`
146+
Webhooks []MechanismWebhook `json:"webhooks"`
147+
JSON mechanismJSON `json:"-"`
148+
}
149+
150+
// mechanismJSON contains the JSON metadata for the struct [Mechanism]
151+
type mechanismJSON struct {
152+
Email apijson.Field
153+
Pagerduty apijson.Field
154+
Webhooks apijson.Field
155+
raw string
156+
ExtraFields map[string]apijson.Field
157+
}
142158

143-
type MechanismItem struct {
144-
// UUID
145-
ID string `json:"id"`
146-
JSON mechanismItemJSON `json:"-"`
159+
func (r *Mechanism) UnmarshalJSON(data []byte) (err error) {
160+
return apijson.UnmarshalRoot(data, r)
147161
}
148162

149-
// mechanismItemJSON contains the JSON metadata for the struct [MechanismItem]
150-
type mechanismItemJSON struct {
163+
func (r mechanismJSON) RawJSON() string {
164+
return r.raw
165+
}
166+
167+
type MechanismEmail struct {
168+
// The email address
169+
ID string `json:"id"`
170+
JSON mechanismEmailJSON `json:"-"`
171+
}
172+
173+
// mechanismEmailJSON contains the JSON metadata for the struct [MechanismEmail]
174+
type mechanismEmailJSON struct {
151175
ID apijson.Field
152176
raw string
153177
ExtraFields map[string]apijson.Field
154178
}
155179

156-
func (r *MechanismItem) UnmarshalJSON(data []byte) (err error) {
180+
func (r *MechanismEmail) UnmarshalJSON(data []byte) (err error) {
157181
return apijson.UnmarshalRoot(data, r)
158182
}
159183

160-
func (r mechanismItemJSON) RawJSON() string {
184+
func (r mechanismEmailJSON) RawJSON() string {
161185
return r.raw
162186
}
163187

164-
type MechanismParam map[string][]MechanismItemParam
188+
type MechanismPagerduty struct {
189+
// UUID
190+
ID string `json:"id"`
191+
JSON mechanismPagerdutyJSON `json:"-"`
192+
}
193+
194+
// mechanismPagerdutyJSON contains the JSON metadata for the struct
195+
// [MechanismPagerduty]
196+
type mechanismPagerdutyJSON struct {
197+
ID apijson.Field
198+
raw string
199+
ExtraFields map[string]apijson.Field
200+
}
201+
202+
func (r *MechanismPagerduty) UnmarshalJSON(data []byte) (err error) {
203+
return apijson.UnmarshalRoot(data, r)
204+
}
165205

166-
type MechanismItemParam struct {
206+
func (r mechanismPagerdutyJSON) RawJSON() string {
207+
return r.raw
208+
}
209+
210+
type MechanismWebhook struct {
167211
// UUID
212+
ID string `json:"id"`
213+
JSON mechanismWebhookJSON `json:"-"`
214+
}
215+
216+
// mechanismWebhookJSON contains the JSON metadata for the struct
217+
// [MechanismWebhook]
218+
type mechanismWebhookJSON struct {
219+
ID apijson.Field
220+
raw string
221+
ExtraFields map[string]apijson.Field
222+
}
223+
224+
func (r *MechanismWebhook) UnmarshalJSON(data []byte) (err error) {
225+
return apijson.UnmarshalRoot(data, r)
226+
}
227+
228+
func (r mechanismWebhookJSON) RawJSON() string {
229+
return r.raw
230+
}
231+
232+
// List of IDs that will be used when dispatching a notification. IDs for email
233+
// type will be the email address.
234+
type MechanismParam struct {
235+
Email param.Field[[]MechanismEmailParam] `json:"email"`
236+
Pagerduty param.Field[[]MechanismPagerdutyParam] `json:"pagerduty"`
237+
Webhooks param.Field[[]MechanismWebhookParam] `json:"webhooks"`
238+
}
239+
240+
func (r MechanismParam) MarshalJSON() (data []byte, err error) {
241+
return apijson.MarshalRoot(r)
242+
}
243+
244+
type MechanismEmailParam struct {
245+
// The email address
168246
ID param.Field[string] `json:"id"`
169247
}
170248

171-
func (r MechanismItemParam) MarshalJSON() (data []byte, err error) {
249+
func (r MechanismEmailParam) MarshalJSON() (data []byte, err error) {
250+
return apijson.MarshalRoot(r)
251+
}
252+
253+
type MechanismPagerdutyParam struct {
254+
}
255+
256+
func (r MechanismPagerdutyParam) MarshalJSON() (data []byte, err error) {
257+
return apijson.MarshalRoot(r)
258+
}
259+
260+
type MechanismWebhookParam struct {
261+
}
262+
263+
func (r MechanismWebhookParam) MarshalJSON() (data []byte, err error) {
172264
return apijson.MarshalRoot(r)
173265
}
174266

‎alerting/policy_test.go

+8-16
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,11 @@ func TestPolicyNewWithOptionalParams(t *testing.T) {
3333
AlertType: cloudflare.F(alerting.PolicyNewParamsAlertTypeAccessCustomCertificateExpirationType),
3434
Enabled: cloudflare.F(true),
3535
Mechanisms: cloudflare.F(alerting.MechanismParam{
36-
"email": []alerting.MechanismItemParam{{
36+
Email: cloudflare.F([]alerting.MechanismEmailParam{{
3737
ID: cloudflare.F("test@example.com"),
38-
}},
39-
"pagerduty": []alerting.MechanismItemParam{{
40-
ID: cloudflare.F("e8133a15-00a4-4d69-aec1-32f70c51f6e5"),
41-
}},
42-
"webhooks": []alerting.MechanismItemParam{{
43-
ID: cloudflare.F("14cc1190-5d2b-4b98-a696-c424cb2ad05f"),
44-
}},
38+
}}),
39+
Pagerduty: cloudflare.F([]alerting.MechanismPagerdutyParam{{}}),
40+
Webhooks: cloudflare.F([]alerting.MechanismWebhookParam{{}}),
4541
}),
4642
Name: cloudflare.F("SSL Notification Event Policy"),
4743
AlertInterval: cloudflare.F("30m"),
@@ -166,15 +162,11 @@ func TestPolicyUpdateWithOptionalParams(t *testing.T) {
166162
Zones: cloudflare.F([]string{"string"}),
167163
}),
168164
Mechanisms: cloudflare.F(alerting.MechanismParam{
169-
"email": []alerting.MechanismItemParam{{
165+
Email: cloudflare.F([]alerting.MechanismEmailParam{{
170166
ID: cloudflare.F("test@example.com"),
171-
}},
172-
"pagerduty": []alerting.MechanismItemParam{{
173-
ID: cloudflare.F("e8133a15-00a4-4d69-aec1-32f70c51f6e5"),
174-
}},
175-
"webhooks": []alerting.MechanismItemParam{{
176-
ID: cloudflare.F("14cc1190-5d2b-4b98-a696-c424cb2ad05f"),
177-
}},
167+
}}),
168+
Pagerduty: cloudflare.F([]alerting.MechanismPagerdutyParam{{}}),
169+
Webhooks: cloudflare.F([]alerting.MechanismWebhookParam{{}}),
178170
}),
179171
Name: cloudflare.F("SSL Notification Event Policy"),
180172
},

0 commit comments

Comments
 (0)
Please sign in to comment.