forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
universal_ssl.go
50 lines (43 loc) · 1.6 KB
/
universal_ssl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package cloudflare
import (
"encoding/json"
"github.com/pkg/errors"
)
// UniversalSSLSetting represents a universal ssl setting's properties.
type UniversalSSLSetting struct {
Enabled bool `json:"enabled"`
}
type universalSSLSettingResponse struct {
Response
Result UniversalSSLSetting `json:"result"`
}
// UniversalSSLSettingDetails returns the details for a universal ssl setting
//
// API reference: https://api.cloudflare.com/#universal-ssl-settings-for-a-zone-universal-ssl-settings-details
func (api *API) UniversalSSLSettingDetails(zoneID string) (UniversalSSLSetting, error) {
uri := "/zones/" + zoneID + "/ssl/universal/settings"
res, err := api.makeRequest("GET", uri, nil)
if err != nil {
return UniversalSSLSetting{}, errors.Wrap(err, errMakeRequestError)
}
var r universalSSLSettingResponse
if err := json.Unmarshal(res, &r); err != nil {
return UniversalSSLSetting{}, errors.Wrap(err, errUnmarshalError)
}
return r.Result, nil
}
// EditUniversalSSLSetting edits the uniersal ssl setting for a zone
//
// API reference: https://api.cloudflare.com/#universal-ssl-settings-for-a-zone-edit-universal-ssl-settings
func (api *API) EditUniversalSSLSetting(zoneID string, setting UniversalSSLSetting) (UniversalSSLSetting, error) {
uri := "/zones/" + zoneID + "/ssl/universal/settings"
res, err := api.makeRequest("PATCH", uri, setting)
if err != nil {
return UniversalSSLSetting{}, errors.Wrap(err, errMakeRequestError)
}
var r universalSSLSettingResponse
if err := json.Unmarshal(res, &r); err != nil {
return UniversalSSLSetting{}, errors.Wrap(err, errUnmarshalError)
}
return r.Result, nil
}