forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logpull.go
56 lines (49 loc) · 1.82 KB
/
logpull.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
package cloudflare
import (
"encoding/json"
"github.com/pkg/errors"
)
// LogpullRetentionConfiguration describes a the structure of a Logpull Retention
// payload.
type LogpullRetentionConfiguration struct {
Flag bool `json:"flag"`
}
// LogpullRetentionConfigurationResponse is the API response, containing the
// Logpull retention result.
type LogpullRetentionConfigurationResponse struct {
Response
Result LogpullRetentionConfiguration `json:"result"`
}
// GetLogpullRetentionFlag gets the current setting flag.
//
// API reference: https://developers.cloudflare.com/logs/logpull-api/enabling-log-retention/
func (api *API) GetLogpullRetentionFlag(zoneID string) (*LogpullRetentionConfiguration, error) {
uri := "/zones/" + zoneID + "/logs/control/retention/flag"
res, err := api.makeRequest("GET", uri, nil)
if err != nil {
return &LogpullRetentionConfiguration{}, errors.Wrap(err, errMakeRequestError)
}
var r LogpullRetentionConfigurationResponse
err = json.Unmarshal(res, &r)
if err != nil {
return nil, errors.Wrap(err, errUnmarshalError)
}
return &r.Result, nil
}
// SetLogpullRetentionFlag updates the retention flag to the defined boolean.
//
// API reference: https://developers.cloudflare.com/logs/logpull-api/enabling-log-retention/
func (api *API) SetLogpullRetentionFlag(zoneID string, enabled bool) (*LogpullRetentionConfiguration, error) {
uri := "/zones/" + zoneID + "/logs/control/retention/flag"
flagPayload := LogpullRetentionConfiguration{Flag: enabled}
res, err := api.makeRequest("POST", uri, flagPayload)
if err != nil {
return &LogpullRetentionConfiguration{}, errors.Wrap(err, errMakeRequestError)
}
var r LogpullRetentionConfigurationResponse
err = json.Unmarshal(res, &r)
if err != nil {
return &LogpullRetentionConfiguration{}, errors.Wrap(err, errMakeRequestError)
}
return &r.Result, nil
}