Skip to content

Commit 1ba44cd

Browse files
authored
feat(audit-trail): add support for ListCombinedEvents (scaleway#2730)
1 parent a469890 commit 1ba44cd

File tree

1 file changed

+199
-17
lines changed

1 file changed

+199
-17
lines changed

api/audit_trail/v1alpha1/audit_trail_sdk.go

Lines changed: 199 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,43 @@ func (enum *ListAuthenticationEventsRequestOrderBy) UnmarshalJSON(data []byte) e
274274
return nil
275275
}
276276

277+
type ListCombinedEventsRequestOrderBy string
278+
279+
const (
280+
ListCombinedEventsRequestOrderByRecordedAtDesc = ListCombinedEventsRequestOrderBy("recorded_at_desc")
281+
ListCombinedEventsRequestOrderByRecordedAtAsc = ListCombinedEventsRequestOrderBy("recorded_at_asc")
282+
)
283+
284+
func (enum ListCombinedEventsRequestOrderBy) String() string {
285+
if enum == "" {
286+
// return default value if empty
287+
return string(ListCombinedEventsRequestOrderByRecordedAtDesc)
288+
}
289+
return string(enum)
290+
}
291+
292+
func (enum ListCombinedEventsRequestOrderBy) Values() []ListCombinedEventsRequestOrderBy {
293+
return []ListCombinedEventsRequestOrderBy{
294+
"recorded_at_desc",
295+
"recorded_at_asc",
296+
}
297+
}
298+
299+
func (enum ListCombinedEventsRequestOrderBy) MarshalJSON() ([]byte, error) {
300+
return []byte(fmt.Sprintf(`"%s"`, enum)), nil
301+
}
302+
303+
func (enum *ListCombinedEventsRequestOrderBy) UnmarshalJSON(data []byte) error {
304+
tmp := ""
305+
306+
if err := json.Unmarshal(data, &tmp); err != nil {
307+
return err
308+
}
309+
310+
*enum = ListCombinedEventsRequestOrderBy(ListCombinedEventsRequestOrderBy(tmp).String())
311+
return nil
312+
}
313+
277314
type ListEventsRequestOrderBy string
278315

