diff --git a/packages_generated/audit_trail/src/v1alpha1/api.gen.ts b/packages_generated/audit_trail/src/v1alpha1/api.gen.ts index fd9621208..204837f64 100644 --- a/packages_generated/audit_trail/src/v1alpha1/api.gen.ts +++ b/packages_generated/audit_trail/src/v1alpha1/api.gen.ts @@ -9,12 +9,16 @@ import { validatePathParam, } from '@scaleway/sdk-client' import { + marshalCreateExportJobRequest, + unmarshalExportJob, unmarshalListAuthenticationEventsResponse, unmarshalListCombinedEventsResponse, unmarshalListEventsResponse, unmarshalListProductsResponse, } from './marshalling.gen' import type { + CreateExportJobRequest, + ExportJob, ListAuthenticationEventsRequest, ListAuthenticationEventsResponse, ListCombinedEventsRequest, @@ -25,6 +29,10 @@ import type { ListProductsResponse, } from './types.gen' +const jsonContentHeaders = { + 'Content-Type': 'application/json; charset=utf-8', +} + /** * Audit Trail API. @@ -154,4 +162,23 @@ export class API extends ParentAPI { }, unmarshalListProductsResponse, ) + + /** + * 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. + * + * @param request - The request {@link CreateExportJobRequest} + * @returns A Promise of ExportJob + */ + createExportJob = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalCreateExportJobRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/audit-trail/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/export-jobs`, + }, + unmarshalExportJob, + ) } diff --git a/packages_generated/audit_trail/src/v1alpha1/index.gen.ts b/packages_generated/audit_trail/src/v1alpha1/index.gen.ts index 1d4afc0cf..03724ad24 100644 --- a/packages_generated/audit_trail/src/v1alpha1/index.gen.ts +++ b/packages_generated/audit_trail/src/v1alpha1/index.gen.ts @@ -15,8 +15,11 @@ export type { AuthenticationEventResult, BaremetalServerInfo, BaremetalSettingInfo, + CreateExportJobRequest, Event, EventPrincipal, + ExportJob, + ExportJobS3, InstanceServerInfo, IpamIpInfo, KeyManagerKeyInfo, diff --git a/packages_generated/audit_trail/src/v1alpha1/marshalling.gen.ts b/packages_generated/audit_trail/src/v1alpha1/marshalling.gen.ts index dd0534b70..7bc90e6b4 100644 --- a/packages_generated/audit_trail/src/v1alpha1/marshalling.gen.ts +++ b/packages_generated/audit_trail/src/v1alpha1/marshalling.gen.ts @@ -1,7 +1,10 @@ // This file was automatically generated. DO NOT EDIT. // If you have any remark or suggestion do not hesitate to open an issue. + +import type { DefaultValues } from '@scaleway/sdk-client' import { isJSONObject, + resolveOneOf, unmarshalArrayOfObject, unmarshalDate, } from '@scaleway/sdk-client' @@ -13,8 +16,11 @@ import type { AuthenticationEvent, BaremetalServerInfo, BaremetalSettingInfo, + CreateExportJobRequest, Event, EventPrincipal, + ExportJob, + ExportJobS3, InstanceServerInfo, IpamIpInfo, KeyManagerKeyInfo, @@ -42,6 +48,39 @@ import type { SystemEvent, } from './types.gen' +const unmarshalExportJobS3 = (data: unknown): ExportJobS3 => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ExportJobS3' failed as data isn't a dictionary.`, + ) + } + + return { + bucket: data.bucket, + prefix: data.prefix, + projectId: data.project_id, + region: data.region, + } as ExportJobS3 +} + +export const unmarshalExportJob = (data: unknown): ExportJob => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ExportJob' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + id: data.id, + lastRunAt: unmarshalDate(data.last_run_at), + name: data.name, + organizationId: data.organization_id, + s3: data.s3 ? unmarshalExportJobS3(data.s3) : undefined, + tags: data.tags, + } as ExportJob +} + const unmarshalAccountOrganizationInfo = ( data: unknown, ): AccountOrganizationInfo => { @@ -612,3 +651,31 @@ export const unmarshalListProductsResponse = ( totalCount: data.total_count, } as ListProductsResponse } + +const marshalExportJobS3 = ( + request: ExportJobS3, + defaults: DefaultValues, +): Record => ({ + bucket: request.bucket, + prefix: request.prefix, + project_id: request.projectId, + region: request.region, +}) + +export const marshalCreateExportJobRequest = ( + request: CreateExportJobRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name, + organization_id: request.organizationId ?? defaults.defaultOrganizationId, + tags: request.tags !== undefined ? request.tags : undefined, + ...resolveOneOf([ + { + param: 's3', + value: + request.s3 !== undefined + ? marshalExportJobS3(request.s3, defaults) + : undefined, + }, + ]), +}) diff --git a/packages_generated/audit_trail/src/v1alpha1/types.gen.ts b/packages_generated/audit_trail/src/v1alpha1/types.gen.ts index f675f1157..e3db985b7 100644 --- a/packages_generated/audit_trail/src/v1alpha1/types.gen.ts +++ b/packages_generated/audit_trail/src/v1alpha1/types.gen.ts @@ -449,6 +449,16 @@ export interface ProductService { methods: string[] } +export interface ExportJobS3 { + bucket: string + /** + * Region to target. If none is passed will use default region from the config. + */ + region: ScwRegion + prefix?: string + projectId?: string +} + export interface ListCombinedEventsResponseCombinedEvent { /** * @@ -482,6 +492,64 @@ export interface Product { services: ProductService[] } +export type CreateExportJobRequest = { + /** + * Region to target. If none is passed will use default region from the config. + */ + region?: ScwRegion + /** + * ID of the Organization to target. + */ + organizationId?: string + /** + * Name of the export. + */ + name: string + /** + * The configuration specifying the bucket where the audit trail events will be exported. + * + * One-of ('destination'): at most one of 's3' could be set. + */ + s3?: ExportJobS3 + /** + * Tags of the export. + */ + tags?: Record +} + +export interface ExportJob { + /** + * ID of the export job. + */ + id: string + /** + * ID of the targeted Organization. + */ + organizationId: string + /** + * Name of the export. + */ + name: string + /** + * Destination in an S3 storage. + * + * One-of ('destination'): at most one of 's3' could be set. + */ + s3?: ExportJobS3 + /** + * Export job creation date. + */ + createdAt?: Date + /** + * Last export date. + */ + lastRunAt?: Date + /** + * Tags of the export. + */ + tags: Record +} + export type ListAuthenticationEventsRequest = { /** * Region to target. If none is passed will use default region from the config. diff --git a/packages_generated/audit_trail/src/v1alpha1/validation-rules.gen.ts b/packages_generated/audit_trail/src/v1alpha1/validation-rules.gen.ts index 46a977aad..9b8993204 100644 --- a/packages_generated/audit_trail/src/v1alpha1/validation-rules.gen.ts +++ b/packages_generated/audit_trail/src/v1alpha1/validation-rules.gen.ts @@ -1,6 +1,29 @@ // This file was automatically generated. DO NOT EDIT. // If you have any remark or suggestion do not hesitate to open an issue. +export const CreateExportJobRequest = { + name: { + maxLength: 255, + minLength: 1, + pattern: /^[a-zA-Z0-9]([-_.a-zA-Z0-9]*[a-zA-Z0-9])?$/, + }, +} + +export const ExportJobS3 = { + bucket: { + maxLength: 63, + minLength: 3, + pattern: /^[a-z0-9][a-z0-9.-]{2,}$/, + }, + prefix: { + maxLength: 255, + pattern: /^[a-zA-Z0-9\._\-]+(?:\/[a-zA-Z0-9\._\-]+)*$/, + }, + region: { + pattern: /^[a-z]{2}-[a-z]{3}$/, + }, +} + export const ListAuthenticationEventsRequest = { pageSize: { greaterThanOrEqual: 1,