Skip to content

Commit ae4c257

Browse files
feat(mongodb): add CreateUser grpc layer (#721)
Co-authored-by: Laure-di <62625835+Laure-di@users.noreply.github.com>
1 parent 100860f commit ae4c257

File tree

8 files changed

+178
-0
lines changed

8 files changed

+178
-0
lines changed

scaleway-async/scaleway_async/mongodb/v1alpha1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .types import RestoreSnapshotRequestVolumeDetails
3131
from .types import CreateInstanceRequest
3232
from .types import CreateSnapshotRequest
33+
from .types import CreateUserRequest
3334
from .types import DeleteInstanceRequest
3435
from .types import DeleteSnapshotRequest
3536
from .types import GetInstanceCertificateRequest
@@ -83,6 +84,7 @@
8384
"RestoreSnapshotRequestVolumeDetails",
8485
"CreateInstanceRequest",
8586
"CreateSnapshotRequest",
87+
"CreateUserRequest",
8688
"DeleteInstanceRequest",
8789
"DeleteSnapshotRequest",
8890
"GetInstanceCertificateRequest",

scaleway-async/scaleway_async/mongodb/v1alpha1/api.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
CreateInstanceRequest,
2525
CreateInstanceRequestVolumeDetails,
2626
CreateSnapshotRequest,
27+
CreateUserRequest,
2728
EndpointSpec,
2829
Instance,
2930
ListInstancesResponse,
@@ -57,6 +58,7 @@
5758
unmarshal_ListVersionsResponse,
5859
marshal_CreateInstanceRequest,
5960
marshal_CreateSnapshotRequest,
61+
marshal_CreateUserRequest,
6062
marshal_RestoreSnapshotRequest,
6163
marshal_UpdateInstanceRequest,
6264
marshal_UpdateSnapshotRequest,
@@ -1070,6 +1072,55 @@ async def list_users_all(
10701072
},
10711073
)
10721074

