Skip to content

Commit 69acd57

Browse files
authored
feat(audit_trail): support system events (#2415)
1 parent 00d3b82 commit 69acd57

File tree

5 files changed

+163
-31
lines changed

5 files changed

+163
-31
lines changed

packages_generated/audit_trail/src/v1alpha1/api.gen.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ import {
1010
} from '@scaleway/sdk-client'
1111
import {
1212
unmarshalListAuthenticationEventsResponse,
13+
unmarshalListCombinedEventsResponse,
1314
unmarshalListEventsResponse,
1415
unmarshalListProductsResponse,
1516
} from './marshalling.gen'
1617
import type {
1718
ListAuthenticationEventsRequest,
1819
ListAuthenticationEventsResponse,
20+
ListCombinedEventsRequest,
21+
ListCombinedEventsResponse,
1922
ListEventsRequest,
2023
ListEventsResponse,
2124
ListProductsRequest,
@@ -107,6 +110,32 @@ export class API extends ParentAPI {
107110
unmarshalListAuthenticationEventsResponse,
108111
)
109112

113+
listCombinedEvents = (request: Readonly<ListCombinedEventsRequest> = {}) =>
114+
this.client.fetch<ListCombinedEventsResponse>(
115+
{
116+
method: 'GET',
117+
path: `/audit-trail/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/combined-events`,
118+
urlParams: urlParams(
119+
['order_by', request.orderBy],
120+
[
121+
'organization_id',
122+
request.organizationId ??
123+
this.client.settings.defaultOrganizationId,
124+
],
125+
[
126+
'page_size',
127+
request.pageSize ?? this.client.settings.defaultPageSize,
128+
],
129+
['page_token', request.pageToken],
130+
['project_id', request.projectId],
131+
['recorded_after', request.recordedAfter],
132+
['recorded_before', request.recordedBefore],
133+
['resource_type', request.resourceType],
134+
),
135+
},
136+
unmarshalListCombinedEventsResponse,
137+
)
138+
110139
/**
111140
* Retrieve the list of Scaleway resources for which you have Audit Trail events.
112141
*

packages_generated/audit_trail/src/v1alpha1/index.gen.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export type {
1717
BaremetalSettingInfo,
1818
Event,
1919
EventPrincipal,
20-
EventSystem,
2120
InstanceServerInfo,
2221
IpamIpInfo,
2322
KeyManagerKeyInfo,
@@ -28,6 +27,10 @@ export type {
2827
ListAuthenticationEventsRequest,
2928
ListAuthenticationEventsRequestOrderBy,
3029
ListAuthenticationEventsResponse,
30+
ListCombinedEventsRequest,
31+
ListCombinedEventsRequestOrderBy,
32+
ListCombinedEventsResponse,
33+
ListCombinedEventsResponseCombinedEvent,
3134
ListEventsRequest,
3235
ListEventsRequestOrderBy,
3336
ListEventsResponse,
@@ -46,5 +49,7 @@ export type {
4649
ResourceType,
4750
SecretManagerSecretInfo,
4851
SecretManagerSecretVersionInfo,
52+
SystemEvent,
53+
SystemEventKind,
4954
} from './types.gen'
5055
export * as ValidationRules from './validation-rules.gen'

packages_generated/audit_trail/src/v1alpha1/marshalling.gen.ts

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import type {
1515
BaremetalSettingInfo,
1616
Event,
1717
EventPrincipal,
18-
EventSystem,
1918
InstanceServerInfo,
2019
IpamIpInfo,
2120
KeyManagerKeyInfo,
@@ -24,6 +23,8 @@ import type {
2423
KubernetesNodeInfo,
2524
KubernetesPoolInfo,
2625
ListAuthenticationEventsResponse,
26+
ListCombinedEventsResponse,
27+
ListCombinedEventsResponseCombinedEvent,
2728
ListEventsResponse,
2829
ListProductsResponse,
2930
LoadBalancerAclInfo,
@@ -38,6 +39,7 @@ import type {
3839
Resource,
3940
SecretManagerSecretInfo,
4041
SecretManagerSecretVersionInfo,
42+
SystemEvent,
4143
} from './types.gen'
4244

4345
const unmarshalAccountOrganizationInfo = (
@@ -471,18 +473,6 @@ const unmarshalEventPrincipal = (data: unknown): EventPrincipal => {
471473
} as EventPrincipal
472474
}
473475

474-
const unmarshalEventSystem = (data: unknown): EventSystem => {
475-
if (!isJSONObject(data)) {
476-
throw new TypeError(
477-
`Unmarshalling the type 'EventSystem' failed as data isn't a dictionary.`,
478-
)
479-
}
480-
481-
return {
482-
name: data.name,
483-
} as EventSystem
484-
}
485-
486476
export const unmarshalEvent = (data: unknown): Event => {
487477
if (!isJSONObject(data)) {
488478
throw new TypeError(
@@ -507,11 +497,65 @@ export const unmarshalEvent = (data: unknown): Event => {
507497
serviceName: data.service_name,
508498
sourceIp: data.source_ip,
509499
statusCode: data.status_code,
510-
system: data.system ? unmarshalEventSystem(data.system) : undefined,
511500
userAgent: data.user_agent,
512501
} as Event
513502
}
514503

504+
const unmarshalSystemEvent = (data: unknown): SystemEvent => {
505+
if (!isJSONObject(data)) {
506+
throw new TypeError(
507+
`Unmarshalling the type 'SystemEvent' failed as data isn't a dictionary.`,
508+
)
509+
}
510+
511+
return {
512+
id: data.id,
513+
kind: data.kind,
514+
locality: data.locality,
515+
organizationId: data.organization_id,
516+
productName: data.product_name,
517+
projectId: data.project_id,
518+
recordedAt: unmarshalDate(data.recorded_at),
519+
resources: unmarshalArrayOfObject(data.resources, unmarshalResource),
520+
source: data.source,
521+
systemName: data.system_name,
522+
} as SystemEvent
523+
}
524+
525+
const unmarshalListCombinedEventsResponseCombinedEvent = (
526+
data: unknown,
527+
): ListCombinedEventsResponseCombinedEvent => {
528+
if (!isJSONObject(data)) {
529+
throw new TypeError(
530+
`Unmarshalling the type 'ListCombinedEventsResponseCombinedEvent' failed as data isn't a dictionary.`,
531+
)
532+
}
533+
534+
return {
535+
api: data.api ? unmarshalEvent(data.api) : undefined,
536+
auth: data.auth ? unmarshalAuthenticationEvent(data.auth) : undefined,
537+
system: data.system ? unmarshalSystemEvent(data.system) : undefined,
538+
} as ListCombinedEventsResponseCombinedEvent
539+
}
540+
541+
export const unmarshalListCombinedEventsResponse = (
542+
data: unknown,
543+
): ListCombinedEventsResponse => {
544+
if (!isJSONObject(data)) {
545+
throw new TypeError(
546+
`Unmarshalling the type 'ListCombinedEventsResponse' failed as data isn't a dictionary.`,
547+
)
548+
}
549+
550+
return {
551+
events: unmarshalArrayOfObject(
552+
data.events,
553+
unmarshalListCombinedEventsResponseCombinedEvent,
554+
),
555+
nextPageToken: data.next_page_token,
556+
} as ListCombinedEventsResponse
557+
}
558+
515559
export const unmarshalListEventsResponse = (
516560
data: unknown,
517561
): ListEventsResponse => {

packages_generated/audit_trail/src/v1alpha1/types.gen.ts

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export type ListAuthenticationEventsRequestOrderBy =
2828
| 'recorded_at_desc'
2929
| 'recorded_at_asc'
3030

31+
export type ListCombinedEventsRequestOrderBy =
32+
| 'recorded_at_desc'
33+
| 'recorded_at_asc'
34+
3135
export type ListEventsRequestOrderBy = 'recorded_at_desc' | 'recorded_at_asc'
3236

3337
export type ResourceType =
@@ -76,6 +80,8 @@ export type ResourceType =
7680
| 'sfs_filesystem'
7781
| 'vpc_private_network'
7882

83+
export type SystemEventKind = 'unknown_kind' | 'cron' | 'notification'
84+
7985
export interface AccountOrganizationInfo {}
8086

8187
export interface AccountProjectInfo {
@@ -309,15 +315,6 @@ export interface EventPrincipal {
309315
id: string
310316
}
311317

312-
export interface EventSystem {
313-
name: string
314-
}
315-
316-
export interface ProductService {
317-
name: string
318-
methods: string[]
319-
}
320-
321318
export interface AuthenticationEvent {
322319
/**
323320
* ID of the event.
@@ -385,15 +382,9 @@ export interface Event {
385382
/**
386383
* User or IAM application at the origin of the event.
387384
*
388-
* One-of ('source'): at most one of 'principal', 'system' could be set.
385+
* One-of ('source'): at most one of 'principal' could be set.
389386
*/
390387
principal?: EventPrincipal
391-
/**
392-
* The Scaleway system that performed an action on behalf of the client.
393-
*
394-
* One-of ('source'): at most one of 'principal', 'system' could be set.
395-
*/
396-
system?: EventSystem
397388
/**
398389
* Organization ID containing the event.
399390
*/
@@ -440,6 +431,42 @@ export interface Event {
440431
statusCode: number
441432
}
442433

434+
export interface SystemEvent {
435+
id: string
436+
recordedAt?: Date
437+
locality: string
438+
organizationId: string
439+
projectId?: string
440+
source: string
441+
systemName: string
442+
resources: Resource[]
443+
kind: SystemEventKind
444+
productName: string
445+
}
446+
447+
export interface ProductService {
448+
name: string
449+
methods: string[]
450+
}
451+
452+
export interface ListCombinedEventsResponseCombinedEvent {
453+
/**
454+
*
455+
* One-of ('event'): at most one of 'api', 'auth', 'system' could be set.
456+
*/
457+
api?: Event
458+
/**
459+
*
460+
* One-of ('event'): at most one of 'api', 'auth', 'system' could be set.
461+
*/
462+
auth?: AuthenticationEvent
463+
/**
464+
*
465+
* One-of ('event'): at most one of 'api', 'auth', 'system' could be set.
466+
*/
467+
system?: SystemEvent
468+
}
469+
443470
export interface Product {
444471
/**
445472
* Product title.
@@ -473,6 +500,26 @@ export interface ListAuthenticationEventsResponse {
473500
nextPageToken?: string
474501
}
475502

503+
export type ListCombinedEventsRequest = {
504+
/**
505+
* Region to target. If none is passed will use default region from the config.
506+
*/
507+
region?: ScwRegion
508+
organizationId?: string
509+
projectId?: string
510+
resourceType?: ResourceType
511+
recordedAfter?: Date
512+
recordedBefore?: Date
513+
orderBy?: ListCombinedEventsRequestOrderBy
514+
pageSize?: number
515+
pageToken?: string
516+
}
517+
518+
export interface ListCombinedEventsResponse {
519+
events: ListCombinedEventsResponseCombinedEvent[]
520+
nextPageToken?: string
521+
}
522+
476523
export type ListEventsRequest = {
477524
/**
478525
* Region to target. If none is passed will use default region from the config.

packages_generated/audit_trail/src/v1alpha1/validation-rules.gen.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ export const ListAuthenticationEventsRequest = {
88
},
99
}
1010

11+
export const ListCombinedEventsRequest = {
12+
pageSize: {
13+
greaterThanOrEqual: 1,
14+
lessThanOrEqual: 1000,
15+
},
16+
}
17+
1118
export const ListEventsRequest = {
1219
methodName: {
1320
pattern: /^[a-zA-Z][a-zA-Z0-9_]*$/,

0 commit comments

Comments
 (0)