Skip to content

Commit bfa52fb

Browse files
Pablo Caminopatryk
authored andcommitted
Custom Hostname update function added (#407)
1 parent 4a4622e commit bfa52fb

File tree

2 files changed

+75
-4
lines changed

2 files changed

+75
-4
lines changed

custom_hostname.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,19 @@ type CustomHostnameListResponse struct {
5555
// hostname in the given zone.
5656
//
5757
// API reference: https://api.cloudflare.com/#custom-hostname-for-a-zone-update-custom-hostname-configuration
58-
func (api *API) UpdateCustomHostnameSSL(zoneID string, customHostnameID string, ssl CustomHostnameSSL) (CustomHostname, error) {
59-
return CustomHostname{}, errors.New("Not implemented")
58+
func (api *API) UpdateCustomHostnameSSL(zoneID string, customHostnameID string, ssl CustomHostnameSSL) (*CustomHostnameResponse, error) {
59+
uri := "/zones/" + zoneID + "/custom_hostnames/" + customHostnameID
60+
res, err := api.makeRequest("PATCH", uri, ssl)
61+
if err != nil {
62+
return nil, errors.Wrap(err, errMakeRequestError)
63+
}
64+
65+
var response *CustomHostnameResponse
66+
err = json.Unmarshal(res, &response)
67+
if err != nil {
68+
return nil, errors.Wrap(err, errUnmarshalError)
69+
}
70+
return response, nil
6071
}
6172

6273
// DeleteCustomHostname deletes a custom hostname (and any issued SSL

custom_hostname_test.go

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ func TestCustomHostname_CreateCustomHostname_CustomOrigin(t *testing.T) {
119119

120120
want := &CustomHostnameResponse{
121121
Result: CustomHostname{
122-
ID: "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
123-
Hostname: "app.example.com",
122+
ID: "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
123+
Hostname: "app.example.com",
124124
CustomOriginServer: "example.app.com",
125125
SSL: CustomHostnameSSL{
126126
Type: "dv",
@@ -250,3 +250,63 @@ func TestCustomHostname_CustomHostname(t *testing.T) {
250250
assert.Equal(t, want, customHostname)
251251
}
252252
}
253+
254+
func TestCustomHostname_UpdateCustomHostnameSSL(t *testing.T) {
255+
setup()
256+
defer teardown()
257+
258+
mux.HandleFunc("/zones/foo/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9", func(w http.ResponseWriter, r *http.Request) {
259+
assert.Equal(t, "PATCH", r.Method, "Expected method 'PATCH', got %s", r.Method)
260+
261+
w.Header().Set("content-type", "application/json")
262+
w.WriteHeader(http.StatusCreated)
263+
fmt.Fprintf(w, `
264+
{
265+
"success": true,
266+
"errors": [],
267+
"messages": [],
268+
"result": {
269+
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
270+
"hostname": "app.example.com",
271+
"custom_origin_server": "example.app.com",
272+
"ssl": {
273+
"status": "pending_validation",
274+
"method": "cname",
275+
"type": "dv",
276+
"cname_target": "dcv.digicert.com",
277+
"cname": "810b7d5f01154524b961ba0cd578acc2.app.example.com",
278+
"settings": {
279+
"http2": "off",
280+
"tls_1_3": "on"
281+
}
282+
}
283+
}
284+
}`)
285+
})
286+
287+
response, err := client.UpdateCustomHostnameSSL("foo", "0d89c70d-ad9f-4843-b99f-6cc0252067e9", CustomHostnameSSL{Method: "cname", Type: "dv", Settings: CustomHostnameSSLSettings{HTTP2: "off", TLS13: "on"}})
288+
289+
want := &CustomHostnameResponse{
290+
Result: CustomHostname{
291+
ID: "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
292+
Hostname: "app.example.com",
293+
CustomOriginServer: "example.app.com",
294+
SSL: CustomHostnameSSL{
295+
Type: "dv",
296+
Method: "cname",
297+
Status: "pending_validation",
298+
CnameTarget: "dcv.digicert.com",
299+
CnameName: "810b7d5f01154524b961ba0cd578acc2.app.example.com",
300+
Settings: CustomHostnameSSLSettings{
301+
HTTP2: "off",
302+
TLS13: "on",
303+
},
304+
},
305+
},
306+
Response: Response{Success: true, Errors: []ResponseInfo{}, Messages: []ResponseInfo{}},
307+
}
308+
309+
if assert.NoError(t, err) {
310+
assert.Equal(t, want, response)
311+
}
312+
}

0 commit comments

Comments
 (0)