1075+
async def create_user(
1076+
self,
1077+
*,
1078+
instance_id: str,
1079+
name: str,
1080+
region: Optional[Region] = None,
1081+
password: Optional[str] = None,
1082+
) -> User:
1083+
"""
1084+
Create an user on a Database Instance.
1085+
Create an user on a Database Instance. You must define the `name`, `password` of the user and `instance_id` parameters in the request.
1086+
:param instance_id: UUID of the Database Instance the user belongs to.
1087+
:param name: Name of the database user.
1088+
:param region: Region to target. If none is passed will use default region from the config.
1089+
:param password: Password of the database user.
1090+
:return: :class:`User <User>`
1091+
1092+
Usage:
1093+
::
1094+
1095+
result = await api.create_user(
1096+
instance_id="example",
1097+
name="example",
1098+
)
1099+
"""
1100+
1101+
param_region = validate_path_param(
1102+
"region", region or self.client.default_region
1103+
)
1104+
param_instance_id = validate_path_param("instance_id", instance_id)
1105+
param_name = validate_path_param("name", name)
1106+
1107+
res = self._request(
1108+
"POST",
1109+
f"/mongodb/v1alpha1/regions/{param_region}/instances/{param_instance_id}/users/{param_name}",
1110+
body=marshal_CreateUserRequest(
1111+
CreateUserRequest(
1112+
instance_id=instance_id,
1113+
name=name,
1114+
region=region,
1115+
password=password,
1116+
),
1117+
self.client,
1118+
),
1119+
)
1120+
1121+
self._throw_on_error(res)
1122+
return unmarshal_User(res.json())
1123+
10731124
async def update_user(
10741125
self,
10751126
*,

scaleway-async/scaleway_async/mongodb/v1alpha1/marshalling.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
EndpointSpec,
3535
CreateInstanceRequest,
3636
CreateSnapshotRequest,
37+
CreateUserRequest,
3738
RestoreSnapshotRequestVolumeDetails,
3839
RestoreSnapshotRequest,
3940
UpdateInstanceRequest,
@@ -708,6 +709,18 @@ def marshal_CreateSnapshotRequest(
708709
return output
709710

710711

712+
def marshal_CreateUserRequest(
713+
request: CreateUserRequest,
714+
defaults: ProfileDefaults,
715+
) -> Dict[str, Any]:
716+
output: Dict[str, Any] = {}
717+
718+
if request.password is not None:
719+
output["password"] = request.password
720+
721+
return output
722+
723+
711724
def marshal_RestoreSnapshotRequestVolumeDetails(
712725
request: RestoreSnapshotRequestVolumeDetails,
713726
defaults: ProfileDefaults,

scaleway-async/scaleway_async/mongodb/v1alpha1/types.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,29 @@ class CreateSnapshotRequest:
592592
"""
593593

594594

595+
@dataclass
596+
class CreateUserRequest:
597+
instance_id: str
598+
"""
599+
UUID of the Database Instance the user belongs to.
600+
"""
601+
602+
name: str
603+
"""
604+
Name of the database user.
605+
"""
606+
607+
region: Optional[Region]
608+
"""
609+
Region to target. If none is passed will use default region from the config.
610+
"""
611+
612+
password: Optional[str]
613+
"""
614+
Password of the database user.
615+
"""
616+
617+
595618
@dataclass
596619
class DeleteInstanceRequest:
597620
instance_id: str

scaleway/scaleway/mongodb/v1alpha1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .types import RestoreSnapshotRequestVolumeDetails
3131
from .types import CreateInstanceRequest
3232
from .types import CreateSnapshotRequest
33+
from .types import CreateUserRequest
3334
from .types import DeleteInstanceRequest
3435
from .types import DeleteSnapshotRequest
3536
from .types import GetInstanceCertificateRequest
@@ -83,6 +84,7 @@
8384
"RestoreSnapshotRequestVolumeDetails",
8485
"CreateInstanceRequest",
8586
"CreateSnapshotRequest",
87+
"CreateUserRequest",
8688
"DeleteInstanceRequest",
8789
"DeleteSnapshotRequest",
8890
"GetInstanceCertificateRequest",

scaleway/scaleway/mongodb/v1alpha1/api.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
CreateInstanceRequest,
2525
CreateInstanceRequestVolumeDetails,
2626
CreateSnapshotRequest,
27+
CreateUserRequest,
2728
EndpointSpec,
2829
Instance,
2930
ListInstancesResponse,
@@ -57,6 +58,7 @@
5758
unmarshal_ListVersionsResponse,
5859
marshal_CreateInstanceRequest,
5960
marshal_CreateSnapshotRequest,
61+
marshal_CreateUserRequest,
6062
marshal_RestoreSnapshotRequest,
6163
marshal_UpdateInstanceRequest,
6264
marshal_UpdateSnapshotRequest,
@@ -1066,6 +1068,55 @@ def list_users_all(
10661068
},
10671069
)
10681070

1071+
def create_user(
1072+
self,
1073+
*,
1074+
instance_id: str,
1075+
name: str,
1076+
region: Optional[Region] = None,
1077+
password: Optional[str] = None,
1078+
) -> User:
1079+
"""
1080+
Create an user on a Database Instance.
1081+
Create an user on a Database Instance. You must define the `name`, `password` of the user and `instance_id` parameters in the request.
1082+
:param instance_id: UUID of the Database Instance the user belongs to.
1083+
:param name: Name of the database user.
1084+
:param region: Region to target. If none is passed will use default region from the config.
1085+
:param password: Password of the database user.
1086+
:return: :class:`User <User>`
1087+
1088+
Usage:
1089+
::
1090+
1091+
result = api.create_user(
1092+
instance_id="example",
1093+
name="example",
1094+
)
1095+
"""
1096+
1097+
param_region = validate_path_param(
1098+
"region", region or self.client.default_region
1099+
)
1100+
param_instance_id = validate_path_param("instance_id", instance_id)
1101+
param_name = validate_path_param("name", name)
1102+
1103+
res = self._request(
1104+
"POST",
1105+
f"/mongodb/v1alpha1/regions/{param_region}/instances/{param_instance_id}/users/{param_name}",
1106+
body=marshal_CreateUserRequest(
1107+
CreateUserRequest(
1108+
instance_id=instance_id,
1109+
name=name,
1110+
region=region,
1111+
password=password,
1112+
),
1113+
self.client,
1114+
),
1115+
)
1116+
1117+
self._throw_on_error(res)
1118+
return unmarshal_User(res.json())
1119+
10691120
def update_user(
10701121
self,
10711122
*,

scaleway/scaleway/mongodb/v1alpha1/marshalling.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
EndpointSpec,
3535
CreateInstanceRequest,
3636
CreateSnapshotRequest,
37+
CreateUserRequest,
3738
RestoreSnapshotRequestVolumeDetails,
3839
RestoreSnapshotRequest,
3940
UpdateInstanceRequest,
@@ -708,6 +709,18 @@ def marshal_CreateSnapshotRequest(
708709
return output
709710

710711

712+
def marshal_CreateUserRequest(
713+
request: CreateUserRequest,
714+
defaults: ProfileDefaults,
715+
) -> Dict[str, Any]:
716+
output: Dict[str, Any] = {}
717+
718+
if request.password is not None:
719+
output["password"] = request.password
720+
721+
return output
722+
723+
711724
def marshal_RestoreSnapshotRequestVolumeDetails(
712725
request: RestoreSnapshotRequestVolumeDetails,
713726
defaults: ProfileDefaults,

scaleway/scaleway/mongodb/v1alpha1/types.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,29 @@ class CreateSnapshotRequest:
592592
"""
593593

594594

595+
@dataclass
596+
class CreateUserRequest:
597+
instance_id: str
598+
"""
599+
UUID of the Database Instance the user belongs to.
600+
"""
601+
602+
name: str
603+
"""
604+
Name of the database user.
605+
"""
606+
607+
region: Optional[Region]
608+
"""
609+
Region to target. If none is passed will use default region from the config.
610+
"""
611+
612+
password: Optional[str]
613+
"""
614+
Password of the database user.
615+
"""
616+
617+
595618
@dataclass
596619
class DeleteInstanceRequest:
597620
instance_id: str

0 commit comments

Comments
 (0)