Skip to content
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
20 changes: 20 additions & 0 deletions packages/clients/src/api/instance/v1/api.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import type {
CreateServerRequest,
DetachVolumeRequest,
DetachVolumeResponse,
SetServerUserDataRequest,
UpdateImageRequest,
UpdateImageResponse,
UpdateSecurityGroupRequest,
Expand Down Expand Up @@ -510,4 +511,23 @@ export class InstanceV1UtilsAPI extends API {
),
)
.then(res => ({ image: res.image }))

/**
* Sets the content of a user data on a server for the given key.
*
* @param request - The request {@link SetServerUserDataRequest}
*/
setServerUserData = (request: Readonly<SetServerUserDataRequest>) =>
this.client.fetch<void>({
body: request.content,
headers: { 'Content-Type': 'text/plain' },
method: 'PATCH',
path: `/instance/v1/zones/${validatePathParam(
'zone',
request.zone ?? this.client.settings.defaultZone,
)}/servers/${validatePathParam(
'serverId',
request.serverId,
)}/user_data/${validatePathParam('key', request.key)}`,
})
}
10 changes: 10 additions & 0 deletions packages/clients/src/api/instance/v1/types.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ export interface UpdateImageResponse {
image?: Image
}

export type SetServerUserDataRequest = {
/** Zone to target. If none is passed will use default zone from the config */
zone?: Zone
serverId: string
/** The user data key to set */
key: string
/** The data encoded in base64 */
content: string
}

export type {
CreateServerRequest,
UpdateServerRequest,
Expand Down