diff --git a/.changelog/3901.txt b/.changelog/3901.txt new file mode 100644 index 00000000000..b7450bd5fe9 --- /dev/null +++ b/.changelog/3901.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +custom_hostname: add support for `cloudflare_branding` SSL flag +``` \ No newline at end of file diff --git a/custom_hostname.go b/custom_hostname.go index b625b723263..fac89afe982 100644 --- a/custom_hostname.go +++ b/custom_hostname.go @@ -78,9 +78,10 @@ type CustomHostnameSSL struct { // Deprecated: use ValidationRecords. // If there a single validation record, this will equal ValidationRecords[0] for backwards compatibility. SSLValidationRecord - ValidationRecords []SSLValidationRecord `json:"validation_records,omitempty"` - ValidationErrors []SSLValidationError `json:"validation_errors,omitempty"` - BundleMethod string `json:"bundle_method,omitempty"` + ValidationRecords []SSLValidationRecord `json:"validation_records,omitempty"` + ValidationErrors []SSLValidationError `json:"validation_errors,omitempty"` + BundleMethod string `json:"bundle_method,omitempty"` + CloudflareBranding *bool `json:"cloudflare_branding,omitempty"` } // CustomMetadata defines custom metadata for the hostname. This requires logic to be implemented by Cloudflare to act on the data provided. diff --git a/custom_hostname_test.go b/custom_hostname_test.go index c38bbbee347..fbcb7d42de8 100644 --- a/custom_hostname_test.go +++ b/custom_hostname_test.go @@ -406,6 +406,86 @@ func TestCustomHostname_CreateCustomHostname_CustomOriginSNI(t *testing.T) { } } +func TestCustomHostname_CreateCustomHostname_CloudflareBrandingSSL(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/zones/foo/custom_hostnames", func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method) + + w.Header().Set("content-type", "application/json") + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, ` +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9", + "hostname": "app.example.com", + "custom_origin_server": "example.app.com", + "ssl": { + "status": "pending_validation", + "method": "http", + "type": "dv", + "wildcard": false, + "certificate_authority": "google" + }, + "status": "pending", + "verification_errors": [ + "None of the A or AAAA records are owned by this account and the pre-generated ownership verification token was not found." + ], + "ownership_verification": { + "type": "txt", + "name": "_cf-custom-hostname.app.example.com", + "value": "38ddbedc-6cc3-4a4c-af67-9c5b02344ce0" + }, + "ownership_verification_http": { + "http_url": "http://app.example.com/.well-known/cf-custom-hostname-challenge/37c82d20-99fb-490e-ba0a-489fa483b776", + "http_body": "38ddbedc-6cc3-4a4c-af67-9c5b02344ce0" + }, + "created_at": "2020-02-06T18:11:23.531995Z" + } +}`) + }) + + response, err := client.CreateCustomHostname(context.Background(), "foo", CustomHostname{Hostname: "app.example.com", CustomOriginServer: "example.app.com", SSL: &CustomHostnameSSL{Method: "http", Type: "dv", CloudflareBranding: BoolPtr(true)}}) + + createdAt, _ := time.Parse(time.RFC3339, "2020-02-06T18:11:23.531995Z") + + want := &CustomHostnameResponse{ + Result: CustomHostname{ + ID: "0d89c70d-ad9f-4843-b99f-6cc0252067e9", + Hostname: "app.example.com", + CustomOriginServer: "example.app.com", + SSL: &CustomHostnameSSL{ + Type: "dv", + Method: "http", + Status: "pending_validation", + Wildcard: BoolPtr(false), + CertificateAuthority: "google", + }, + Status: "pending", + VerificationErrors: []string{"None of the A or AAAA records are owned by this account and the pre-generated ownership verification token was not found."}, + OwnershipVerification: CustomHostnameOwnershipVerification{ + Type: "txt", + Name: "_cf-custom-hostname.app.example.com", + Value: "38ddbedc-6cc3-4a4c-af67-9c5b02344ce0", + }, + OwnershipVerificationHTTP: CustomHostnameOwnershipVerificationHTTP{ + HTTPUrl: "http://app.example.com/.well-known/cf-custom-hostname-challenge/37c82d20-99fb-490e-ba0a-489fa483b776", + HTTPBody: "38ddbedc-6cc3-4a4c-af67-9c5b02344ce0", + }, + CreatedAt: &createdAt, + }, + Response: Response{Success: true, Errors: []ResponseInfo{}, Messages: []ResponseInfo{}}, + } + + if assert.NoError(t, err) { + assert.Equal(t, want, response) + } +} + func TestCustomHostname_CustomHostnames(t *testing.T) { setup() defer teardown()