From ce7fbf058c7af9b27e092e318ea4db1d31c30be0 Mon Sep 17 00:00:00 2001 From: scaleway-bot Date: Thu, 27 Feb 2025 13:33:11 +0000 Subject: [PATCH] feat: update generated APIs --- .../src/api/mongodb/v1alpha1/api.gen.ts | 15 +++++++ .../src/api/mongodb/v1alpha1/index.gen.ts | 3 ++ .../api/mongodb/v1alpha1/marshalling.gen.ts | 39 +++++++++++++++++++ .../src/api/mongodb/v1alpha1/types.gen.ts | 32 +++++++++++++++ .../mongodb/v1alpha1/validation-rules.gen.ts | 8 ++++ 5 files changed, 97 insertions(+) diff --git a/packages/clients/src/api/mongodb/v1alpha1/api.gen.ts b/packages/clients/src/api/mongodb/v1alpha1/api.gen.ts index 30117dc23..00b08d3a1 100644 --- a/packages/clients/src/api/mongodb/v1alpha1/api.gen.ts +++ b/packages/clients/src/api/mongodb/v1alpha1/api.gen.ts @@ -18,6 +18,7 @@ import { marshalCreateSnapshotRequest, marshalCreateUserRequest, marshalRestoreSnapshotRequest, + marshalSetUserRoleRequest, marshalUpdateInstanceRequest, marshalUpdateSnapshotRequest, marshalUpdateUserRequest, @@ -57,6 +58,7 @@ import type { ListVersionsRequest, ListVersionsResponse, RestoreSnapshotRequest, + SetUserRoleRequest, Snapshot, UpdateInstanceRequest, UpdateSnapshotRequest, @@ -542,6 +544,19 @@ export class API extends ParentAPI { path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/instances/${validatePathParam('instanceId', request.instanceId)}/users/${validatePathParam('name', request.name)}`, }) + setUserRole = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalSetUserRoleRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PUT', + path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/instances/${validatePathParam('instanceId', request.instanceId)}/roles`, + }, + unmarshalUser, + ) + /** * Delete a Database Instance endpoint. Delete the endpoint of a Database * Instance. You must specify the `endpoint_id` parameter of the endpoint you diff --git a/packages/clients/src/api/mongodb/v1alpha1/index.gen.ts b/packages/clients/src/api/mongodb/v1alpha1/index.gen.ts index af9f7d30a..c28d2ff6b 100644 --- a/packages/clients/src/api/mongodb/v1alpha1/index.gen.ts +++ b/packages/clients/src/api/mongodb/v1alpha1/index.gen.ts @@ -42,6 +42,7 @@ export type { NodeTypeVolumeType, RestoreSnapshotRequest, RestoreSnapshotRequestVolumeDetails, + SetUserRoleRequest, Setting, SettingPropertyType, Snapshot, @@ -52,6 +53,8 @@ export type { UpdateUserRequest, UpgradeInstanceRequest, User, + UserRole, + UserRoleRole, Version, Volume, VolumeType, diff --git a/packages/clients/src/api/mongodb/v1alpha1/marshalling.gen.ts b/packages/clients/src/api/mongodb/v1alpha1/marshalling.gen.ts index 2a79ece61..e8bf7162f 100644 --- a/packages/clients/src/api/mongodb/v1alpha1/marshalling.gen.ts +++ b/packages/clients/src/api/mongodb/v1alpha1/marshalling.gen.ts @@ -31,6 +31,7 @@ import type { NodeTypeVolumeType, RestoreSnapshotRequest, RestoreSnapshotRequestVolumeDetails, + SetUserRoleRequest, Setting, Snapshot, SnapshotVolumeType, @@ -39,6 +40,7 @@ import type { UpdateUserRequest, UpgradeInstanceRequest, User, + UserRole, Version, Volume, } from './types.gen' @@ -177,6 +179,20 @@ export const unmarshalSnapshot = (data: unknown): Snapshot => { } as Snapshot } +const unmarshalUserRole = (data: unknown): UserRole => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'UserRole' failed as data isn't a dictionary.`, + ) + } + + return { + anyDatabase: data.any_database, + database: data.database, + role: data.role, + } as UserRole +} + export const unmarshalUser = (data: unknown): User => { if (!isJSONObject(data)) { throw new TypeError( @@ -186,6 +202,7 @@ export const unmarshalUser = (data: unknown): User => { return { name: data.name, + roles: unmarshalArrayOfObject(data.roles, unmarshalUserRole), } as User } @@ -450,6 +467,28 @@ export const marshalRestoreSnapshotRequest = ( volume: marshalRestoreSnapshotRequestVolumeDetails(request.volume, defaults), }) +const marshalUserRole = ( + request: UserRole, + defaults: DefaultValues, +): Record => ({ + role: request.role, + ...resolveOneOf([ + { param: 'database', value: request.database }, + { param: 'any_database', value: request.anyDatabase }, + ]), +}) + +export const marshalSetUserRoleRequest = ( + request: SetUserRoleRequest, + defaults: DefaultValues, +): Record => ({ + roles: + request.roles !== undefined + ? request.roles.map(elt => marshalUserRole(elt, defaults)) + : undefined, + user_name: request.userName, +}) + export const marshalUpdateInstanceRequest = ( request: UpdateInstanceRequest, defaults: DefaultValues, diff --git a/packages/clients/src/api/mongodb/v1alpha1/types.gen.ts b/packages/clients/src/api/mongodb/v1alpha1/types.gen.ts index 161a37eb7..796ba7fb0 100644 --- a/packages/clients/src/api/mongodb/v1alpha1/types.gen.ts +++ b/packages/clients/src/api/mongodb/v1alpha1/types.gen.ts @@ -48,6 +48,8 @@ export type SnapshotStatus = | 'error' | 'locked' +export type UserRoleRole = 'unknown_role' | 'read' | 'read_write' | 'db_admin' + export type VolumeType = 'unknown_type' | 'sbs_5k' | 'sbs_15k' /** Private Network details. */ @@ -119,6 +121,14 @@ export interface SnapshotVolumeType { type: VolumeType } +export interface UserRole { + role: UserRoleRole + /** One-of ('scope'): at most one of 'database', 'anyDatabase' could be set. */ + database?: string + /** One-of ('scope'): at most one of 'database', 'anyDatabase' could be set. */ + anyDatabase?: boolean +} + export interface Setting { /** Setting name from the database engine. */ name: string @@ -242,6 +252,11 @@ export interface User { * characters are accepted). */ name: string + /** + * List of roles assigned to the user, along with the corresponding database + * where each role is granted. + */ + roles: UserRole[] } export interface Version { @@ -530,6 +545,23 @@ export type RestoreSnapshotRequest = { volume: RestoreSnapshotRequestVolumeDetails } +export type SetUserRoleRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: ScwRegion + /** UUID of the Database Instance the user belongs to. */ + instanceId: string + /** Name of the database user. */ + userName: string + /** + * List of roles assigned to the user, along with the corresponding database + * where each role is granted. + */ + roles?: UserRole[] +} + export type UpdateInstanceRequest = { /** * Region to target. If none is passed will use default region from the diff --git a/packages/clients/src/api/mongodb/v1alpha1/validation-rules.gen.ts b/packages/clients/src/api/mongodb/v1alpha1/validation-rules.gen.ts index 5258e7c83..ffff8e675 100644 --- a/packages/clients/src/api/mongodb/v1alpha1/validation-rules.gen.ts +++ b/packages/clients/src/api/mongodb/v1alpha1/validation-rules.gen.ts @@ -138,6 +138,14 @@ export const RestoreSnapshotRequest = { }, } +export const SetUserRoleRequest = { + userName: { + maxLength: 63, + minLength: 1, + pattern: /^[a-zA-Z0-9_\-]*$/, + }, +} + export const UpdateInstanceRequest = { name: { maxLength: 255,