forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
authenticated_origin_pulls.go
65 lines (59 loc) · 2.13 KB
/
authenticated_origin_pulls.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package cloudflare
import (
"encoding/json"
"time"
"github.com/pkg/errors"
)
// AuthenticatedOriginPulls represents global AuthenticatedOriginPulls (tls_client_auth) metadata.
type AuthenticatedOriginPulls struct {
ID string `json:"id"`
Value string `json:"value"`
Editable bool `json:"editable"`
ModifiedOn time.Time `json:"modified_on"`
}
// AuthenticatedOriginPullsResponse represents the response from the global AuthenticatedOriginPulls (tls_client_auth) details endpoint.
type AuthenticatedOriginPullsResponse struct {
Response
Result AuthenticatedOriginPulls `json:"result"`
}
// GetAuthenticatedOriginPullsStatus returns the configuration details for global AuthenticatedOriginPulls (tls_client_auth).
//
// API reference: https://api.cloudflare.com/#zone-settings-get-tls-client-auth-setting
func (api *API) GetAuthenticatedOriginPullsStatus(zoneID string) (AuthenticatedOriginPulls, error) {
uri := "/zones/" + zoneID + "/settings/tls_client_auth"
res, err := api.makeRequest("GET", uri, nil)
if err != nil {
return AuthenticatedOriginPulls{}, errors.Wrap(err, errMakeRequestError)
}
var r AuthenticatedOriginPullsResponse
if err := json.Unmarshal(res, &r); err != nil {
return AuthenticatedOriginPulls{}, errors.Wrap(err, errUnmarshalError)
}
return r.Result, nil
}
// SetAuthenticatedOriginPullsStatus toggles whether global AuthenticatedOriginPulls is enabled for the zone.
//
// API reference: https://api.cloudflare.com/#zone-settings-change-tls-client-auth-setting
func (api *API) SetAuthenticatedOriginPullsStatus(zoneID string, enable bool) (AuthenticatedOriginPulls, error) {
uri := "/zones/" + zoneID + "/settings/tls_client_auth"
var val string
if enable {
val = "on"
} else {
val = "off"
}
params := struct {
Value string `json:"value"`
}{
Value: val,
}
res, err := api.makeRequest("PATCH", uri, params)
if err != nil {
return AuthenticatedOriginPulls{}, errors.Wrap(err, errMakeRequestError)
}
var r AuthenticatedOriginPullsResponse
if err := json.Unmarshal(res, &r); err != nil {
return AuthenticatedOriginPulls{}, errors.Wrap(err, errUnmarshalError)
}
return r.Result, nil
}