Skip to content

Commit cf778ac

Browse files
authored
feat(audit_trail): add event export (#2447)
1 parent 3b6457d commit cf778ac

File tree

5 files changed

+188
-0
lines changed

5 files changed

+188
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ import {
99
validatePathParam,
1010
} from '@scaleway/sdk-client'
1111
import {
12+
marshalCreateExportJobRequest,
13+
unmarshalExportJob,
1214
unmarshalListAuthenticationEventsResponse,
1315
unmarshalListCombinedEventsResponse,
1416
unmarshalListEventsResponse,
1517
unmarshalListProductsResponse,
1618
} from './marshalling.gen'
1719
import type {
20+
CreateExportJobRequest,
21+
ExportJob,
1822
ListAuthenticationEventsRequest,
1923
ListAuthenticationEventsResponse,
2024
ListCombinedEventsRequest,
@@ -25,6 +29,10 @@ import type {
2529
ListProductsResponse,
2630
} from './types.gen'
2731

32+
const jsonContentHeaders = {
33+
'Content-Type': 'application/json; charset=utf-8',
34+
}
35+
2836
/**
2937
* Audit Trail API.
3038
@@ -154,4 +162,23 @@ export class API extends ParentAPI {
154162
},
155163
unmarshalListProductsResponse,
156164
)
165+
166+
/**
167+
* Create an export job. Create an export job for a specified organization. This allows you to export audit trail events to a destination, such as an S3 bucket. The request requires the organization ID, a name for the export, and a destination configuration.
168+
*
169+
* @param request - The request {@link CreateExportJobRequest}
170+
* @returns A Promise of ExportJob
171+
*/
172+
createExportJob = (request: Readonly<CreateExportJobRequest>) =>
173+
this.client.fetch<ExportJob>(
174+
{
175+
body: JSON.stringify(
176+
marshalCreateExportJobRequest(request, this.client.settings),
177+
),
178+
headers: jsonContentHeaders,
179+
method: 'POST',
180+
path: `/audit-trail/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/export-jobs`,
181+
},
182+
unmarshalExportJob,
183+
)
157184
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ export type {
1515
AuthenticationEventResult,
1616
BaremetalServerInfo,
1717
BaremetalSettingInfo,
18+
CreateExportJobRequest,
1819
Event,
1920
EventPrincipal,
21+
ExportJob,
22+
ExportJobS3,
2023
InstanceServerInfo,
2124
IpamIpInfo,
2225
KeyManagerKeyInfo,

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// This file was automatically generated. DO NOT EDIT.
22
// If you have any remark or suggestion do not hesitate to open an issue.
3+
4+
import type { DefaultValues } from '@scaleway/sdk-client'
35
import {
46
isJSONObject,
7+
resolveOneOf,
58
unmarshalArrayOfObject,
69
unmarshalDate,
710
} from '@scaleway/sdk-client'
@@ -13,8 +16,11 @@ import type {
1316
AuthenticationEvent,
1417
BaremetalServerInfo,
1518
BaremetalSettingInfo,
19+
CreateExportJobRequest,
1620
Event,
1721
EventPrincipal,
22+
ExportJob,
23+
ExportJobS3,
1824
InstanceServerInfo,
1925
IpamIpInfo,
2026
KeyManagerKeyInfo,
@@ -42,6 +48,39 @@ import type {
4248
SystemEvent,
4349
} from './types.gen'
4450

51+
const unmarshalExportJobS3 = (data: unknown): ExportJobS3 => {
52+
if (!isJSONObject(data)) {
53+
throw new TypeError(
54+
`Unmarshalling the type 'ExportJobS3' failed as data isn't a dictionary.`,
55+
)
56+
}
57+
58+
return {
59+
bucket: data.bucket,
60+
prefix: data.prefix,
61+
projectId: data.project_id,
62+
region: data.region,
63+
} as ExportJobS3
64+
}
65+
66+
export const unmarshalExportJob = (data: unknown): ExportJob => {
67+
if (!isJSONObject(data)) {
68+
throw new TypeError(
69+
`Unmarshalling the type 'ExportJob' failed as data isn't a dictionary.`,
70+
)
71+
}
72+
73+
return {
74+
createdAt: unmarshalDate(data.created_at),
75+
id: data.id,
76+
lastRunAt: unmarshalDate(data.last_run_at),
77+
name: data.name,
78+
organizationId: data.organization_id,
79+
s3: data.s3 ? unmarshalExportJobS3(data.s3) : undefined,
80+
tags: data.tags,
81+
} as ExportJob
82+
}
83+
4584
const unmarshalAccountOrganizationInfo = (
4685
data: unknown,
4786
): AccountOrganizationInfo => {
@@ -612,3 +651,31 @@ export const unmarshalListProductsResponse = (
612651
totalCount: data.total_count,
613652
} as ListProductsResponse
614653
}
654+
655+
const marshalExportJobS3 = (
656+
request: ExportJobS3,
657+
defaults: DefaultValues,
658+
): Record<string, unknown> => ({
659+
bucket: request.bucket,
660+
prefix: request.prefix,
661+
project_id: request.projectId,
662+
region: request.region,
663+
})
664+
665+
export const marshalCreateExportJobRequest = (
666+
request: CreateExportJobRequest,
667+
defaults: DefaultValues,
668+
): Record<string, unknown> => ({
669+
name: request.name,
670+
organization_id: request.organizationId ?? defaults.defaultOrganizationId,
671+
tags: request.tags !== undefined ? request.tags : undefined,
672+
...resolveOneOf([
673+
{
674+
param: 's3',
675+
value:
676+
request.s3 !== undefined
677+
? marshalExportJobS3(request.s3, defaults)
678+
: undefined,
679+
},
680+
]),
681+
})

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,16 @@ export interface ProductService {
449449
methods: string[]
450450
}
451451

452+
export interface ExportJobS3 {
453+
bucket: string
454+
/**
455+
* Region to target. If none is passed will use default region from the config.
456+
*/
457+
region: ScwRegion
458+
prefix?: string
459+
projectId?: string
460+
}
461+
452462
export interface ListCombinedEventsResponseCombinedEvent {
453463
/**
454464
*
@@ -482,6 +492,64 @@ export interface Product {
482492
services: ProductService[]
483493
}
484494

495+
export type CreateExportJobRequest = {
496+
/**
497+
* Region to target. If none is passed will use default region from the config.
498+
*/
499+
region?: ScwRegion
500+
/**
501+
* ID of the Organization to target.
502+
*/
503+
organizationId?: string
504+
/**
505+
* Name of the export.
506+
*/
507+
name: string
508+
/**
509+
* The configuration specifying the bucket where the audit trail events will be exported.
510+
*
511+
* One-of ('destination'): at most one of 's3' could be set.
512+
*/
513+
s3?: ExportJobS3
514+
/**
515+
* Tags of the export.
516+
*/
517+
tags?: Record<string, string>
518+
}
519+
520+
export interface ExportJob {
521+
/**
522+
* ID of the export job.
523+
*/
524+
id: string
525+
/**
526+
* ID of the targeted Organization.
527+
*/
528+
organizationId: string
529+
/**
530+
* Name of the export.
531+
*/
532+
name: string
533+
/**
534+
* Destination in an S3 storage.
535+
*
536+
* One-of ('destination'): at most one of 's3' could be set.
537+
*/
538+
s3?: ExportJobS3
539+
/**
540+
* Export job creation date.
541+
*/
542+
createdAt?: Date
543+
/**
544+
* Last export date.
545+
*/
546+
lastRunAt?: Date
547+
/**
548+
* Tags of the export.
549+
*/
550+
tags: Record<string, string>
551+
}
552+
485553
export type ListAuthenticationEventsRequest = {
486554
/**
487555
* 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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
// This file was automatically generated. DO NOT EDIT.
22
// If you have any remark or suggestion do not hesitate to open an issue.
33

4+
export const CreateExportJobRequest = {
5+
name: {
6+
maxLength: 255,
7+
minLength: 1,
8+
pattern: /^[a-zA-Z0-9]([-_.a-zA-Z0-9]*[a-zA-Z0-9])?$/,
9+
},
10+
}
11+
12+
export const ExportJobS3 = {
13+
bucket: {
14+
maxLength: 63,
15+
minLength: 3,
16+
pattern: /^[a-z0-9][a-z0-9.-]{2,}$/,
17+
},
18+
prefix: {
19+
maxLength: 255,
20+
pattern: /^[a-zA-Z0-9\._\-]+(?:\/[a-zA-Z0-9\._\-]+)*$/,
21+
},
22+
region: {
23+
pattern: /^[a-z]{2}-[a-z]{3}$/,
24+
},
25+
}
26+
427
export const ListAuthenticationEventsRequest = {
528
pageSize: {
629
greaterThanOrEqual: 1,

0 commit comments

Comments
 (0)