forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
authenticated_origin_pulls.go
67 lines (61 loc) · 2.2 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
66
67
package cloudflare
import (
"context"
"fmt"
"net/http"
"time"
"github.com/goccy/go-json"
)
// 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(ctx context.Context, zoneID string) (AuthenticatedOriginPulls, error) {
uri := fmt.Sprintf("/zones/%s/settings/tls_client_auth", zoneID)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return AuthenticatedOriginPulls{}, err
}
var r AuthenticatedOriginPullsResponse
if err := json.Unmarshal(res, &r); err != nil {
return AuthenticatedOriginPulls{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
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(ctx context.Context, zoneID string, enable bool) (AuthenticatedOriginPulls, error) {
uri := fmt.Sprintf("/zones/%s/settings/tls_client_auth", zoneID)
var val string
if enable {
val = "on"
} else {
val = "off"
}
params := struct {
Value string `json:"value"`
}{
Value: val,
}
res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, params)
if err != nil {
return AuthenticatedOriginPulls{}, err
}
var r AuthenticatedOriginPullsResponse
if err := json.Unmarshal(res, &r); err != nil {
return AuthenticatedOriginPulls{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return r.Result, nil
}