forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlp_payload_log.go
71 lines (56 loc) · 2.18 KB
/
dlp_payload_log.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
68
69
70
71
package cloudflare
import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"
)
type DLPPayloadLogSettings struct {
PublicKey string `json:"public_key,omitempty"`
// Only present in responses
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}
type GetDLPPayloadLogSettingsParams struct{}
type DLPPayloadLogSettingsResponse struct {
Response
Result DLPPayloadLogSettings `json:"result"`
}
// GetDLPPayloadLogSettings gets the current DLP payload logging settings.
//
// API reference: https://api.cloudflare.com/#dlp-payload-log-settings-get-settings
func (api *API) GetDLPPayloadLogSettings(ctx context.Context, rc *ResourceContainer, params GetDLPPayloadLogSettingsParams) (DLPPayloadLogSettings, error) {
if rc.Identifier == "" {
return DLPPayloadLogSettings{}, ErrMissingResourceIdentifier
}
uri := buildURI(fmt.Sprintf("/%s/%s/dlp/payload_log", rc.Level, rc.Identifier), nil)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return DLPPayloadLogSettings{}, err
}
var dlpPayloadLogSettingsResponse DLPPayloadLogSettingsResponse
err = json.Unmarshal(res, &dlpPayloadLogSettingsResponse)
if err != nil {
return DLPPayloadLogSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return dlpPayloadLogSettingsResponse.Result, nil
}
// UpdateDLPPayloadLogSettings sets the current DLP payload logging settings to new values.
//
// API reference: https://api.cloudflare.com/#dlp-payload-log-settings-update-settings
func (api *API) UpdateDLPPayloadLogSettings(ctx context.Context, rc *ResourceContainer, settings DLPPayloadLogSettings) (DLPPayloadLogSettings, error) {
if rc.Identifier == "" {
return DLPPayloadLogSettings{}, ErrMissingResourceIdentifier
}
uri := buildURI(fmt.Sprintf("/%s/%s/dlp/payload_log", rc.Level, rc.Identifier), nil)
res, err := api.makeRequestContext(ctx, http.MethodPut, uri, settings)
if err != nil {
return DLPPayloadLogSettings{}, err
}
var dlpPayloadLogSettingsResponse DLPPayloadLogSettingsResponse
err = json.Unmarshal(res, &dlpPayloadLogSettingsResponse)
if err != nil {
return DLPPayloadLogSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return dlpPayloadLogSettingsResponse.Result, nil
}