279316
const (
@@ -432,6 +469,45 @@ func (enum *ResourceType) UnmarshalJSON(data []byte) error {
432469
return nil
433470
}
434471

472+
type SystemEventKind string
473+
474+
const (
475+
SystemEventKindUnknownKind = SystemEventKind("unknown_kind")
476+
SystemEventKindCron = SystemEventKind("cron")
477+
SystemEventKindNotification = SystemEventKind("notification")
478+
)
479+
480+
func (enum SystemEventKind) String() string {
481+
if enum == "" {
482+
// return default value if empty
483+
return string(SystemEventKindUnknownKind)
484+
}
485+
return string(enum)
486+
}
487+
488+
func (enum SystemEventKind) Values() []SystemEventKind {
489+
return []SystemEventKind{
490+
"unknown_kind",
491+
"cron",
492+
"notification",
493+
}
494+
}
495+
496+
func (enum SystemEventKind) MarshalJSON() ([]byte, error) {
497+
return []byte(fmt.Sprintf(`"%s"`, enum)), nil
498+
}
499+
500+
func (enum *SystemEventKind) UnmarshalJSON(data []byte) error {
501+
tmp := ""
502+
503+
if err := json.Unmarshal(data, &tmp); err != nil {
504+
return err
505+
}
506+
507+
*enum = SystemEventKind(SystemEventKind(tmp).String())
508+
return nil
509+
}
510+
435511
// AccountOrganizationInfo: account organization info.
436512
type AccountOrganizationInfo struct{}
437513

@@ -656,18 +732,6 @@ type EventPrincipal struct {
656732
ID string `json:"id"`
657733
}
658734

659-
// EventSystem: event system.
660-
type EventSystem struct {
661-
Name string `json:"name"`
662-
}
663-
664-
// ProductService: product service.
665-
type ProductService struct {
666-
Name string `json:"name"`
667-
668-
Methods []string `json:"methods"`
669-
}
670-
671735
// AuthenticationEvent: authentication event.
672736
type AuthenticationEvent struct {
673737
// ID: ID of the event.
@@ -725,13 +789,9 @@ type Event struct {
725789
Locality string `json:"locality"`
726790

727791
// Principal: user or IAM application at the origin of the event.
728-
// Precisely one of Principal, System must be set.
792+
// Precisely one of Principal must be set.
729793
Principal *EventPrincipal `json:"principal,omitempty"`
730794

731-
// System: the Scaleway system that performed an action on behalf of the client.
732-
// Precisely one of Principal, System must be set.
733-
System *EventSystem `json:"system,omitempty"`
734-
735795
// OrganizationID: organization ID containing the event.
736796
OrganizationID string `json:"organization_id"`
737797

@@ -766,6 +826,49 @@ type Event struct {
766826
StatusCode uint32 `json:"status_code"`
767827
}
768828

829+
// SystemEvent: system event.
830+
type SystemEvent struct {
831+
ID string `json:"id"`
832+
833+
RecordedAt *time.Time `json:"recorded_at"`
834+
835+
Locality string `json:"locality"`
836+
837+
OrganizationID string `json:"organization_id"`
838+
839+
ProjectID *string `json:"project_id"`
840+
841+
Source string `json:"source"`
842+
843+
SystemName string `json:"system_name"`
844+
845+
Resources []*Resource `json:"resources"`
846+
847+
// Kind: default value: unknown_kind
848+
Kind SystemEventKind `json:"kind"`
849+
850+
ProductName string `json:"product_name"`
851+
}
852+
853+
// ProductService: product service.
854+
type ProductService struct {
855+
Name string `json:"name"`
856+
857+
Methods []string `json:"methods"`
858+
}
859+
860+
// ListCombinedEventsResponseCombinedEvent: list combined events response combined event.
861+
type ListCombinedEventsResponseCombinedEvent struct {
862+
// Precisely one of API, Auth, System must be set.
863+
API *Event `json:"api,omitempty"`
864+
865+
// Precisely one of API, Auth, System must be set.
866+
Auth *AuthenticationEvent `json:"auth,omitempty"`
867+
868+
// Precisely one of API, Auth, System must be set.
869+
System *SystemEvent `json:"system,omitempty"`
870+
}
871+
769872
// Product: product.
770873
type Product struct {
771874
// Title: product title.
@@ -804,6 +907,37 @@ type ListAuthenticationEventsResponse struct {
804907
NextPageToken *string `json:"next_page_token"`
805908
}
806909

910+
// ListCombinedEventsRequest: list combined events request.
911+
type ListCombinedEventsRequest struct {
912+
// Region: region to target. If none is passed will use default region from the config.
913+
Region scw.Region `json:"-"`
914+
915+
OrganizationID string `json:"-"`
916+
917+
ProjectID *string `json:"-"`
918+
919+
// ResourceType: default value: unknown_type
920+
ResourceType ResourceType `json:"-"`
921+
922+
RecordedAfter *time.Time `json:"-"`
923+
924+
RecordedBefore *time.Time `json:"-"`
925+
926+
// OrderBy: default value: recorded_at_desc
927+
OrderBy ListCombinedEventsRequestOrderBy `json:"-"`
928+
929+
PageSize *uint32 `json:"-"`
930+
931+
PageToken *string `json:"-"`
932+
}
933+
934+
// ListCombinedEventsResponse: list combined events response.
935+
type ListCombinedEventsResponse struct {
936+
Events []*ListCombinedEventsResponseCombinedEvent `json:"events"`
937+
938+
NextPageToken *string `json:"next_page_token"`
939+
}
940+
807941
// ListEventsRequest: list events request.
808942
type ListEventsRequest struct {
809943
// Region: region to target. If none is passed will use default region from the config.
@@ -1017,6 +1151,54 @@ func (s *API) ListAuthenticationEvents(req *ListAuthenticationEventsRequest, opt
10171151
return &resp, nil
10181152
}
10191153

1154+
// ListCombinedEvents:
1155+
func (s *API) ListCombinedEvents(req *ListCombinedEventsRequest, opts ...scw.RequestOption) (*ListCombinedEventsResponse, error) {
1156+
var err error
1157+
1158+
if req.Region == "" {
1159+
defaultRegion, _ := s.client.GetDefaultRegion()
1160+
req.Region = defaultRegion
1161+
}
1162+
1163+
if req.OrganizationID == "" {
1164+
defaultOrganizationID, _ := s.client.GetDefaultOrganizationID()
1165+
req.OrganizationID = defaultOrganizationID
1166+
}
1167+
1168+
defaultPageSize, exist := s.client.GetDefaultPageSize()
1169+
if (req.PageSize == nil || *req.PageSize == 0) && exist {
1170+
req.PageSize = &defaultPageSize
1171+
}
1172+
1173+
query := url.Values{}
1174+
parameter.AddToQuery(query, "organization_id", req.OrganizationID)
1175+
parameter.AddToQuery(query, "project_id", req.ProjectID)
1176+
parameter.AddToQuery(query, "resource_type", req.ResourceType)
1177+
parameter.AddToQuery(query, "recorded_after", req.RecordedAfter)
1178+
parameter.AddToQuery(query, "recorded_before", req.RecordedBefore)
1179+
parameter.AddToQuery(query, "order_by", req.OrderBy)
1180+
parameter.AddToQuery(query, "page_size", req.PageSize)
1181+
parameter.AddToQuery(query, "page_token", req.PageToken)
1182+
1183+
if fmt.Sprint(req.Region) == "" {
1184+
return nil, errors.New("field Region cannot be empty in request")
1185+
}
1186+
1187+
scwReq := &scw.ScalewayRequest{
1188+
Method: "GET",
1189+
Path: "/audit-trail/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/combined-events",
1190+
Query: query,
1191+
}
1192+
1193+
var resp ListCombinedEventsResponse
1194+
1195+
err = s.client.Do(scwReq, &resp, opts...)
1196+
if err != nil {
1197+
return nil, err
1198+
}
1199+
return &resp, nil
1200+
}
1201+
10201202
// ListProducts: Retrieve the list of Scaleway resources for which you have Audit Trail events.
10211203
func (s *API) ListProducts(req *ListProductsRequest, opts ...scw.RequestOption) (*ListProductsResponse, error) {
10221204
var err error

0 commit comments

Comments
 (0)