Skip to content

Commit 76fccaa

Browse files
scaleway-botyfodil
andauthored
feat(audit_trail): enable v1alpha1 (scaleway#2338)
Co-authored-by: Yacine Fodil <[email protected]>
1 parent 8d738b4 commit 76fccaa

File tree

2 files changed

+399
-1
lines changed

2 files changed

+399
-1
lines changed
Lines changed: 398 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,398 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
4+
// Package audit_trail provides methods and message types of the audit_trail v1alpha1 API.
5+
package audit_trail
6+
7+
import (
8+
"bytes"
9+
"encoding/json"
10+
"fmt"
11+
"net"
12+
"net/http"
13+
"net/url"
14+
"strings"
15+
"time"
16+
17+
"github.com/scaleway/scaleway-sdk-go/errors"
18+
"github.com/scaleway/scaleway-sdk-go/marshaler"
19+
"github.com/scaleway/scaleway-sdk-go/namegenerator"
20+
"github.com/scaleway/scaleway-sdk-go/parameter"
21+
"github.com/scaleway/scaleway-sdk-go/scw"
22+
)
23+
24+
// always import dependencies
25+
var (
26+
_ fmt.Stringer
27+
_ json.Unmarshaler
28+
_ url.URL
29+
_ net.IP
30+
_ http.Header
31+
_ bytes.Reader
32+
_ time.Time
33+
_ = strings.Join
34+
35+
_ scw.ScalewayRequest
36+
_ marshaler.Duration
37+
_ scw.File
38+
_ = parameter.AddToQuery
39+
_ = namegenerator.GetRandomName
40+
)
41+
42+
type ListEventsRequestOrderBy string
43+
44+
const (
45+
ListEventsRequestOrderByRecordedAtDesc = ListEventsRequestOrderBy("recorded_at_desc")
46+
ListEventsRequestOrderByRecordedAtAsc = ListEventsRequestOrderBy("recorded_at_asc")
47+
)
48+
49+
func (enum ListEventsRequestOrderBy) String() string {
50+
if enum == "" {
51+
// return default value if empty
52+
return "recorded_at_desc"
53+
}
54+
return string(enum)
55+
}
56+
57+
func (enum ListEventsRequestOrderBy) Values() []ListEventsRequestOrderBy {
58+
return []ListEventsRequestOrderBy{
59+
"recorded_at_desc",
60+
"recorded_at_asc",
61+
}
62+
}
63+
64+
func (enum ListEventsRequestOrderBy) MarshalJSON() ([]byte, error) {
65+
return []byte(fmt.Sprintf(`"%s"`, enum)), nil
66+
}
67+
68+
func (enum *ListEventsRequestOrderBy) UnmarshalJSON(data []byte) error {
69+
tmp := ""
70+
71+
if err := json.Unmarshal(data, &tmp); err != nil {
72+
return err
73+
}
74+
75+
*enum = ListEventsRequestOrderBy(ListEventsRequestOrderBy(tmp).String())
76+
return nil
77+
}
78+
79+
type ResourceType string
80+
81+
const (
82+
ResourceTypeUnknownType = ResourceType("unknown_type")
83+
ResourceTypeSecmSecret = ResourceType("secm_secret")
84+
ResourceTypeSecmSecretVersion = ResourceType("secm_secret_version")
85+
ResourceTypeKubeCluster = ResourceType("kube_cluster")
86+
ResourceTypeKubePool = ResourceType("kube_pool")
87+
ResourceTypeKubeNode = ResourceType("kube_node")
88+
)
89+
90+
func (enum ResourceType) String() string {
91+
if enum == "" {
92+
// return default value if empty
93+
return "unknown_type"
94+
}
95+
return string(enum)
96+
}
97+
98+
func (enum ResourceType) Values() []ResourceType {
99+
return []ResourceType{
100+
"unknown_type",
101+
"secm_secret",
102+
"secm_secret_version",
103+
"kube_cluster",
104+
"kube_pool",
105+
"kube_node",
106+
}
107+
}
108+
109+
func (enum ResourceType) MarshalJSON() ([]byte, error) {
110+
return []byte(fmt.Sprintf(`"%s"`, enum)), nil
111+
}
112+
113+
func (enum *ResourceType) UnmarshalJSON(data []byte) error {
114+
tmp := ""
115+
116+
if err := json.Unmarshal(data, &tmp); err != nil {
117+
return err
118+
}
119+
120+
*enum = ResourceType(ResourceType(tmp).String())
121+
return nil
122+
}
123+
124+
// KubernetesClusterInfo: kubernetes cluster info.
125+
type KubernetesClusterInfo struct {
126+
}
127+
128+
// KubernetesNodeInfo: kubernetes node info.
129+
type KubernetesNodeInfo struct {
130+
ID string `json:"id"`
131+
132+
Name string `json:"name"`
133+
}
134+
135+
// KubernetesPoolInfo: kubernetes pool info.
136+
type KubernetesPoolInfo struct {
137+
ID string `json:"id"`
138+
139+
Name string `json:"name"`
140+
}
141+
142+
// SecretManagerSecretInfo: secret manager secret info.
143+
type SecretManagerSecretInfo struct {
144+
Path string `json:"path"`
145+
}
146+
147+
// SecretManagerSecretVersionInfo: secret manager secret version info.
148+
type SecretManagerSecretVersionInfo struct {
149+
Revision uint32 `json:"revision"`
150+
}
151+
152+
// EventPrincipal: event principal.
153+
type EventPrincipal struct {
154+
ID string `json:"id"`
155+
}
156+
157+
// Resource: resource.
158+
type Resource struct {
159+
ID string `json:"id"`
160+
161+
// Type: default value: unknown_type
162+
Type ResourceType `json:"type"`
163+
164+
CreatedAt *time.Time `json:"created_at"`
165+
166+
UpdatedAt *time.Time `json:"updated_at"`
167+
168+
DeletedAt *time.Time `json:"deleted_at"`
169+
170+
Name *string `json:"name"`
171+
172+
// Precisely one of SecmSecretInfo, SecmSecretVersionInfo, KubeClusterInfo, KubePoolInfo, KubeNodeInfo must be set.
173+
SecmSecretInfo *SecretManagerSecretInfo `json:"secm_secret_info,omitempty"`
174+
175+
// Precisely one of SecmSecretInfo, SecmSecretVersionInfo, KubeClusterInfo, KubePoolInfo, KubeNodeInfo must be set.
176+
SecmSecretVersionInfo *SecretManagerSecretVersionInfo `json:"secm_secret_version_info,omitempty"`
177+
178+
// Precisely one of SecmSecretInfo, SecmSecretVersionInfo, KubeClusterInfo, KubePoolInfo, KubeNodeInfo must be set.
179+
KubeClusterInfo *KubernetesClusterInfo `json:"kube_cluster_info,omitempty"`
180+
181+
// Precisely one of SecmSecretInfo, SecmSecretVersionInfo, KubeClusterInfo, KubePoolInfo, KubeNodeInfo must be set.
182+
KubePoolInfo *KubernetesPoolInfo `json:"kube_pool_info,omitempty"`
183+
184+
// Precisely one of SecmSecretInfo, SecmSecretVersionInfo, KubeClusterInfo, KubePoolInfo, KubeNodeInfo must be set.
185+
KubeNodeInfo *KubernetesNodeInfo `json:"kube_node_info,omitempty"`
186+
}
187+
188+
// Event: event.
189+
type Event struct {
190+
ID string `json:"id"`
191+
192+
RecordedAt *time.Time `json:"recorded_at"`
193+
194+
Locality string `json:"locality"`
195+
196+
Principal *EventPrincipal `json:"principal"`
197+
198+
OrganizationID string `json:"organization_id"`
199+
200+
ProjectID *string `json:"project_id"`
201+
202+
SourceIP net.IP `json:"source_ip"`
203+
204+
UserAgent *string `json:"user_agent"`
205+
206+
ProductName string `json:"product_name"`
207+
208+
ServiceName string `json:"service_name"`
209+
210+
MethodName string `json:"method_name"`
211+
212+
Resource *Resource `json:"resource"`
213+
214+
RequestID string `json:"request_id"`
215+
216+
RequestBody *scw.JSONObject `json:"request_body"`
217+
218+
StatusCode uint32 `json:"status_code"`
219+
}
220+
221+
// Product: product.
222+
type Product struct {
223+
Title string `json:"title"`
224+
225+
Name string `json:"name"`
226+
}
227+
228+
// ListEventsRequest: list events request.
229+
type ListEventsRequest struct {
230+
// Region: region to target. If none is passed will use default region from the config.
231+
Region scw.Region `json:"-"`
232+
233+
// ProjectID: (Optional) ID of the Project containing the Audit Trail events.
234+
ProjectID *string `json:"-"`
235+
236+
// OrganizationID: ID of the Organization containing the Audit Trail events.
237+
OrganizationID string `json:"-"`
238+
239+
// ResourceType: (Optional) Returns a paginated list of Scaleway resources' features.
240+
// Default value: unknown_type
241+
ResourceType ResourceType `json:"-"`
242+
243+
// MethodName: (Optional) Name of the method or the API call performed.
244+
MethodName *string `json:"-"`
245+
246+
// Status: (Optional) HTTP status code of the request. Returns either `200` if the request was successful or `403` if the permission was denied.
247+
Status *uint32 `json:"-"`
248+
249+
// RecordedAfter: (Optional) The `recorded_after` parameter defines the earliest timestamp from which Audit Trail events are retrieved. Returns `one hour ago` by default.
250+
RecordedAfter *time.Time `json:"-"`
251+
252+
// RecordedBefore: (Optional) The `recorded_before` parameter defines the latest timestamp up to which Audit Trail events are retrieved. Returns `now` by default.
253+
RecordedBefore *time.Time `json:"-"`
254+
255+
// OrderBy: default value: recorded_at_desc
256+
OrderBy ListEventsRequestOrderBy `json:"-"`
257+
258+
PageSize *uint32 `json:"-"`
259+
260+
PageToken *string `json:"-"`
261+
262+
// ProductName: (Optional) Name of the Scaleway resource in a hyphenated format.
263+
ProductName *string `json:"-"`
264+
}
265+
266+
// ListEventsResponse: list events response.
267+
type ListEventsResponse struct {
268+
// Events: single page of events matching the requested criteria.
269+
Events []*Event `json:"events"`
270+
271+
// NextPageToken: page token to use in following calls to keep listing.
272+
NextPageToken *string `json:"next_page_token"`
273+
}
274+
275+
// ListProductsRequest: list products request.
276+
type ListProductsRequest struct {
277+
// Region: region to target. If none is passed will use default region from the config.
278+
Region scw.Region `json:"-"`
279+
}
280+
281+
// ListProductsResponse: list products response.
282+
type ListProductsResponse struct {
283+
Products []*Product `json:"products"`
284+
285+
TotalCount uint64 `json:"total_count"`
286+
}
287+
288+
// UnsafeGetTotalCount should not be used
289+
// Internal usage only
290+
func (r *ListProductsResponse) UnsafeGetTotalCount() uint64 {
291+
return r.TotalCount
292+
}
293+
294+
// UnsafeAppend should not be used
295+
// Internal usage only
296+
func (r *ListProductsResponse) UnsafeAppend(res interface{}) (uint64, error) {
297+
results, ok := res.(*ListProductsResponse)
298+
if !ok {
299+
return 0, errors.New("%T type cannot be appended to type %T", res, r)
300+
}
301+
302+
r.Products = append(r.Products, results.Products...)
303+
r.TotalCount += uint64(len(results.Products))
304+
return uint64(len(results.Products)), nil
305+
}
306+
307+
// This API allows you to ensure accountability and security by recording events and changes performed within your Scaleway Organization.
308+
type API struct {
309+
client *scw.Client
310+
}
311+
312+
// NewAPI returns a API object from a Scaleway client.
313+
func NewAPI(client *scw.Client) *API {
314+
return &API{
315+
client: client,
316+
}
317+
}
318+
func (s *API) Regions() []scw.Region {
319+
return []scw.Region{scw.RegionFrPar, scw.RegionNlAms}
320+
}
321+
322+
// ListEvents: Retrieve the list of Audit Trail events for a Scaleway Organization and/or Project. You must specify the `organization_id` and optionally, the `project_id`.
323+
func (s *API) ListEvents(req *ListEventsRequest, opts ...scw.RequestOption) (*ListEventsResponse, error) {
324+
var err error
325+
326+
if req.Region == "" {
327+
defaultRegion, _ := s.client.GetDefaultRegion()
328+
req.Region = defaultRegion
329+
}
330+
331+
if req.OrganizationID == "" {
332+
defaultOrganizationID, _ := s.client.GetDefaultOrganizationID()
333+
req.OrganizationID = defaultOrganizationID
334+
}
335+
336+
defaultPageSize, exist := s.client.GetDefaultPageSize()
337+
if (req.PageSize == nil || *req.PageSize == 0) && exist {
338+
req.PageSize = &defaultPageSize
339+
}
340+
341+
query := url.Values{}
342+
parameter.AddToQuery(query, "project_id", req.ProjectID)
343+
parameter.AddToQuery(query, "organization_id", req.OrganizationID)
344+
parameter.AddToQuery(query, "resource_type", req.ResourceType)
345+
parameter.AddToQuery(query, "method_name", req.MethodName)
346+
parameter.AddToQuery(query, "status", req.Status)
347+
parameter.AddToQuery(query, "recorded_after", req.RecordedAfter)
348+
parameter.AddToQuery(query, "recorded_before", req.RecordedBefore)
349+
parameter.AddToQuery(query, "order_by", req.OrderBy)
350+
parameter.AddToQuery(query, "page_size", req.PageSize)
351+
parameter.AddToQuery(query, "page_token", req.PageToken)
352+
parameter.AddToQuery(query, "product_name", req.ProductName)
353+
354+
if fmt.Sprint(req.Region) == "" {
355+
return nil, errors.New("field Region cannot be empty in request")
356+
}
357+
358+
scwReq := &scw.ScalewayRequest{
359+
Method: "GET",
360+
Path: "/audit-trail/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/events",
361+
Query: query,
362+
}
363+
364+
var resp ListEventsResponse
365+
366+
err = s.client.Do(scwReq, &resp, opts...)
367+
if err != nil {
368+
return nil, err
369+
}
370+
return &resp, nil
371+
}
372+
373+
// ListProducts: Retrieve the list of Scaleway resources for which you have Audit Trail events.
374+
func (s *API) ListProducts(req *ListProductsRequest, opts ...scw.RequestOption) (*ListProductsResponse, error) {
375+
var err error
376+
377+
if req.Region == "" {
378+
defaultRegion, _ := s.client.GetDefaultRegion()
379+
req.Region = defaultRegion
380+
}
381+
382+
if fmt.Sprint(req.Region) == "" {
383+
return nil, errors.New("field Region cannot be empty in request")
384+
}
385+
386+
scwReq := &scw.ScalewayRequest{
387+
Method: "GET",
388+
Path: "/audit-trail/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/products",
389+
}
390+
391+
var resp ListProductsResponse
392+
393+
err = s.client.Do(scwReq, &resp, opts...)
394+
if err != nil {
395+
return nil, err
396+
}
397+
return &resp, nil
398+
}

0 commit comments

Comments
 (0)