Skip to content

Commit

Permalink
feat(audit_trail): enable v1alpha1 (#1615)
Browse files Browse the repository at this point in the history
Co-authored-by: Yacine Fodil <105779815+yfodil@users.noreply.github.com>
  • Loading branch information
scaleway-bot and yfodil authored Nov 29, 2024
1 parent a4a477e commit b696c1e
Show file tree
Hide file tree
Showing 7 changed files with 478 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/clients/src/api/audit_trail/index.gen.ts
Original file line number Diff line number Diff line change
@@ -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'
78 changes: 78 additions & 0 deletions packages/clients/src/api/audit_trail/v1alpha1/api.gen.ts
Original file line number Diff line number Diff line change
@@ -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<ListEventsRequest> = {}) =>
this.client.fetch<ListEventsResponse>(
{
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<ListProductsRequest> = {}) =>
this.client.fetch<ListProductsResponse>(
{
method: 'GET',
path: `/audit-trail/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/products`,
},
unmarshalListProductsResponse,
)
}
21 changes: 21 additions & 0 deletions packages/clients/src/api/audit_trail/v1alpha1/index.gen.ts
Original file line number Diff line number Diff line change
@@ -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'
201 changes: 201 additions & 0 deletions packages/clients/src/api/audit_trail/v1alpha1/marshalling.gen.ts
Original file line number Diff line number Diff line change
@@ -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
}
Loading

0 comments on commit b696c1e

Please sign in to comment.