Skip to content

Commit

Permalink
feat(instance): add encrypted rdp password method (#1282)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored May 21, 2024
1 parent da7490a commit 421e1fc
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/clients/src/api/instance/v1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
unmarshalExportSnapshotResponse,
unmarshalGetBootscriptResponse,
unmarshalGetDashboardResponse,
unmarshalGetEncryptedRdpPasswordResponse,
unmarshalGetImageResponse,
unmarshalGetIpResponse,
unmarshalGetPlacementGroupResponse,
Expand Down Expand Up @@ -123,6 +124,7 @@ import type {
CreateSnapshotResponse,
CreateVolumeRequest,
CreateVolumeResponse,
DeleteEncryptedRdpPasswordRequest,
DeleteImageRequest,
DeleteIpRequest,
DeletePlacementGroupRequest,
Expand All @@ -141,6 +143,8 @@ import type {
GetBootscriptResponse,
GetDashboardRequest,
GetDashboardResponse,
GetEncryptedRdpPasswordRequest,
GetEncryptedRdpPasswordResponse,
GetImageRequest,
GetImageResponse,
GetIpRequest,
Expand Down Expand Up @@ -1622,4 +1626,37 @@ export class API extends ParentAPI {
method: 'POST',
path: `/instance/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/block-migration/apply`,
})

/**
* 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 request - The request {@link GetEncryptedRdpPasswordRequest}
* @returns A Promise of GetEncryptedRdpPasswordResponse
*/
getEncryptedRdpPassword = (
request: Readonly<GetEncryptedRdpPasswordRequest>,
) =>
this.client.fetch<GetEncryptedRdpPasswordResponse>(
{
method: 'GET',
path: `/instance/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/servers/${validatePathParam('serverId', request.serverId)}/encrypted_rdp_password`,
},
unmarshalGetEncryptedRdpPasswordResponse,
)

/**
* Delete the encrypted RDP password. Delete the initial administrator
* password for Windows RDP.
*
* @param request - The request {@link DeleteEncryptedRdpPasswordRequest}
*/
deleteEncryptedRdpPassword = (
request: Readonly<DeleteEncryptedRdpPasswordRequest>,
) =>
this.client.fetch<void>({
method: 'DELETE',
path: `/instance/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/servers/${validatePathParam('serverId', request.serverId)}/encrypted_rdp_password`,
})
}
3 changes: 3 additions & 0 deletions packages/clients/src/api/instance/v1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type {
CreateVolumeRequest,
CreateVolumeResponse,
Dashboard,
DeleteEncryptedRdpPasswordRequest,
DeleteImageRequest,
DeleteIpRequest,
DeletePlacementGroupRequest,
Expand All @@ -47,6 +48,8 @@ export type {
GetBootscriptResponse,
GetDashboardRequest,
GetDashboardResponse,
GetEncryptedRdpPasswordRequest,
GetEncryptedRdpPasswordResponse,
GetImageRequest,
GetImageResponse,
GetIpRequest,
Expand Down
19 changes: 19 additions & 0 deletions packages/clients/src/api/instance/v1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import type {
ExportSnapshotResponse,
GetBootscriptResponse,
GetDashboardResponse,
GetEncryptedRdpPasswordResponse,
GetImageResponse,
GetIpResponse,
GetPlacementGroupResponse,
Expand Down Expand Up @@ -800,6 +801,23 @@ export const unmarshalGetDashboardResponse = (
} as GetDashboardResponse
}

export const unmarshalGetEncryptedRdpPasswordResponse = (
data: unknown,
): GetEncryptedRdpPasswordResponse => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'GetEncryptedRdpPasswordResponse' failed as data isn't a dictionary.`,
)
}

return {
adminPasswordEncryptionSshKeyDescription:
data.admin_password_encryption_ssh_key_description,
adminPasswordEncryptionSshKeyId: data.admin_password_encryption_ssh_key_id,
value: data.value,
} as GetEncryptedRdpPasswordResponse
}

export const unmarshalGetImageResponse = (data: unknown): GetImageResponse => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand Down Expand Up @@ -1818,6 +1836,7 @@ export const marshalCreateServerRequest = (
request: CreateServerRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
admin_password_encryption_ssh_key_id: request.adminPasswordEncryptionSshKeyId,
boot_type: request.bootType,
bootscript: request.bootscript,
commercial_type: request.commercialType,
Expand Down
28 changes: 28 additions & 0 deletions packages/clients/src/api/instance/v1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,11 @@ export type CreateServerRequest = {
securityGroup?: string
/** Placement group ID if Instance must be part of a placement group. */
placementGroup?: string
/**
* UUID of the SSH RSA key that will be used to encrypt the initial admin
* password for OS requiring it. Mandatory for Windows OS.
*/
adminPasswordEncryptionSshKeyId?: string
}

export interface CreateServerResponse {
Expand Down Expand Up @@ -1123,6 +1128,13 @@ export interface CreateVolumeResponse {
volume?: Volume
}

export type DeleteEncryptedRdpPasswordRequest = {
/** Zone to target. If none is passed will use default zone from the config. */
zone?: Zone
/** UUID of the Instance. */
serverId: string
}

export type DeleteImageRequest = {
/** Zone to target. If none is passed will use default zone from the config. */
zone?: Zone
Expand Down Expand Up @@ -1243,6 +1255,22 @@ export interface GetDashboardResponse {
dashboard?: Dashboard
}

export type GetEncryptedRdpPasswordRequest = {
/** Zone to target. If none is passed will use default zone from the config. */
zone?: Zone
/** UUID of the Instance. */
serverId: string
}

export interface GetEncryptedRdpPasswordResponse {
/** The encrypted RDP password. */
value?: string
/** The description of the SSH key used for ciphering. */
adminPasswordEncryptionSshKeyDescription?: string
/** The UUID of the SSH key used for ciphering. */
adminPasswordEncryptionSshKeyId?: string
}

export type GetImageRequest = {
/** Zone to target. If none is passed will use default zone from the config. */
zone?: Zone
Expand Down

0 comments on commit 421e1fc

Please sign in to comment.