Skip to content

Commit 966ed42

Browse files
feat(mongodb): add CreateUser grpc layer (#1539)
Co-authored-by: Laure-di <[email protected]>
1 parent a771c89 commit 966ed42

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

packages/clients/src/api/mongodb/v1alpha1/api.gen.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import {
1616
marshalCreateInstanceRequest,
1717
marshalCreateSnapshotRequest,
18+
marshalCreateUserRequest,
1819
marshalRestoreSnapshotRequest,
1920
marshalUpdateInstanceRequest,
2021
marshalUpdateSnapshotRequest,
@@ -32,6 +33,7 @@ import {
3233
import type {
3334
CreateInstanceRequest,
3435
CreateSnapshotRequest,
36+
CreateUserRequest,
3537
DeleteInstanceRequest,
3638
DeleteSnapshotRequest,
3739
GetInstanceCertificateRequest,
@@ -492,6 +494,27 @@ export class API extends ParentAPI {
492494
listUsers = (request: Readonly<ListUsersRequest>) =>
493495
enrichForPagination('users', this.pageOfListUsers, request)
494496

497+
/**
498+
* Create an user on a Database Instance. Create an user on a Database
499+
* Instance. You must define the `name`, `password` of the user and
500+
* `instance_id` parameters in the request.
501+
*
502+
* @param request - The request {@link CreateUserRequest}
503+
* @returns A Promise of User
504+
*/
505+
createUser = (request: Readonly<CreateUserRequest>) =>
506+
this.client.fetch<User>(
507+
{
508+
body: JSON.stringify(
509+
marshalCreateUserRequest(request, this.client.settings),
510+
),
511+
headers: jsonContentHeaders,
512+
method: 'POST',
513+
path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/instances/${validatePathParam('instanceId', request.instanceId)}/users/${validatePathParam('name', request.name)}`,
514+
},
515+
unmarshalUser,
516+
)
517+
495518
/**
496519
* Update a user on a Database Instance. Update the parameters of a user on a
497520
* Database Instance. You can update the `password` parameter, but you cannot

packages/clients/src/api/mongodb/v1alpha1/index.gen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type {
66
CreateInstanceRequest,
77
CreateInstanceRequestVolumeDetails,
88
CreateSnapshotRequest,
9+
CreateUserRequest,
910
DeleteInstanceRequest,
1011
DeleteSnapshotRequest,
1112
Endpoint,

packages/clients/src/api/mongodb/v1alpha1/marshalling.gen.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
CreateInstanceRequest,
1313
CreateInstanceRequestVolumeDetails,
1414
CreateSnapshotRequest,
15+
CreateUserRequest,
1516
Endpoint,
1617
EndpointPrivateNetworkDetails,
1718
EndpointPublicDetails,
@@ -415,6 +416,13 @@ export const marshalCreateSnapshotRequest = (
415416
name: request.name,
416417
})
417418

419+
export const marshalCreateUserRequest = (
420+
request: CreateUserRequest,
421+
defaults: DefaultValues,
422+
): Record<string, unknown> => ({
423+
password: request.password,
424+
})
425+
418426
const marshalRestoreSnapshotRequestVolumeDetails = (
419427
request: RestoreSnapshotRequestVolumeDetails,
420428
defaults: DefaultValues,

packages/clients/src/api/mongodb/v1alpha1/types.gen.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,20 @@ export type CreateSnapshotRequest = {
300300
expiresAt?: Date
301301
}
302302

303+
export type CreateUserRequest = {
304+
/**
305+
* Region to target. If none is passed will use default region from the
306+
* config.
307+
*/
308+
region?: Region
309+
/** UUID of the Database Instance the user belongs to. */
310+
instanceId: string
311+
/** Name of the database user. */
312+
name: string
313+
/** Password of the database user. */
314+
password?: string
315+
}
316+
303317
export type DeleteInstanceRequest = {
304318
/**
305319
* Region to target. If none is passed will use default region from the

packages/clients/src/api/mongodb/v1alpha1/validation-rules.gen.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ export const CreateSnapshotRequest = {
3838
},
3939
}
4040

41+
export const CreateUserRequest = {
42+
name: {
43+
maxLength: 63,
44+
minLength: 1,
45+
pattern: /^[a-zA-Z0-9_\-]*$/,
46+
},
47+
password: {
48+
maxLength: 128,
49+
minLength: 8,
50+
},
51+
}
52+
4153
export const ListInstancesRequest = {
4254
name: {
4355
maxLength: 255,

0 commit comments

Comments
 (0)