Skip to content

feat(instance): add encrypted rdp password method #523

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 1 commit into from
May 21, 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
6 changes: 6 additions & 0 deletions scaleway-async/scaleway_async/instance/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
from .types import CreateSnapshotResponse
from .types import CreateVolumeRequest
from .types import CreateVolumeResponse
from .types import DeleteEncryptedRdpPasswordRequest
from .types import DeleteImageRequest
from .types import DeleteIpRequest
from .types import DeletePlacementGroupRequest
Expand All @@ -115,6 +116,8 @@
from .types import GetBootscriptResponse
from .types import GetDashboardRequest
from .types import GetDashboardResponse
from .types import GetEncryptedRdpPasswordRequest
from .types import GetEncryptedRdpPasswordResponse
from .types import GetImageRequest
from .types import GetImageResponse
from .types import GetIpRequest
Expand Down Expand Up @@ -296,6 +299,7 @@
"CreateSnapshotResponse",
"CreateVolumeRequest",
"CreateVolumeResponse",
"DeleteEncryptedRdpPasswordRequest",
"DeleteImageRequest",
"DeleteIpRequest",
"DeletePlacementGroupRequest",
Expand All @@ -314,6 +318,8 @@
"GetBootscriptResponse",
"GetDashboardRequest",
"GetDashboardResponse",
"GetEncryptedRdpPasswordRequest",
"GetEncryptedRdpPasswordResponse",
"GetImageRequest",
"GetImageResponse",
"GetIpRequest",
Expand Down
67 changes: 67 additions & 0 deletions scaleway-async/scaleway_async/instance/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
ExportSnapshotResponse,
GetBootscriptResponse,
GetDashboardResponse,
GetEncryptedRdpPasswordResponse,
GetImageResponse,
GetIpResponse,
GetPlacementGroupResponse,
Expand Down Expand Up @@ -165,6 +166,7 @@
unmarshal_ExportSnapshotResponse,
unmarshal_GetBootscriptResponse,
unmarshal_GetDashboardResponse,
unmarshal_GetEncryptedRdpPasswordResponse,
unmarshal_GetImageResponse,
unmarshal_GetIpResponse,
unmarshal_GetPlacementGroupResponse,
Expand Down Expand Up @@ -528,6 +530,7 @@ async def _create_server(
tags: Optional[List[str]] = None,
security_group: Optional[str] = None,
placement_group: Optional[str] = None,
admin_password_encryption_ssh_key_id: Optional[str] = None,
) -> CreateServerResponse:
"""
Create an Instance.
Expand All @@ -552,6 +555,7 @@ async def _create_server(
:param tags: Instance tags.
:param security_group: Security group ID.
:param placement_group: Placement group ID if Instance must be part of a placement group.
:param admin_password_encryption_ssh_key_id: UUID of the SSH RSA key that will be used to encrypt the initial admin password for OS requiring it. Mandatory for Windows OS.
:return: :class:`CreateServerResponse <CreateServerResponse>`

Usage:
Expand Down Expand Up @@ -585,6 +589,7 @@ async def _create_server(
tags=tags,
security_group=security_group,
placement_group=placement_group,
admin_password_encryption_ssh_key_id=admin_password_encryption_ssh_key_id,
project=project,
organization=organization,
),
Expand Down Expand Up @@ -4169,3 +4174,65 @@ async def apply_block_migration(
)

self._throw_on_error(res)

async def get_encrypted_rdp_password(
self,
*,
server_id: str,
zone: Optional[Zone] = None,
) -> GetEncryptedRdpPasswordResponse:
"""
Get the encrypted RDP password.
Get the initial administrator password for Windows RDP. This password is encrypted using the SSH RSA key specified at the time of Instance creation.
:param server_id: UUID of the Instance.
:param zone: Zone to target. If none is passed will use default zone from the config.
:return: :class:`GetEncryptedRdpPasswordResponse <GetEncryptedRdpPasswordResponse>`

Usage:
::

result = await api.get_encrypted_rdp_password(
server_id="example",
)
"""

param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_server_id = validate_path_param("server_id", server_id)

res = self._request(
"GET",
f"/instance/v1/zones/{param_zone}/servers/{param_server_id}/encrypted_rdp_password",
)

self._throw_on_error(res)
return unmarshal_GetEncryptedRdpPasswordResponse(res.json())

async def delete_encrypted_rdp_password(
self,
*,
server_id: str,
zone: Optional[Zone] = None,
) -> None:
"""
Delete the encrypted RDP password.
Delete the initial administrator password for Windows RDP.
:param server_id: UUID of the Instance.
:param zone: Zone to target. If none is passed will use default zone from the config.

Usage:
::

