diff --git a/.changelog/1070.txt b/.changelog/1070.txt new file mode 100644 index 00000000000..d3586c87e3f --- /dev/null +++ b/.changelog/1070.txt @@ -0,0 +1,3 @@ +```release-note:bug +email_routing_rules: Fix response for email routing catch all rule. +``` \ No newline at end of file diff --git a/email_routing_rules.go b/email_routing_rules.go index aa3a694d17e..22101b62455 100644 --- a/email_routing_rules.go +++ b/email_routing_rules.go @@ -76,6 +76,11 @@ type EmailRoutingCatchAllRule struct { Actions []EmailRoutingRuleAction `json:"actions,omitempty"` } +type EmailRoutingCatchAllRuleResponse struct { + Result EmailRoutingCatchAllRule `json:"result"` + Response +} + // ListEmailRoutingRules Lists existing routing rules. // // API reference: https://api.cloudflare.com/#email-routing-routing-rules-list-routing-rules @@ -227,21 +232,19 @@ func (api *API) GetEmailRoutingCatchAllRule(ctx context.Context, rc *ResourceCon if rc.Identifier == "" { return EmailRoutingCatchAllRule{}, ErrMissingZoneID } - uri := fmt.Sprintf("/zones/%s/email/routing/rules/catch_all", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) if err != nil { return EmailRoutingCatchAllRule{}, err } - var r EmailRoutingCatchAllRule + var r EmailRoutingCatchAllRuleResponse err = json.Unmarshal(res, &r) if err != nil { return EmailRoutingCatchAllRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } - return r, nil + return r.Result, nil } // UpdateEmailRoutingCatchAllRule Enable or disable catch-all routing rule, or change action to forward to specific destination address. @@ -259,11 +262,11 @@ func (api *API) UpdateEmailRoutingCatchAllRule(ctx context.Context, rc *Resource return EmailRoutingCatchAllRule{}, err } - var r EmailRoutingCatchAllRule + var r EmailRoutingCatchAllRuleResponse err = json.Unmarshal(res, &r) if err != nil { return EmailRoutingCatchAllRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } - return r, nil + return r.Result, nil } diff --git a/email_routing_rules_test.go b/email_routing_rules_test.go index 502f88ef2e0..5a3cdb4d7c1 100644 --- a/email_routing_rules_test.go +++ b/email_routing_rules_test.go @@ -280,22 +280,28 @@ func TestEmailRouting_GetAllRule(t *testing.T) { assert.Equal(t, http.MethodGet, r.Method, "Expected method 'PUT', got %s", r.Method) w.Header().Set("content-type", "application/json") fmt.Fprint(w, `{ - "tag": "a7e6fb77503c41d8a7f3113c6918f10c", - "name": "Rule send to user@example.net", - "enabled": true, - "matchers": [ - { - "type": "all" - } - ], - "actions": [ - { - "type": "forward", - "value": [ - "destinationaddress@example.net" - ] - } - ] + "result": { + "tag": "a7e6fb77503c41d8a7f3113c6918f10c", + "name": "Send to user@example.net rule.", + "matchers": [ + { + "type": "all" + } + ], + "actions": [ + { + "type": "forward", + "value": [ + "destinationaddress@example.net" + ] + } + ], + "enabled": true, + "priority": 2147483647 + }, + "success": true, + "errors": [], + "messages": [] }`) }) @@ -306,7 +312,7 @@ func TestEmailRouting_GetAllRule(t *testing.T) { want := EmailRoutingCatchAllRule{ Tag: "a7e6fb77503c41d8a7f3113c6918f10c", - Name: "Rule send to user@example.net", + Name: "Send to user@example.net rule.", Enabled: BoolPtr(true), Matchers: []EmailRoutingRuleMatcher{ { @@ -335,22 +341,28 @@ func TestEmailRouting_UpdateAllRule(t *testing.T) { assert.Equal(t, http.MethodPut, r.Method, "Expected method 'PUT', got %s", r.Method) w.Header().Set("content-type", "application/json") fmt.Fprint(w, `{ - "tag": "a7e6fb77503c41d8a7f3113c6918f10c", - "name": "Rule send to user@example.net", - "enabled": true, - "matchers": [ - { - "type": "all" - } - ], - "actions": [ - { - "type": "forward", - "value": [ - "destinationaddress@example.net" - ] - } - ] + "result": { + "tag": "a7e6fb77503c41d8a7f3113c6918f10c", + "name": "Send to user@example.net rule.", + "matchers": [ + { + "type": "all" + } + ], + "actions": [ + { + "type": "forward", + "value": [ + "destinationaddress@example.net" + ] + } + ], + "enabled": true, + "priority": 2147483647 + }, + "success": true, + "errors": [], + "messages": [] }`) }) @@ -361,7 +373,7 @@ func TestEmailRouting_UpdateAllRule(t *testing.T) { want := EmailRoutingCatchAllRule{ Tag: "a7e6fb77503c41d8a7f3113c6918f10c", - Name: "Rule send to user@example.net", + Name: "Send to user@example.net rule.", Enabled: BoolPtr(true), Matchers: []EmailRoutingRuleMatcher{ {