/
auditlog.go
151 lines (133 loc) · 5.82 KB
/
auditlog.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package user
import (
"context"
"net/http"
"net/url"
"time"
"github.com/cloudflare/cloudflare-go/v2/internal/apiquery"
"github.com/cloudflare/cloudflare-go/v2/internal/pagination"
"github.com/cloudflare/cloudflare-go/v2/internal/param"
"github.com/cloudflare/cloudflare-go/v2/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v2/internal/shared"
"github.com/cloudflare/cloudflare-go/v2/option"
)
// AuditLogService contains methods and other services that help with interacting
// with the cloudflare API. Note, unlike clients, this service does not read
// variables from the environment automatically. You should not instantiate this
// service directly, and instead use the [NewAuditLogService] method instead.
type AuditLogService struct {
Options []option.RequestOption
}
// NewAuditLogService generates a new service that applies the given options to
// each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewAuditLogService(opts ...option.RequestOption) (r *AuditLogService) {
r = &AuditLogService{}
r.Options = opts
return
}
// Gets a list of audit logs for a user account. Can be filtered by who made the
// change, on which zone, and the timeframe of the change.
func (r *AuditLogService) List(ctx context.Context, query AuditLogListParams, opts ...option.RequestOption) (res *pagination.V4PagePaginationArray[shared.AuditLog], err error) {
var raw *http.Response
opts = append(r.Options, opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "user/audit_logs"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// Gets a list of audit logs for a user account. Can be filtered by who made the
// change, on which zone, and the timeframe of the change.
func (r *AuditLogService) ListAutoPaging(ctx context.Context, query AuditLogListParams, opts ...option.RequestOption) *pagination.V4PagePaginationArrayAutoPager[shared.AuditLog] {
return pagination.NewV4PagePaginationArrayAutoPager(r.List(ctx, query, opts...))
}
type AuditLogListParams struct {
// Finds a specific log by its ID.
ID param.Field[string] `query:"id"`
Action param.Field[AuditLogListParamsAction] `query:"action"`
Actor param.Field[AuditLogListParamsActor] `query:"actor"`
// Limits the returned results to logs older than the specified date. This can be a
// date string `2019-04-30` or an absolute timestamp that conforms to RFC3339.
Before param.Field[time.Time] `query:"before" format:"date-time"`
// Changes the direction of the chronological sorting.
Direction param.Field[AuditLogListParamsDirection] `query:"direction"`
// Indicates that this request is an export of logs in CSV format.
Export param.Field[bool] `query:"export"`
// Indicates whether or not to hide user level audit logs.
HideUserLogs param.Field[bool] `query:"hide_user_logs"`
// Defines which page of results to return.
Page param.Field[float64] `query:"page"`
// Sets the number of results to return per page.
PerPage param.Field[float64] `query:"per_page"`
// Limits the returned results to logs newer than the specified date. This can be a
// date string `2019-04-30` or an absolute timestamp that conforms to RFC3339.
Since param.Field[time.Time] `query:"since" format:"date-time"`
Zone param.Field[AuditLogListParamsZone] `query:"zone"`
}
// URLQuery serializes [AuditLogListParams]'s query parameters as `url.Values`.
func (r AuditLogListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type AuditLogListParamsAction struct {
// Filters by the action type.
Type param.Field[string] `query:"type"`
}
// URLQuery serializes [AuditLogListParamsAction]'s query parameters as
// `url.Values`.
func (r AuditLogListParamsAction) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type AuditLogListParamsActor struct {
// Filters by the email address of the actor that made the change.
Email param.Field[string] `query:"email" format:"email"`
// Filters by the IP address of the request that made the change by specific IP
// address or valid CIDR Range.
IP param.Field[string] `query:"ip"`
}
// URLQuery serializes [AuditLogListParamsActor]'s query parameters as
// `url.Values`.
func (r AuditLogListParamsActor) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Changes the direction of the chronological sorting.
type AuditLogListParamsDirection string
const (
AuditLogListParamsDirectionDesc AuditLogListParamsDirection = "desc"
AuditLogListParamsDirectionAsc AuditLogListParamsDirection = "asc"
)
func (r AuditLogListParamsDirection) IsKnown() bool {
switch r {
case AuditLogListParamsDirectionDesc, AuditLogListParamsDirectionAsc:
return true
}
return false
}
type AuditLogListParamsZone struct {
// Filters by the name of the zone associated to the change.
Name param.Field[string] `query:"name"`
}
// URLQuery serializes [AuditLogListParamsZone]'s query parameters as `url.Values`.
func (r AuditLogListParamsZone) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}