Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/clients/src/api/mongodb/v1alpha1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
marshalCreateSnapshotRequest,
marshalCreateUserRequest,
marshalRestoreSnapshotRequest,
marshalSetUserRoleRequest,
marshalUpdateInstanceRequest,
marshalUpdateSnapshotRequest,
marshalUpdateUserRequest,
Expand Down Expand Up @@ -57,6 +58,7 @@ import type {
ListVersionsRequest,
ListVersionsResponse,
RestoreSnapshotRequest,
SetUserRoleRequest,
Snapshot,
UpdateInstanceRequest,
UpdateSnapshotRequest,
Expand Down Expand Up @@ -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<SetUserRoleRequest>) =>
this.client.fetch<User>(
{
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
Expand Down
3 changes: 3 additions & 0 deletions packages/clients/src/api/mongodb/v1alpha1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type {
NodeTypeVolumeType,
RestoreSnapshotRequest,
RestoreSnapshotRequestVolumeDetails,
SetUserRoleRequest,
Setting,
SettingPropertyType,
Snapshot,
Expand All @@ -52,6 +53,8 @@ export type {
UpdateUserRequest,
UpgradeInstanceRequest,
User,
UserRole,
UserRoleRole,
Version,
Volume,
VolumeType,
Expand Down
39 changes: 39 additions & 0 deletions packages/clients/src/api/mongodb/v1alpha1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import type {
NodeTypeVolumeType,
RestoreSnapshotRequest,
RestoreSnapshotRequestVolumeDetails,
SetUserRoleRequest,
Setting,
Snapshot,
SnapshotVolumeType,
Expand All @@ -39,6 +40,7 @@ import type {
UpdateUserRequest,
UpgradeInstanceRequest,
User,
UserRole,
Version,
Volume,
} from './types.gen'
Expand Down Expand Up @@ -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(
Expand All @@ -186,6 +202,7 @@ export const unmarshalUser = (data: unknown): User => {

return {
name: data.name,
roles: unmarshalArrayOfObject(data.roles, unmarshalUserRole),
} as User
}

Expand Down Expand Up @@ -450,6 +467,28 @@ export const marshalRestoreSnapshotRequest = (
volume: marshalRestoreSnapshotRequestVolumeDetails(request.volume, defaults),
})

const marshalUserRole = (
request: UserRole,
defaults: DefaultValues,
): Record<string, unknown> => ({
role: request.role,
...resolveOneOf<string | boolean>([
{ param: 'database', value: request.database },
{ param: 'any_database', value: request.anyDatabase },
]),
})

export const marshalSetUserRoleRequest = (
request: SetUserRoleRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
roles:
request.roles !== undefined
? request.roles.map(elt => marshalUserRole(elt, defaults))
: undefined,
user_name: request.userName,
})

export const marshalUpdateInstanceRequest = (
request: UpdateInstanceRequest,
defaults: DefaultValues,
Expand Down
32 changes: 32 additions & 0 deletions packages/clients/src/api/mongodb/v1alpha1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading