diff --git a/scaleway-async/scaleway_async/mongodb/v1alpha1/__init__.py b/scaleway-async/scaleway_async/mongodb/v1alpha1/__init__.py index 0fd1e118d..ead557620 100644 --- a/scaleway-async/scaleway_async/mongodb/v1alpha1/__init__.py +++ b/scaleway-async/scaleway_async/mongodb/v1alpha1/__init__.py @@ -30,6 +30,7 @@ from .types import RestoreSnapshotRequestVolumeDetails from .types import CreateInstanceRequest from .types import CreateSnapshotRequest +from .types import CreateUserRequest from .types import DeleteInstanceRequest from .types import DeleteSnapshotRequest from .types import GetInstanceCertificateRequest @@ -83,6 +84,7 @@ "RestoreSnapshotRequestVolumeDetails", "CreateInstanceRequest", "CreateSnapshotRequest", + "CreateUserRequest", "DeleteInstanceRequest", "DeleteSnapshotRequest", "GetInstanceCertificateRequest", diff --git a/scaleway-async/scaleway_async/mongodb/v1alpha1/api.py b/scaleway-async/scaleway_async/mongodb/v1alpha1/api.py index 9d8c0dca0..78883abbf 100644 --- a/scaleway-async/scaleway_async/mongodb/v1alpha1/api.py +++ b/scaleway-async/scaleway_async/mongodb/v1alpha1/api.py @@ -24,6 +24,7 @@ CreateInstanceRequest, CreateInstanceRequestVolumeDetails, CreateSnapshotRequest, + CreateUserRequest, EndpointSpec, Instance, ListInstancesResponse, @@ -57,6 +58,7 @@ unmarshal_ListVersionsResponse, marshal_CreateInstanceRequest, marshal_CreateSnapshotRequest, + marshal_CreateUserRequest, marshal_RestoreSnapshotRequest, marshal_UpdateInstanceRequest, marshal_UpdateSnapshotRequest, @@ -1070,6 +1072,55 @@ async def list_users_all( }, ) + async def create_user( + self, + *, + instance_id: str, + name: str, + region: Optional[Region] = None, + password: Optional[str] = None, + ) -> User: + """ + Create an user on a Database Instance. + Create an user on a Database Instance. You must define the `name`, `password` of the user and `instance_id` parameters in the request. + :param instance_id: UUID of the Database Instance the user belongs to. + :param name: Name of the database user. + :param region: Region to target. If none is passed will use default region from the config. + :param password: Password of the database user. + :return: :class:`User ` + + Usage: + :: + + result = await api.create_user( + instance_id="example", + name="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + param_name = validate_path_param("name", name) + + res = self._request( + "POST", + f"/mongodb/v1alpha1/regions/{param_region}/instances/{param_instance_id}/users/{param_name}", + body=marshal_CreateUserRequest( + CreateUserRequest( + instance_id=instance_id, + name=name, + region=region, + password=password, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_User(res.json()) + async def update_user( self, *, diff --git a/scaleway-async/scaleway_async/mongodb/v1alpha1/marshalling.py b/scaleway-async/scaleway_async/mongodb/v1alpha1/marshalling.py index d486ad668..a59cdf460 100644 --- a/scaleway-async/scaleway_async/mongodb/v1alpha1/marshalling.py +++ b/scaleway-async/scaleway_async/mongodb/v1alpha1/marshalling.py @@ -34,6 +34,7 @@ EndpointSpec, CreateInstanceRequest, CreateSnapshotRequest, + CreateUserRequest, RestoreSnapshotRequestVolumeDetails, RestoreSnapshotRequest, UpdateInstanceRequest, @@ -708,6 +709,18 @@ def marshal_CreateSnapshotRequest( return output +def marshal_CreateUserRequest( + request: CreateUserRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.password is not None: + output["password"] = request.password + + return output + + def marshal_RestoreSnapshotRequestVolumeDetails( request: RestoreSnapshotRequestVolumeDetails, defaults: ProfileDefaults, diff --git a/scaleway-async/scaleway_async/mongodb/v1alpha1/types.py b/scaleway-async/scaleway_async/mongodb/v1alpha1/types.py index 3139e0454..fec93e393 100644 --- a/scaleway-async/scaleway_async/mongodb/v1alpha1/types.py +++ b/scaleway-async/scaleway_async/mongodb/v1alpha1/types.py @@ -592,6 +592,29 @@ class CreateSnapshotRequest: """ +@dataclass +class CreateUserRequest: + instance_id: str + """ + UUID of the Database Instance the user belongs to. + """ + + name: str + """ + Name of the database user. + """ + + region: Optional[Region] + """ + Region to target. If none is passed will use default region from the config. + """ + + password: Optional[str] + """ + Password of the database user. + """ + + @dataclass class DeleteInstanceRequest: instance_id: str diff --git a/scaleway/scaleway/mongodb/v1alpha1/__init__.py b/scaleway/scaleway/mongodb/v1alpha1/__init__.py index 0fd1e118d..ead557620 100644 --- a/scaleway/scaleway/mongodb/v1alpha1/__init__.py +++ b/scaleway/scaleway/mongodb/v1alpha1/__init__.py @@ -30,6 +30,7 @@ from .types import RestoreSnapshotRequestVolumeDetails from .types import CreateInstanceRequest from .types import CreateSnapshotRequest +from .types import CreateUserRequest from .types import DeleteInstanceRequest from .types import DeleteSnapshotRequest from .types import GetInstanceCertificateRequest @@ -83,6 +84,7 @@ "RestoreSnapshotRequestVolumeDetails", "CreateInstanceRequest", "CreateSnapshotRequest", + "CreateUserRequest", "DeleteInstanceRequest", "DeleteSnapshotRequest", "GetInstanceCertificateRequest", diff --git a/scaleway/scaleway/mongodb/v1alpha1/api.py b/scaleway/scaleway/mongodb/v1alpha1/api.py index 0dc84f64e..15577d853 100644 --- a/scaleway/scaleway/mongodb/v1alpha1/api.py +++ b/scaleway/scaleway/mongodb/v1alpha1/api.py @@ -24,6 +24,7 @@ CreateInstanceRequest, CreateInstanceRequestVolumeDetails, CreateSnapshotRequest, + CreateUserRequest, EndpointSpec, Instance, ListInstancesResponse, @@ -57,6 +58,7 @@ unmarshal_ListVersionsResponse, marshal_CreateInstanceRequest, marshal_CreateSnapshotRequest, + marshal_CreateUserRequest, marshal_RestoreSnapshotRequest, marshal_UpdateInstanceRequest, marshal_UpdateSnapshotRequest, @@ -1066,6 +1068,55 @@ def list_users_all( }, ) + def create_user( + self, + *, + instance_id: str, + name: str, + region: Optional[Region] = None, + password: Optional[str] = None, + ) -> User: + """ + Create an user on a Database Instance. + Create an user on a Database Instance. You must define the `name`, `password` of the user and `instance_id` parameters in the request. + :param instance_id: UUID of the Database Instance the user belongs to. + :param name: Name of the database user. + :param region: Region to target. If none is passed will use default region from the config. + :param password: Password of the database user. + :return: :class:`User ` + + Usage: + :: + + result = api.create_user( + instance_id="example", + name="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + param_name = validate_path_param("name", name) + + res = self._request( + "POST", + f"/mongodb/v1alpha1/regions/{param_region}/instances/{param_instance_id}/users/{param_name}", + body=marshal_CreateUserRequest( + CreateUserRequest( + instance_id=instance_id, + name=name, + region=region, + password=password, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_User(res.json()) + def update_user( self, *, diff --git a/scaleway/scaleway/mongodb/v1alpha1/marshalling.py b/scaleway/scaleway/mongodb/v1alpha1/marshalling.py index d486ad668..a59cdf460 100644 --- a/scaleway/scaleway/mongodb/v1alpha1/marshalling.py +++ b/scaleway/scaleway/mongodb/v1alpha1/marshalling.py @@ -34,6 +34,7 @@ EndpointSpec, CreateInstanceRequest, CreateSnapshotRequest, + CreateUserRequest, RestoreSnapshotRequestVolumeDetails, RestoreSnapshotRequest, UpdateInstanceRequest, @@ -708,6 +709,18 @@ def marshal_CreateSnapshotRequest( return output +def marshal_CreateUserRequest( + request: CreateUserRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.password is not None: + output["password"] = request.password + + return output + + def marshal_RestoreSnapshotRequestVolumeDetails( request: RestoreSnapshotRequestVolumeDetails, defaults: ProfileDefaults, diff --git a/scaleway/scaleway/mongodb/v1alpha1/types.py b/scaleway/scaleway/mongodb/v1alpha1/types.py index 3139e0454..fec93e393 100644 --- a/scaleway/scaleway/mongodb/v1alpha1/types.py +++ b/scaleway/scaleway/mongodb/v1alpha1/types.py @@ -592,6 +592,29 @@ class CreateSnapshotRequest: """ +@dataclass +class CreateUserRequest: + instance_id: str + """ + UUID of the Database Instance the user belongs to. + """ + + name: str + """ + Name of the database user. + """ + + region: Optional[Region] + """ + Region to target. If none is passed will use default region from the config. + """ + + password: Optional[str] + """ + Password of the database user. + """ + + @dataclass class DeleteInstanceRequest: instance_id: str