Skip to content

feat(mongodb): add CreateUser grpc layer #721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 29, 2024
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
2 changes: 2 additions & 0 deletions scaleway-async/scaleway_async/mongodb/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,6 +84,7 @@
"RestoreSnapshotRequestVolumeDetails",
"CreateInstanceRequest",
"CreateSnapshotRequest",
"CreateUserRequest",
"DeleteInstanceRequest",
"DeleteSnapshotRequest",
"GetInstanceCertificateRequest",
Expand Down
51 changes: 51 additions & 0 deletions scaleway-async/scaleway_async/mongodb/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
CreateInstanceRequest,
CreateInstanceRequestVolumeDetails,
CreateSnapshotRequest,
CreateUserRequest,
EndpointSpec,
Instance,
ListInstancesResponse,
Expand Down Expand Up @@ -57,6 +58,7 @@
unmarshal_ListVersionsResponse,
marshal_CreateInstanceRequest,
marshal_CreateSnapshotRequest,
marshal_CreateUserRequest,
marshal_RestoreSnapshotRequest,
marshal_UpdateInstanceRequest,
marshal_UpdateSnapshotRequest,
Expand Down Expand Up @@ -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 <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,
*,
Expand Down
13 changes: 13 additions & 0 deletions scaleway-async/scaleway_async/mongodb/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
EndpointSpec,
CreateInstanceRequest,
CreateSnapshotRequest,
CreateUserRequest,
RestoreSnapshotRequestVolumeDetails,
RestoreSnapshotRequest,
UpdateInstanceRequest,
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions scaleway-async/scaleway_async/mongodb/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions scaleway/scaleway/mongodb/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,6 +84,7 @@
"RestoreSnapshotRequestVolumeDetails",
"CreateInstanceRequest",
"CreateSnapshotRequest",
"CreateUserRequest",
"DeleteInstanceRequest",
"DeleteSnapshotRequest",
"GetInstanceCertificateRequest",
Expand Down
51 changes: 51 additions & 0 deletions scaleway/scaleway/mongodb/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
CreateInstanceRequest,
CreateInstanceRequestVolumeDetails,
CreateSnapshotRequest,
CreateUserRequest,
EndpointSpec,
Instance,
ListInstancesResponse,
Expand Down Expand Up @@ -57,6 +58,7 @@
unmarshal_ListVersionsResponse,
marshal_CreateInstanceRequest,
marshal_CreateSnapshotRequest,
marshal_CreateUserRequest,
marshal_RestoreSnapshotRequest,
marshal_UpdateInstanceRequest,
marshal_UpdateSnapshotRequest,
Expand Down Expand Up @@ -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 <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,
*,
Expand Down
13 changes: 13 additions & 0 deletions scaleway/scaleway/mongodb/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
EndpointSpec,
CreateInstanceRequest,
CreateSnapshotRequest,
CreateUserRequest,
RestoreSnapshotRequestVolumeDetails,
RestoreSnapshotRequest,
UpdateInstanceRequest,
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions scaleway/scaleway/mongodb/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down