result = await api.delete_encrypted_rdp_password(
server_id="example",
)
"""

param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_server_id = validate_path_param("server_id", server_id)

res = self._request(
"DELETE",
f"/instance/v1/zones/{param_zone}/servers/{param_server_id}/encrypted_rdp_password",
)

self._throw_on_error(res)
37 changes: 37 additions & 0 deletions scaleway-async/scaleway_async/instance/v1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
GetBootscriptResponse,
Dashboard,
GetDashboardResponse,
GetEncryptedRdpPasswordResponse,
GetImageResponse,
GetIpResponse,
GetPlacementGroupResponse,
Expand Down Expand Up @@ -1565,6 +1566,37 @@ def unmarshal_GetDashboardResponse(data: Any) -> GetDashboardResponse:
return GetDashboardResponse(**args)


def unmarshal_GetEncryptedRdpPasswordResponse(
data: Any,
) -> GetEncryptedRdpPasswordResponse:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'GetEncryptedRdpPasswordResponse' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("value", None)
if field is not None:
args["value"] = field
else:
args["value"] = None

field = data.get("admin_password_encryption_ssh_key_description", None)
if field is not None:
args["admin_password_encryption_ssh_key_description"] = field
else:
args["admin_password_encryption_ssh_key_description"] = None

field = data.get("admin_password_encryption_ssh_key_id", None)
if field is not None:
args["admin_password_encryption_ssh_key_id"] = field
else:
args["admin_password_encryption_ssh_key_id"] = None

return GetEncryptedRdpPasswordResponse(**args)


def unmarshal_GetImageResponse(data: Any) -> GetImageResponse:
if not isinstance(data, dict):
raise TypeError(
Expand Down Expand Up @@ -3089,6 +3121,11 @@ def marshal_CreateServerRequest(
if request.placement_group is not None:
output["placement_group"] = request.placement_group

if request.admin_password_encryption_ssh_key_id is not None:
output["admin_password_encryption_ssh_key_id"] = (
request.admin_password_encryption_ssh_key_id
)

return output


Expand Down
49 changes: 49 additions & 0 deletions scaleway-async/scaleway_async/instance/v1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,11 @@ class CreateServerRequest:
Placement group ID if Instance must be part of a placement group.
"""

admin_password_encryption_ssh_key_id: Optional[str]
"""
UUID of the SSH RSA key that will be used to encrypt the initial admin password for OS requiring it. Mandatory for Windows OS.
"""

project: Optional[str]

organization: Optional[str]
Expand Down Expand Up @@ -1959,6 +1964,19 @@ class CreateVolumeResponse:
volume: Optional[Volume]


@dataclass
class DeleteEncryptedRdpPasswordRequest:
server_id: str
"""
UUID of the Instance.
"""

zone: Optional[Zone]
"""
Zone to target. If none is passed will use default zone from the config.
"""


@dataclass
class DeleteImageRequest:
image_id: str
Expand Down Expand Up @@ -2172,6 +2190,37 @@ class GetDashboardResponse:
dashboard: Optional[Dashboard]


@dataclass
class GetEncryptedRdpPasswordRequest:
server_id: str
"""
UUID of the Instance.
"""

zone: Optional[Zone]
"""
Zone to target. If none is passed will use default zone from the config.
"""


@dataclass
class GetEncryptedRdpPasswordResponse:
value: Optional[str]
"""
The encrypted RDP password.
"""

admin_password_encryption_ssh_key_description: Optional[str]
"""
The description of the SSH key used for ciphering.
"""

admin_password_encryption_ssh_key_id: Optional[str]
"""
The UUID of the SSH key used for ciphering.
"""


@dataclass
class GetImageRequest:
image_id: str
Expand Down
6 changes: 6 additions & 0 deletions scaleway/scaleway/instance/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
from .types import CreateSnapshotResponse
from .types import CreateVolumeRequest
from .types import CreateVolumeResponse
from .types import DeleteEncryptedRdpPasswordRequest
from .types import DeleteImageRequest
from .types import DeleteIpRequest
from .types import DeletePlacementGroupRequest
Expand All @@ -115,6 +116,8 @@
from .types import GetBootscriptResponse
from .types import GetDashboardRequest
from .types import GetDashboardResponse
from .types import GetEncryptedRdpPasswordRequest
from .types import GetEncryptedRdpPasswordResponse
from .types import GetImageRequest
from .types import GetImageResponse
from .types import GetIpRequest
Expand Down Expand Up @@ -296,6 +299,7 @@
"CreateSnapshotResponse",
"CreateVolumeRequest",
"CreateVolumeResponse",
"DeleteEncryptedRdpPasswordRequest",
"DeleteImageRequest",
"DeleteIpRequest",
"DeletePlacementGroupRequest",
Expand All @@ -314,6 +318,8 @@
"GetBootscriptResponse",
"GetDashboardRequest",
"GetDashboardResponse",
"GetEncryptedRdpPasswordRequest",
"GetEncryptedRdpPasswordResponse",
"GetImageRequest",
"GetImageResponse",
"GetIpRequest",
Expand Down
Loading