forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteams_audit_ssh_settings.go
86 lines (69 loc) · 2.47 KB
/
teams_audit_ssh_settings.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package cloudflare
import (
"context"
"fmt"
"net/http"
"time"
"github.com/goccy/go-json"
)
// TeamsList represents a Teams List.
type AuditSSHSettings struct {
PublicKey string `json:"public_key"`
SeedUUID string `json:"seed_id"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
}
type AuditSSHSettingsResponse struct {
Result AuditSSHSettings `json:"result"`
Response
ResultInfo `json:"result_info"`
}
type GetAuditSSHSettingsParams struct{}
type UpdateAuditSSHSettingsParams struct {
PublicKey string `json:"public_key"`
}
// GetAuditSSHSettings returns the accounts zt audit ssh settings.
//
// API reference: https://api.cloudflare.com/#zero-trust-get-audit-ssh-settings
func (api *API) GetAuditSSHSettings(ctx context.Context, rc *ResourceContainer, params GetAuditSSHSettingsParams) (AuditSSHSettings, ResultInfo, error) {
if rc.Level != AccountRouteLevel {
return AuditSSHSettings{}, ResultInfo{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level)
}
uri := fmt.Sprintf("/%s/%s/gateway/audit_ssh_settings", rc.Level, rc.Identifier)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return AuditSSHSettings{}, ResultInfo{}, err
}
var auditSSHSettingsResponse AuditSSHSettingsResponse
err = json.Unmarshal(res, &auditSSHSettingsResponse)
if err != nil {
return AuditSSHSettings{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return auditSSHSettingsResponse.Result, auditSSHSettingsResponse.ResultInfo, nil
}
// UpdateAuditSSHSettings updates an existing zt audit ssh setting.
//
// API reference: https://api.cloudflare.com/#zero-trust-update-audit-ssh-settings
func (api *API) UpdateAuditSSHSettings(ctx context.Context, rc *ResourceContainer, params UpdateAuditSSHSettingsParams) (AuditSSHSettings, error) {
if rc.Level != AccountRouteLevel {
return AuditSSHSettings{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level)
}
if rc.Identifier == "" {
return AuditSSHSettings{}, ErrMissingAccountID
}
uri := fmt.Sprintf(
"/%s/%s/gateway/audit_ssh_settings",
rc.Level,
rc.Identifier,
)
res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params)
if err != nil {
return AuditSSHSettings{}, err
}
var auditSSHSettingsResponse AuditSSHSettingsResponse
err = json.Unmarshal(res, &auditSSHSettingsResponse)
if err != nil {
return AuditSSHSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return auditSSHSettingsResponse.Result, nil
}