From 77f39b4b0cfa9dd2eaf163f0f957563290d41592 Mon Sep 17 00:00:00 2001 From: scaleway-bot Date: Thu, 27 Feb 2025 13:32:20 +0000 Subject: [PATCH] feat: update generated APIs --- .../mongodb/v1alpha1/__init__.py | 6 ++ .../scaleway_async/mongodb/v1alpha1/api.py | 49 +++++++++++++ .../mongodb/v1alpha1/marshalling.py | 70 +++++++++++++++++++ .../scaleway_async/mongodb/v1alpha1/types.py | 47 +++++++++++++ .../scaleway/mongodb/v1alpha1/__init__.py | 6 ++ scaleway/scaleway/mongodb/v1alpha1/api.py | 49 +++++++++++++ .../scaleway/mongodb/v1alpha1/marshalling.py | 70 +++++++++++++++++++ scaleway/scaleway/mongodb/v1alpha1/types.py | 47 +++++++++++++ 8 files changed, 344 insertions(+) diff --git a/scaleway-async/scaleway_async/mongodb/v1alpha1/__init__.py b/scaleway-async/scaleway_async/mongodb/v1alpha1/__init__.py index d1d42a9e..697dc169 100644 --- a/scaleway-async/scaleway_async/mongodb/v1alpha1/__init__.py +++ b/scaleway-async/scaleway_async/mongodb/v1alpha1/__init__.py @@ -9,6 +9,7 @@ from .types import SettingPropertyType from .types import SnapshotStatus from .content import SNAPSHOT_TRANSIENT_STATUSES +from .types import UserRoleRole from .types import VolumeType from .types import EndpointPrivateNetworkDetails from .types import EndpointPublicDetails @@ -19,6 +20,7 @@ from .types import Volume from .types import NodeTypeVolumeType from .types import SnapshotVolumeType +from .types import UserRole from .types import Setting from .types import EndpointSpec from .types import CreateInstanceRequestVolumeDetails @@ -50,6 +52,7 @@ from .types import ListVersionsRequest from .types import ListVersionsResponse from .types import RestoreSnapshotRequest +from .types import SetUserRoleRequest from .types import UpdateInstanceRequest from .types import UpdateSnapshotRequest from .types import UpdateUserRequest @@ -66,6 +69,7 @@ "SettingPropertyType", "SnapshotStatus", "SNAPSHOT_TRANSIENT_STATUSES", + "UserRoleRole", "VolumeType", "EndpointPrivateNetworkDetails", "EndpointPublicDetails", @@ -76,6 +80,7 @@ "Volume", "NodeTypeVolumeType", "SnapshotVolumeType", + "UserRole", "Setting", "EndpointSpec", "CreateInstanceRequestVolumeDetails", @@ -107,6 +112,7 @@ "ListVersionsRequest", "ListVersionsResponse", "RestoreSnapshotRequest", + "SetUserRoleRequest", "UpdateInstanceRequest", "UpdateSnapshotRequest", "UpdateUserRequest", diff --git a/scaleway-async/scaleway_async/mongodb/v1alpha1/api.py b/scaleway-async/scaleway_async/mongodb/v1alpha1/api.py index b38b712f..dc413e65 100644 --- a/scaleway-async/scaleway_async/mongodb/v1alpha1/api.py +++ b/scaleway-async/scaleway_async/mongodb/v1alpha1/api.py @@ -37,12 +37,14 @@ NodeType, RestoreSnapshotRequest, RestoreSnapshotRequestVolumeDetails, + SetUserRoleRequest, Snapshot, UpdateInstanceRequest, UpdateSnapshotRequest, UpdateUserRequest, UpgradeInstanceRequest, User, + UserRole, Version, ) from .content import ( @@ -64,6 +66,7 @@ marshal_CreateSnapshotRequest, marshal_CreateUserRequest, marshal_RestoreSnapshotRequest, + marshal_SetUserRoleRequest, marshal_UpdateInstanceRequest, marshal_UpdateSnapshotRequest, marshal_UpdateUserRequest, @@ -1211,6 +1214,52 @@ async def delete_user( self._throw_on_error(res) + async def set_user_role( + self, + *, + instance_id: str, + user_name: str, + region: Optional[ScwRegion] = None, + roles: Optional[List[UserRole]] = None, + ) -> User: + """ + :param instance_id: UUID of the Database Instance the user belongs to. + :param user_name: Name of the database user. + :param region: Region to target. If none is passed will use default region from the config. + :param roles: List of roles assigned to the user, along with the corresponding database where each role is granted. + :return: :class:`User ` + + Usage: + :: + + result = await api.set_user_role( + instance_id="example", + user_name="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "PUT", + f"/mongodb/v1alpha1/regions/{param_region}/instances/{param_instance_id}/roles", + body=marshal_SetUserRoleRequest( + SetUserRoleRequest( + instance_id=instance_id, + user_name=user_name, + region=region, + roles=roles, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_User(res.json()) + async def delete_endpoint( self, *, diff --git a/scaleway-async/scaleway_async/mongodb/v1alpha1/marshalling.py b/scaleway-async/scaleway_async/mongodb/v1alpha1/marshalling.py index d491bab8..9b267ac1 100644 --- a/scaleway-async/scaleway_async/mongodb/v1alpha1/marshalling.py +++ b/scaleway-async/scaleway_async/mongodb/v1alpha1/marshalling.py @@ -18,6 +18,7 @@ Instance, SnapshotVolumeType, Snapshot, + UserRole, User, ListInstancesResponse, NodeTypeVolumeType, @@ -38,6 +39,7 @@ CreateUserRequest, RestoreSnapshotRequestVolumeDetails, RestoreSnapshotRequest, + SetUserRoleRequest, UpdateInstanceRequest, UpdateSnapshotRequest, UpdateUserRequest, @@ -301,6 +303,33 @@ def unmarshal_Snapshot(data: Any) -> Snapshot: return Snapshot(**args) +def unmarshal_UserRole(data: Any) -> UserRole: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'UserRole' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("role", None) + if field is not None: + args["role"] = field + + field = data.get("database", None) + if field is not None: + args["database"] = field + else: + args["database"] = None + + field = data.get("any_database", None) + if field is not None: + args["any_database"] = field + else: + args["any_database"] = None + + return UserRole(**args) + + def unmarshal_User(data: Any) -> User: if not isinstance(data, dict): raise TypeError( @@ -313,6 +342,12 @@ def unmarshal_User(data: Any) -> User: if field is not None: args["name"] = field + field = data.get("roles", None) + if field is not None: + args["roles"] = ( + [unmarshal_UserRole(v) for v in field] if field is not None else None + ) + return User(**args) @@ -775,6 +810,41 @@ def marshal_RestoreSnapshotRequest( return output +def marshal_UserRole( + request: UserRole, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + output.update( + resolve_one_of( + [ + OneOfPossibility("database", request.database), + OneOfPossibility("any_database", request.any_database), + ] + ), + ) + + if request.role is not None: + output["role"] = str(request.role) + + return output + + +def marshal_SetUserRoleRequest( + request: SetUserRoleRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.user_name is not None: + output["user_name"] = request.user_name + + if request.roles is not None: + output["roles"] = [marshal_UserRole(item, defaults) for item in request.roles] + + return output + + def marshal_UpdateInstanceRequest( request: UpdateInstanceRequest, defaults: ProfileDefaults, diff --git a/scaleway-async/scaleway_async/mongodb/v1alpha1/types.py b/scaleway-async/scaleway_async/mongodb/v1alpha1/types.py index a1ee3200..422e5431 100644 --- a/scaleway-async/scaleway_async/mongodb/v1alpha1/types.py +++ b/scaleway-async/scaleway_async/mongodb/v1alpha1/types.py @@ -95,6 +95,16 @@ def __str__(self) -> str: return str(self.value) +class UserRoleRole(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_ROLE = "unknown_role" + READ = "read" + READ_WRITE = "read_write" + DB_ADMIN = "db_admin" + + def __str__(self) -> str: + return str(self.value) + + class VolumeType(str, Enum, metaclass=StrEnumMeta): UNKNOWN_TYPE = "unknown_type" SBS_5K = "sbs_5k" @@ -220,6 +230,15 @@ class SnapshotVolumeType: type_: VolumeType +@dataclass +class UserRole: + role: UserRoleRole + + database: Optional[str] + + any_database: Optional[bool] + + @dataclass class Setting: name: str @@ -484,6 +503,11 @@ class User: Name of the user (Length must be between 1 and 63 characters. First character must be an alphabet character (a-zA-Z). Only a-zA-Z0-9_$- characters are accepted). """ + roles: List[UserRole] + """ + List of roles assigned to the user, along with the corresponding database where each role is granted. + """ + @dataclass class Version: @@ -959,6 +983,29 @@ class RestoreSnapshotRequest: """ +@dataclass +class SetUserRoleRequest: + instance_id: str + """ + UUID of the Database Instance the user belongs to. + """ + + user_name: str + """ + Name of the database user. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + roles: Optional[List[UserRole]] + """ + List of roles assigned to the user, along with the corresponding database where each role is granted. + """ + + @dataclass class UpdateInstanceRequest: instance_id: str diff --git a/scaleway/scaleway/mongodb/v1alpha1/__init__.py b/scaleway/scaleway/mongodb/v1alpha1/__init__.py index d1d42a9e..697dc169 100644 --- a/scaleway/scaleway/mongodb/v1alpha1/__init__.py +++ b/scaleway/scaleway/mongodb/v1alpha1/__init__.py @@ -9,6 +9,7 @@ from .types import SettingPropertyType from .types import SnapshotStatus from .content import SNAPSHOT_TRANSIENT_STATUSES +from .types import UserRoleRole from .types import VolumeType from .types import EndpointPrivateNetworkDetails from .types import EndpointPublicDetails @@ -19,6 +20,7 @@ from .types import Volume from .types import NodeTypeVolumeType from .types import SnapshotVolumeType +from .types import UserRole from .types import Setting from .types import EndpointSpec from .types import CreateInstanceRequestVolumeDetails @@ -50,6 +52,7 @@ from .types import ListVersionsRequest from .types import ListVersionsResponse from .types import RestoreSnapshotRequest +from .types import SetUserRoleRequest from .types import UpdateInstanceRequest from .types import UpdateSnapshotRequest from .types import UpdateUserRequest @@ -66,6 +69,7 @@ "SettingPropertyType", "SnapshotStatus", "SNAPSHOT_TRANSIENT_STATUSES", + "UserRoleRole", "VolumeType", "EndpointPrivateNetworkDetails", "EndpointPublicDetails", @@ -76,6 +80,7 @@ "Volume", "NodeTypeVolumeType", "SnapshotVolumeType", + "UserRole", "Setting", "EndpointSpec", "CreateInstanceRequestVolumeDetails", @@ -107,6 +112,7 @@ "ListVersionsRequest", "ListVersionsResponse", "RestoreSnapshotRequest", + "SetUserRoleRequest", "UpdateInstanceRequest", "UpdateSnapshotRequest", "UpdateUserRequest", diff --git a/scaleway/scaleway/mongodb/v1alpha1/api.py b/scaleway/scaleway/mongodb/v1alpha1/api.py index 6745175a..1af85656 100644 --- a/scaleway/scaleway/mongodb/v1alpha1/api.py +++ b/scaleway/scaleway/mongodb/v1alpha1/api.py @@ -37,12 +37,14 @@ NodeType, RestoreSnapshotRequest, RestoreSnapshotRequestVolumeDetails, + SetUserRoleRequest, Snapshot, UpdateInstanceRequest, UpdateSnapshotRequest, UpdateUserRequest, UpgradeInstanceRequest, User, + UserRole, Version, ) from .content import ( @@ -64,6 +66,7 @@ marshal_CreateSnapshotRequest, marshal_CreateUserRequest, marshal_RestoreSnapshotRequest, + marshal_SetUserRoleRequest, marshal_UpdateInstanceRequest, marshal_UpdateSnapshotRequest, marshal_UpdateUserRequest, @@ -1207,6 +1210,52 @@ def delete_user( self._throw_on_error(res) + def set_user_role( + self, + *, + instance_id: str, + user_name: str, + region: Optional[ScwRegion] = None, + roles: Optional[List[UserRole]] = None, + ) -> User: + """ + :param instance_id: UUID of the Database Instance the user belongs to. + :param user_name: Name of the database user. + :param region: Region to target. If none is passed will use default region from the config. + :param roles: List of roles assigned to the user, along with the corresponding database where each role is granted. + :return: :class:`User ` + + Usage: + :: + + result = api.set_user_role( + instance_id="example", + user_name="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "PUT", + f"/mongodb/v1alpha1/regions/{param_region}/instances/{param_instance_id}/roles", + body=marshal_SetUserRoleRequest( + SetUserRoleRequest( + instance_id=instance_id, + user_name=user_name, + region=region, + roles=roles, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_User(res.json()) + def delete_endpoint( self, *, diff --git a/scaleway/scaleway/mongodb/v1alpha1/marshalling.py b/scaleway/scaleway/mongodb/v1alpha1/marshalling.py index d491bab8..9b267ac1 100644 --- a/scaleway/scaleway/mongodb/v1alpha1/marshalling.py +++ b/scaleway/scaleway/mongodb/v1alpha1/marshalling.py @@ -18,6 +18,7 @@ Instance, SnapshotVolumeType, Snapshot, + UserRole, User, ListInstancesResponse, NodeTypeVolumeType, @@ -38,6 +39,7 @@ CreateUserRequest, RestoreSnapshotRequestVolumeDetails, RestoreSnapshotRequest, + SetUserRoleRequest, UpdateInstanceRequest, UpdateSnapshotRequest, UpdateUserRequest, @@ -301,6 +303,33 @@ def unmarshal_Snapshot(data: Any) -> Snapshot: return Snapshot(**args) +def unmarshal_UserRole(data: Any) -> UserRole: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'UserRole' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("role", None) + if field is not None: + args["role"] = field + + field = data.get("database", None) + if field is not None: + args["database"] = field + else: + args["database"] = None + + field = data.get("any_database", None) + if field is not None: + args["any_database"] = field + else: + args["any_database"] = None + + return UserRole(**args) + + def unmarshal_User(data: Any) -> User: if not isinstance(data, dict): raise TypeError( @@ -313,6 +342,12 @@ def unmarshal_User(data: Any) -> User: if field is not None: args["name"] = field + field = data.get("roles", None) + if field is not None: + args["roles"] = ( + [unmarshal_UserRole(v) for v in field] if field is not None else None + ) + return User(**args) @@ -775,6 +810,41 @@ def marshal_RestoreSnapshotRequest( return output +def marshal_UserRole( + request: UserRole, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + output.update( + resolve_one_of( + [ + OneOfPossibility("database", request.database), + OneOfPossibility("any_database", request.any_database), + ] + ), + ) + + if request.role is not None: + output["role"] = str(request.role) + + return output + + +def marshal_SetUserRoleRequest( + request: SetUserRoleRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.user_name is not None: + output["user_name"] = request.user_name + + if request.roles is not None: + output["roles"] = [marshal_UserRole(item, defaults) for item in request.roles] + + return output + + def marshal_UpdateInstanceRequest( request: UpdateInstanceRequest, defaults: ProfileDefaults, diff --git a/scaleway/scaleway/mongodb/v1alpha1/types.py b/scaleway/scaleway/mongodb/v1alpha1/types.py index a1ee3200..422e5431 100644 --- a/scaleway/scaleway/mongodb/v1alpha1/types.py +++ b/scaleway/scaleway/mongodb/v1alpha1/types.py @@ -95,6 +95,16 @@ def __str__(self) -> str: return str(self.value) +class UserRoleRole(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_ROLE = "unknown_role" + READ = "read" + READ_WRITE = "read_write" + DB_ADMIN = "db_admin" + + def __str__(self) -> str: + return str(self.value) + + class VolumeType(str, Enum, metaclass=StrEnumMeta): UNKNOWN_TYPE = "unknown_type" SBS_5K = "sbs_5k" @@ -220,6 +230,15 @@ class SnapshotVolumeType: type_: VolumeType +@dataclass +class UserRole: + role: UserRoleRole + + database: Optional[str] + + any_database: Optional[bool] + + @dataclass class Setting: name: str @@ -484,6 +503,11 @@ class User: Name of the user (Length must be between 1 and 63 characters. First character must be an alphabet character (a-zA-Z). Only a-zA-Z0-9_$- characters are accepted). """ + roles: List[UserRole] + """ + List of roles assigned to the user, along with the corresponding database where each role is granted. + """ + @dataclass class Version: @@ -959,6 +983,29 @@ class RestoreSnapshotRequest: """ +@dataclass +class SetUserRoleRequest: + instance_id: str + """ + UUID of the Database Instance the user belongs to. + """ + + user_name: str + """ + Name of the database user. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + roles: Optional[List[UserRole]] + """ + List of roles assigned to the user, along with the corresponding database where each role is granted. + """ + + @dataclass class UpdateInstanceRequest: instance_id: str