Skip to content

Commit 54b98a0

Browse files
authored
feat(instance): add setServerUserData method (#387)
1 parent 6890883 commit 54b98a0

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

packages/clients/src/api/instance/v1/api.utils.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import type {
3939
CreateServerRequest,
4040
DetachVolumeRequest,
4141
DetachVolumeResponse,
42+
SetServerUserDataRequest,
4243
UpdateImageRequest,
4344
UpdateImageResponse,
4445
UpdateSecurityGroupRequest,
@@ -510,4 +511,23 @@ export class InstanceV1UtilsAPI extends API {
510511
),
511512
)
512513
.then(res => ({ image: res.image }))
514+
515+
/**
516+
* Sets the content of a user data on a server for the given key.
517+
*
518+
* @param request - The request {@link SetServerUserDataRequest}
519+
*/
520+
setServerUserData = (request: Readonly<SetServerUserDataRequest>) =>
521+
this.client.fetch<void>({
522+
body: request.content,
523+
headers: { 'Content-Type': 'text/plain' },
524+
method: 'PATCH',
525+
path: `/instance/v1/zones/${validatePathParam(
526+
'zone',
527+
request.zone ?? this.client.settings.defaultZone,
528+
)}/servers/${validatePathParam(
529+
'serverId',
530+
request.serverId,
531+
)}/user_data/${validatePathParam('key', request.key)}`,
532+
})
513533
}

packages/clients/src/api/instance/v1/types.utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ export interface UpdateImageResponse {
106106
image?: Image
107107
}
108108

109+
export type SetServerUserDataRequest = {
110+
/** Zone to target. If none is passed will use default zone from the config */
111+
zone?: Zone
112+
serverId: string
113+
/** The user data key to set */
114+
key: string
115+
/** The data encoded in base64 */
116+
content: string
117+
}
118+
109119
export type {
110120
CreateServerRequest,
111121
UpdateServerRequest,

0 commit comments

Comments
 (0)