diff --git a/packages/clients/src/api/audit_trail/index.gen.ts b/packages/clients/src/api/audit_trail/index.gen.ts new file mode 100644 index 000000000..6dec29b44 --- /dev/null +++ b/packages/clients/src/api/audit_trail/index.gen.ts @@ -0,0 +1,6 @@ +/** + * This file is automatically generated from /scripts/generate.js PLEASE DO NOT + * EDIT HERE + */ + +export * as v1alpha1 from './v1alpha1/index.gen' diff --git a/packages/clients/src/api/audit_trail/v1alpha1/api.gen.ts b/packages/clients/src/api/audit_trail/v1alpha1/api.gen.ts new file mode 100644 index 000000000..a0ee8dc34 --- /dev/null +++ b/packages/clients/src/api/audit_trail/v1alpha1/api.gen.ts @@ -0,0 +1,78 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import { API as ParentAPI, urlParams, validatePathParam } from '../../../bridge' +import type { Region } from '../../../bridge' +import { + unmarshalListEventsResponse, + unmarshalListProductsResponse, +} from './marshalling.gen' +import type { + ListEventsRequest, + ListEventsResponse, + ListProductsRequest, + ListProductsResponse, +} from './types.gen' + +/** + * Audit Trail API. + * + * This API allows you to ensure accountability and security by recording events + * and changes performed within your Scaleway Organization. + */ +export class API extends ParentAPI { + /** Lists the available regions of the API. */ + public static readonly LOCALITIES: Region[] = ['fr-par', 'nl-ams'] + + /** + * List events. 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`. + * + * @param request - The request {@link ListEventsRequest} + * @returns A Promise of ListEventsResponse + */ + listEvents = (request: Readonly = {}) => + this.client.fetch( + { + method: 'GET', + path: `/audit-trail/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/events`, + urlParams: urlParams( + ['method_name', request.methodName], + ['order_by', request.orderBy], + [ + 'organization_id', + request.organizationId ?? + this.client.settings.defaultOrganizationId, + ], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ['page_token', request.pageToken], + ['product_name', request.productName], + ['project_id', request.projectId], + ['recorded_after', request.recordedAfter], + ['recorded_before', request.recordedBefore], + ['resource_type', request.resourceType], + ['status', request.status], + ), + }, + unmarshalListEventsResponse, + ) + + /** + * Retrieve the list of Scaleway resources for which you have Audit Trail + * events. + * + * @param request - The request {@link ListProductsRequest} + * @returns A Promise of ListProductsResponse + */ + listProducts = (request: Readonly = {}) => + this.client.fetch( + { + method: 'GET', + path: `/audit-trail/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/products`, + }, + unmarshalListProductsResponse, + ) +} diff --git a/packages/clients/src/api/audit_trail/v1alpha1/index.gen.ts b/packages/clients/src/api/audit_trail/v1alpha1/index.gen.ts new file mode 100644 index 000000000..ddef97699 --- /dev/null +++ b/packages/clients/src/api/audit_trail/v1alpha1/index.gen.ts @@ -0,0 +1,21 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +export { API } from './api.gen' +export type { + Event, + EventPrincipal, + KubernetesClusterInfo, + KubernetesNodeInfo, + KubernetesPoolInfo, + ListEventsRequest, + ListEventsRequestOrderBy, + ListEventsResponse, + ListProductsRequest, + ListProductsResponse, + Product, + Resource, + ResourceType, + SecretManagerSecretInfo, + SecretManagerSecretVersionInfo, +} from './types.gen' +export * as ValidationRules from './validation-rules.gen' diff --git a/packages/clients/src/api/audit_trail/v1alpha1/marshalling.gen.ts b/packages/clients/src/api/audit_trail/v1alpha1/marshalling.gen.ts new file mode 100644 index 000000000..525c4cbfe --- /dev/null +++ b/packages/clients/src/api/audit_trail/v1alpha1/marshalling.gen.ts @@ -0,0 +1,201 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import { + isJSONObject, + unmarshalArrayOfObject, + unmarshalDate, +} from '../../../bridge' +import type { + Event, + EventPrincipal, + KubernetesClusterInfo, + KubernetesNodeInfo, + KubernetesPoolInfo, + ListEventsResponse, + ListProductsResponse, + Product, + Resource, + SecretManagerSecretInfo, + SecretManagerSecretVersionInfo, +} from './types.gen' + +const unmarshalKubernetesClusterInfo = ( + data: unknown, +): KubernetesClusterInfo => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'KubernetesClusterInfo' failed as data isn't a dictionary.`, + ) + } + + return {} as KubernetesClusterInfo +} + +const unmarshalKubernetesNodeInfo = (data: unknown): KubernetesNodeInfo => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'KubernetesNodeInfo' failed as data isn't a dictionary.`, + ) + } + + return { + id: data.id, + name: data.name, + } as KubernetesNodeInfo +} + +const unmarshalKubernetesPoolInfo = (data: unknown): KubernetesPoolInfo => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'KubernetesPoolInfo' failed as data isn't a dictionary.`, + ) + } + + return { + id: data.id, + name: data.name, + } as KubernetesPoolInfo +} + +const unmarshalSecretManagerSecretInfo = ( + data: unknown, +): SecretManagerSecretInfo => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SecretManagerSecretInfo' failed as data isn't a dictionary.`, + ) + } + + return { + path: data.path, + } as SecretManagerSecretInfo +} + +const unmarshalSecretManagerSecretVersionInfo = ( + data: unknown, +): SecretManagerSecretVersionInfo => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SecretManagerSecretVersionInfo' failed as data isn't a dictionary.`, + ) + } + + return { + revision: data.revision, + } as SecretManagerSecretVersionInfo +} + +const unmarshalEventPrincipal = (data: unknown): EventPrincipal => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'EventPrincipal' failed as data isn't a dictionary.`, + ) + } + + return { + id: data.id, + } as EventPrincipal +} + +export const unmarshalResource = (data: unknown): Resource => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Resource' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + deletedAt: unmarshalDate(data.deleted_at), + id: data.id, + kubeClusterInfo: data.kube_cluster_info + ? unmarshalKubernetesClusterInfo(data.kube_cluster_info) + : undefined, + kubeNodeInfo: data.kube_node_info + ? unmarshalKubernetesNodeInfo(data.kube_node_info) + : undefined, + kubePoolInfo: data.kube_pool_info + ? unmarshalKubernetesPoolInfo(data.kube_pool_info) + : undefined, + name: data.name, + secmSecretInfo: data.secm_secret_info + ? unmarshalSecretManagerSecretInfo(data.secm_secret_info) + : undefined, + secmSecretVersionInfo: data.secm_secret_version_info + ? unmarshalSecretManagerSecretVersionInfo(data.secm_secret_version_info) + : undefined, + type: data.type, + updatedAt: unmarshalDate(data.updated_at), + } as Resource +} + +export const unmarshalEvent = (data: unknown): Event => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Event' failed as data isn't a dictionary.`, + ) + } + + return { + id: data.id, + locality: data.locality, + methodName: data.method_name, + organizationId: data.organization_id, + principal: data.principal + ? unmarshalEventPrincipal(data.principal) + : undefined, + productName: data.product_name, + projectId: data.project_id, + recordedAt: unmarshalDate(data.recorded_at), + requestBody: data.request_body, + requestId: data.request_id, + resource: data.resource ? unmarshalResource(data.resource) : undefined, + serviceName: data.service_name, + sourceIp: data.source_ip, + statusCode: data.status_code, + userAgent: data.user_agent, + } as Event +} + +export const unmarshalListEventsResponse = ( + data: unknown, +): ListEventsResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListEventsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + events: unmarshalArrayOfObject(data.events, unmarshalEvent), + nextPageToken: data.next_page_token, + } as ListEventsResponse +} + +const unmarshalProduct = (data: unknown): Product => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Product' failed as data isn't a dictionary.`, + ) + } + + return { + name: data.name, + title: data.title, + } as Product +} + +export const unmarshalListProductsResponse = ( + data: unknown, +): ListProductsResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListProductsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + products: unmarshalArrayOfObject(data.products, unmarshalProduct), + totalCount: data.total_count, + } as ListProductsResponse +} diff --git a/packages/clients/src/api/audit_trail/v1alpha1/types.gen.ts b/packages/clients/src/api/audit_trail/v1alpha1/types.gen.ts new file mode 100644 index 000000000..ea1122aef --- /dev/null +++ b/packages/clients/src/api/audit_trail/v1alpha1/types.gen.ts @@ -0,0 +1,151 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import type { Region } from '../../../bridge' + +export type ListEventsRequestOrderBy = 'recorded_at_desc' | 'recorded_at_asc' + +export type ResourceType = + | 'unknown_type' + | 'secm_secret' + | 'secm_secret_version' + | 'kube_cluster' + | 'kube_pool' + | 'kube_node' + +export interface KubernetesClusterInfo {} + +export interface KubernetesNodeInfo { + id: string + name: string +} + +export interface KubernetesPoolInfo { + id: string + name: string +} + +export interface SecretManagerSecretInfo { + path: string +} + +export interface SecretManagerSecretVersionInfo { + revision: number +} + +export interface EventPrincipal { + id: string +} + +export interface Resource { + id: string + type: ResourceType + createdAt?: Date + updatedAt?: Date + deletedAt?: Date + name?: string + /** + * One-of ('info'): at most one of 'secmSecretInfo', 'secmSecretVersionInfo', + * 'kubeClusterInfo', 'kubePoolInfo', 'kubeNodeInfo' could be set. + */ + secmSecretInfo?: SecretManagerSecretInfo + /** + * One-of ('info'): at most one of 'secmSecretInfo', 'secmSecretVersionInfo', + * 'kubeClusterInfo', 'kubePoolInfo', 'kubeNodeInfo' could be set. + */ + secmSecretVersionInfo?: SecretManagerSecretVersionInfo + /** + * One-of ('info'): at most one of 'secmSecretInfo', 'secmSecretVersionInfo', + * 'kubeClusterInfo', 'kubePoolInfo', 'kubeNodeInfo' could be set. + */ + kubeClusterInfo?: KubernetesClusterInfo + /** + * One-of ('info'): at most one of 'secmSecretInfo', 'secmSecretVersionInfo', + * 'kubeClusterInfo', 'kubePoolInfo', 'kubeNodeInfo' could be set. + */ + kubePoolInfo?: KubernetesPoolInfo + /** + * One-of ('info'): at most one of 'secmSecretInfo', 'secmSecretVersionInfo', + * 'kubeClusterInfo', 'kubePoolInfo', 'kubeNodeInfo' could be set. + */ + kubeNodeInfo?: KubernetesNodeInfo +} + +export interface Event { + id: string + recordedAt?: Date + locality: string + principal?: EventPrincipal + organizationId: string + projectId?: string + sourceIp: string + userAgent?: string + productName: string + serviceName: string + methodName: string + resource?: Resource + requestId: string + requestBody?: Record + statusCode: number +} + +export interface Product { + title: string + name: string +} + +export type ListEventsRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** (Optional) ID of the Project containing the Audit Trail events. */ + projectId?: string + /** ID of the Organization containing the Audit Trail events. */ + organizationId?: string + /** (Optional) Returns a paginated list of Scaleway resources' features. */ + resourceType?: ResourceType + /** (Optional) Name of the method or the API call performed. */ + methodName?: string + /** + * (Optional) HTTP status code of the request. Returns either `200` if the + * request was successful or `403` if the permission was denied. + */ + status?: number + /** + * (Optional) The `recorded_after` parameter defines the earliest timestamp + * from which Audit Trail events are retrieved. Returns `one hour ago` by + * default. + */ + recordedAfter?: Date + /** + * (Optional) The `recorded_before` parameter defines the latest timestamp up + * to which Audit Trail events are retrieved. Returns `now` by default. + */ + recordedBefore?: Date + orderBy?: ListEventsRequestOrderBy + pageSize?: number + pageToken?: string + /** (Optional) Name of the Scaleway resource in a hyphenated format. */ + productName?: string +} + +export interface ListEventsResponse { + /** Single page of events matching the requested criteria. */ + events: Event[] + /** Page token to use in following calls to keep listing. */ + nextPageToken?: string +} + +export type ListProductsRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region +} + +export interface ListProductsResponse { + products: Product[] + totalCount: number +} diff --git a/packages/clients/src/api/audit_trail/v1alpha1/validation-rules.gen.ts b/packages/clients/src/api/audit_trail/v1alpha1/validation-rules.gen.ts new file mode 100644 index 000000000..4c4f24d12 --- /dev/null +++ b/packages/clients/src/api/audit_trail/v1alpha1/validation-rules.gen.ts @@ -0,0 +1,19 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. + +export const ListEventsRequest = { + methodName: { + pattern: /^[a-zA-Z][a-zA-Z0-9_]*$/, + }, + pageSize: { + greaterThanOrEqual: 1, + lessThanOrEqual: 1000, + }, + productName: { + pattern: /^[a-z]+(-[a-z]+)*$/, + }, + status: { + greaterThanOrEqual: 200, + lessThan: 600, + }, +} diff --git a/packages/clients/src/api/index.gen.ts b/packages/clients/src/api/index.gen.ts index 665edb26e..f1ea4aea0 100644 --- a/packages/clients/src/api/index.gen.ts +++ b/packages/clients/src/api/index.gen.ts @@ -5,6 +5,7 @@ import * as Account from './account/index.gen' import * as Applesilicon from './applesilicon/index.gen' +import * as AuditTrail from './audit_trail/index.gen' import * as Baremetal from './baremetal/index.gen' import * as Billing from './billing/index.gen' import * as Block from './block/index.gen' @@ -46,6 +47,7 @@ import * as Webhosting from './webhosting/index.gen' export { Account, Applesilicon, + AuditTrail, Baremetal, Billing, Block,