@nilovonjs/hcloud-js 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -0
- package/package.json +70 -0
- package/src/apis/actions/index.ts +113 -0
- package/src/apis/actions/schemas.ts +59 -0
- package/src/apis/actions/types.ts +77 -0
- package/src/apis/certificates/index.ts +326 -0
- package/src/apis/certificates/schemas.ts +140 -0
- package/src/apis/certificates/types.ts +176 -0
- package/src/apis/common/schemas.ts +19 -0
- package/src/apis/dns/index.ts +961 -0
- package/src/apis/dns/schemas.ts +437 -0
- package/src/apis/dns/types.ts +397 -0
- package/src/apis/firewalls/index.ts +469 -0
- package/src/apis/firewalls/schemas.ts +274 -0
- package/src/apis/firewalls/types.ts +205 -0
- package/src/apis/floating-ips/index.ts +466 -0
- package/src/apis/floating-ips/schemas.ts +203 -0
- package/src/apis/floating-ips/types.ts +207 -0
- package/src/apis/images/index.ts +195 -0
- package/src/apis/images/schemas.ts +113 -0
- package/src/apis/images/types.ts +124 -0
- package/src/apis/isos/index.ts +91 -0
- package/src/apis/isos/schemas.ts +43 -0
- package/src/apis/isos/types.ts +60 -0
- package/src/apis/load-balancers/index.ts +892 -0
- package/src/apis/load-balancers/schemas.ts +561 -0
- package/src/apis/load-balancers/types.ts +361 -0
- package/src/apis/locations/index.ts +176 -0
- package/src/apis/locations/schemas.ts +83 -0
- package/src/apis/locations/types.ts +113 -0
- package/src/apis/networks/index.ts +544 -0
- package/src/apis/networks/schemas.ts +279 -0
- package/src/apis/networks/types.ts +243 -0
- package/src/apis/placement-groups/index.ts +212 -0
- package/src/apis/placement-groups/schemas.ts +90 -0
- package/src/apis/placement-groups/types.ts +99 -0
- package/src/apis/pricing/index.ts +42 -0
- package/src/apis/pricing/schemas.ts +93 -0
- package/src/apis/pricing/types.ts +71 -0
- package/src/apis/primary-ips/index.ts +467 -0
- package/src/apis/primary-ips/schemas.ts +221 -0
- package/src/apis/primary-ips/types.ts +221 -0
- package/src/apis/server-types/index.ts +93 -0
- package/src/apis/server-types/schemas.ts +29 -0
- package/src/apis/server-types/types.ts +43 -0
- package/src/apis/servers/index.ts +378 -0
- package/src/apis/servers/schemas.ts +771 -0
- package/src/apis/servers/types.ts +538 -0
- package/src/apis/ssh-keys/index.ts +204 -0
- package/src/apis/ssh-keys/schemas.ts +84 -0
- package/src/apis/ssh-keys/types.ts +106 -0
- package/src/apis/volumes/index.ts +452 -0
- package/src/apis/volumes/schemas.ts +195 -0
- package/src/apis/volumes/types.ts +197 -0
- package/src/auth/index.ts +26 -0
- package/src/base/index.ts +10 -0
- package/src/client/index.ts +388 -0
- package/src/config/index.ts +34 -0
- package/src/errors/index.ts +38 -0
- package/src/index.ts +799 -0
- package/src/types/index.ts +37 -0
- package/src/validation/index.ts +109 -0
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hetzner Cloud Floating IPs API
|
|
3
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { HCloudClient } from "../../client/index";
|
|
7
|
+
import type {
|
|
8
|
+
ListFloatingIPsParams,
|
|
9
|
+
ListFloatingIPsResponse,
|
|
10
|
+
CreateFloatingIPParams,
|
|
11
|
+
CreateFloatingIPResponse,
|
|
12
|
+
GetFloatingIPResponse,
|
|
13
|
+
UpdateFloatingIPParams,
|
|
14
|
+
UpdateFloatingIPResponse,
|
|
15
|
+
DeleteFloatingIPResponse,
|
|
16
|
+
ListFloatingIPActionsParams,
|
|
17
|
+
ListFloatingIPActionsResponse,
|
|
18
|
+
GetFloatingIPActionResponse,
|
|
19
|
+
AssignFloatingIPToServerParams,
|
|
20
|
+
AssignFloatingIPToServerResponse,
|
|
21
|
+
ChangeFloatingIPReverseDNSParams,
|
|
22
|
+
ChangeFloatingIPReverseDNSResponse,
|
|
23
|
+
ChangeFloatingIPProtectionParams,
|
|
24
|
+
ChangeFloatingIPProtectionResponse,
|
|
25
|
+
UnassignFloatingIPResponse,
|
|
26
|
+
} from "../../apis/floating-ips/types";
|
|
27
|
+
import { validate } from "../../validation/index";
|
|
28
|
+
import {
|
|
29
|
+
listFloatingIPsResponseSchema,
|
|
30
|
+
createFloatingIPRequestSchema,
|
|
31
|
+
createFloatingIPResponseSchema,
|
|
32
|
+
getFloatingIPResponseSchema,
|
|
33
|
+
updateFloatingIPRequestSchema,
|
|
34
|
+
updateFloatingIPResponseSchema,
|
|
35
|
+
deleteFloatingIPResponseSchema,
|
|
36
|
+
listFloatingIPActionsResponseSchema,
|
|
37
|
+
getFloatingIPActionResponseSchema,
|
|
38
|
+
assignFloatingIPToServerRequestSchema,
|
|
39
|
+
assignFloatingIPToServerResponseSchema,
|
|
40
|
+
changeFloatingIPReverseDNSRequestSchema,
|
|
41
|
+
changeFloatingIPReverseDNSResponseSchema,
|
|
42
|
+
changeFloatingIPProtectionRequestSchema,
|
|
43
|
+
changeFloatingIPProtectionResponseSchema,
|
|
44
|
+
unassignFloatingIPRequestSchema,
|
|
45
|
+
unassignFloatingIPResponseSchema,
|
|
46
|
+
} from "../../apis/floating-ips/schemas";
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Floating IPs API client
|
|
50
|
+
*/
|
|
51
|
+
export class FloatingIPsClient {
|
|
52
|
+
constructor(private readonly client: HCloudClient) {}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Returns all Floating IP objects.
|
|
56
|
+
*
|
|
57
|
+
* @param params - Query parameters for filtering and pagination
|
|
58
|
+
* @returns Promise resolving to list of floating IPs with pagination metadata
|
|
59
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-list-floating-ips
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
64
|
+
*
|
|
65
|
+
* // List all floating IPs
|
|
66
|
+
* const result = await client.floatingIPs.list();
|
|
67
|
+
*
|
|
68
|
+
* // List floating IPs with filters
|
|
69
|
+
* const floatingIPs = await client.floatingIPs.list({
|
|
70
|
+
* name: 'my-floating-ip',
|
|
71
|
+
* label_selector: 'environment=production',
|
|
72
|
+
* sort: ['name:asc'],
|
|
73
|
+
* page: 1,
|
|
74
|
+
* per_page: 50
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
async list(params?: ListFloatingIPsParams): Promise<ListFloatingIPsResponse> {
|
|
79
|
+
const queryParams: Record<string, string | number | string[] | undefined> = {};
|
|
80
|
+
|
|
81
|
+
if (params?.name) {
|
|
82
|
+
queryParams.name = params.name;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (params?.label_selector) {
|
|
86
|
+
queryParams.label_selector = params.label_selector;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (params?.sort) {
|
|
90
|
+
queryParams.sort = Array.isArray(params.sort) ? params.sort : [params.sort];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (params?.page !== undefined) {
|
|
94
|
+
queryParams.page = params.page;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (params?.per_page !== undefined) {
|
|
98
|
+
queryParams.per_page = params.per_page;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const response = await this.client.get<unknown>("/floating_ips", queryParams);
|
|
102
|
+
|
|
103
|
+
return validate(listFloatingIPsResponseSchema, response, {
|
|
104
|
+
context: "List floating IPs response",
|
|
105
|
+
detailed: true,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Creates a new Floating IP.
|
|
111
|
+
*
|
|
112
|
+
* @param params - Parameters for creating the floating IP
|
|
113
|
+
* @returns Promise resolving to the created floating IP and action
|
|
114
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-create-a-floating-ip
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
119
|
+
*
|
|
120
|
+
* // Create an IPv4 floating IP in a location
|
|
121
|
+
* const floatingIP = await client.floatingIPs.create({
|
|
122
|
+
* type: 'ipv4',
|
|
123
|
+
* location: 'nbg1',
|
|
124
|
+
* name: 'my-floating-ip'
|
|
125
|
+
* });
|
|
126
|
+
*
|
|
127
|
+
* // Create an IPv4 floating IP and assign to a server
|
|
128
|
+
* const floatingIP = await client.floatingIPs.create({
|
|
129
|
+
* type: 'ipv4',
|
|
130
|
+
* server: 12345,
|
|
131
|
+
* name: 'my-floating-ip'
|
|
132
|
+
* });
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
async create(params: CreateFloatingIPParams): Promise<CreateFloatingIPResponse> {
|
|
136
|
+
const validatedParams = validate(createFloatingIPRequestSchema, params, {
|
|
137
|
+
context: "Create floating IP request",
|
|
138
|
+
detailed: true,
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const response = await this.client.post<unknown>("/floating_ips", validatedParams);
|
|
142
|
+
|
|
143
|
+
return validate(createFloatingIPResponseSchema, response, {
|
|
144
|
+
context: "Create floating IP response",
|
|
145
|
+
detailed: true,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Returns a specific Floating IP object.
|
|
151
|
+
*
|
|
152
|
+
* @param id - ID of the Floating IP
|
|
153
|
+
* @returns Promise resolving to the floating IP
|
|
154
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-get-a-floating-ip
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
159
|
+
*
|
|
160
|
+
* // Get a floating IP by ID
|
|
161
|
+
* const floatingIP = await client.floatingIPs.get(12345);
|
|
162
|
+
* console.log(floatingIP.floating_ip.ip);
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
async get(id: number): Promise<GetFloatingIPResponse> {
|
|
166
|
+
const response = await this.client.get<unknown>(`/floating_ips/${id}`);
|
|
167
|
+
|
|
168
|
+
return validate(getFloatingIPResponseSchema, response, {
|
|
169
|
+
context: "Get floating IP response",
|
|
170
|
+
detailed: true,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Updates the Floating IP.
|
|
176
|
+
*
|
|
177
|
+
* You can update a Floating IP's name and labels.
|
|
178
|
+
*
|
|
179
|
+
* @param id - ID of the Floating IP
|
|
180
|
+
* @param params - Parameters to update (name, description, and/or labels)
|
|
181
|
+
* @returns Promise resolving to the updated floating IP
|
|
182
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-update-a-floating-ip
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
187
|
+
*
|
|
188
|
+
* // Update floating IP name
|
|
189
|
+
* const updated = await client.floatingIPs.update(12345, {
|
|
190
|
+
* name: 'new-floating-ip-name'
|
|
191
|
+
* });
|
|
192
|
+
*
|
|
193
|
+
* // Update labels
|
|
194
|
+
* const updated = await client.floatingIPs.update(12345, {
|
|
195
|
+
* labels: { environment: 'production', team: 'backend' }
|
|
196
|
+
* });
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
async update(
|
|
200
|
+
id: number,
|
|
201
|
+
params: UpdateFloatingIPParams,
|
|
202
|
+
): Promise<UpdateFloatingIPResponse> {
|
|
203
|
+
const validatedParams = validate(updateFloatingIPRequestSchema, params, {
|
|
204
|
+
context: "Update floating IP request",
|
|
205
|
+
detailed: true,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const response = await this.client.put<unknown>(`/floating_ips/${id}`, validatedParams);
|
|
209
|
+
|
|
210
|
+
return validate(updateFloatingIPResponseSchema, response, {
|
|
211
|
+
context: "Update floating IP response",
|
|
212
|
+
detailed: true,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Deletes a Floating IP.
|
|
218
|
+
*
|
|
219
|
+
* @param id - ID of the Floating IP
|
|
220
|
+
* @returns Promise resolving to the delete action
|
|
221
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-delete-a-floating-ip
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```typescript
|
|
225
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
226
|
+
*
|
|
227
|
+
* // Delete a floating IP
|
|
228
|
+
* const result = await client.floatingIPs.delete(12345);
|
|
229
|
+
* if (result.action) {
|
|
230
|
+
* console.log(`Delete action ID: ${result.action.id}`);
|
|
231
|
+
* }
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
async delete(id: number): Promise<DeleteFloatingIPResponse> {
|
|
235
|
+
const response = await this.client.delete<unknown>(`/floating_ips/${id}`);
|
|
236
|
+
|
|
237
|
+
return validate(deleteFloatingIPResponseSchema, response, {
|
|
238
|
+
context: "Delete floating IP response",
|
|
239
|
+
detailed: true,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Returns all Action objects for a Floating IP.
|
|
245
|
+
*
|
|
246
|
+
* @param id - ID of the Floating IP
|
|
247
|
+
* @param params - Query parameters for filtering and pagination
|
|
248
|
+
* @returns Promise resolving to list of actions with pagination metadata
|
|
249
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-list-actions-for-a-floating-ip
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```typescript
|
|
253
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
254
|
+
*
|
|
255
|
+
* // List all actions for a floating IP
|
|
256
|
+
* const actions = await client.floatingIPs.listActions(12345);
|
|
257
|
+
*
|
|
258
|
+
* // List actions with filters
|
|
259
|
+
* const runningActions = await client.floatingIPs.listActions(12345, {
|
|
260
|
+
* status: ['running'],
|
|
261
|
+
* sort: ['started:desc']
|
|
262
|
+
* });
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
async listActions(
|
|
266
|
+
id: number,
|
|
267
|
+
params?: ListFloatingIPActionsParams,
|
|
268
|
+
): Promise<ListFloatingIPActionsResponse> {
|
|
269
|
+
const queryParams: Record<string, string | number | string[] | undefined> = {};
|
|
270
|
+
|
|
271
|
+
if (params?.sort) {
|
|
272
|
+
queryParams.sort = Array.isArray(params.sort) ? params.sort : [params.sort];
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (params?.status) {
|
|
276
|
+
queryParams.status = Array.isArray(params.status) ? params.status : [params.status];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (params?.page !== undefined) {
|
|
280
|
+
queryParams.page = params.page;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (params?.per_page !== undefined) {
|
|
284
|
+
queryParams.per_page = params.per_page;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const response = await this.client.get<unknown>(`/floating_ips/${id}/actions`, queryParams);
|
|
288
|
+
|
|
289
|
+
return validate(listFloatingIPActionsResponseSchema, response, {
|
|
290
|
+
context: "List floating IP actions response",
|
|
291
|
+
detailed: true,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Returns a specific Action object for a Floating IP.
|
|
297
|
+
*
|
|
298
|
+
* @param id - ID of the Floating IP
|
|
299
|
+
* @param actionId - ID of the Action
|
|
300
|
+
* @returns Promise resolving to the action
|
|
301
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-get-an-action-for-a-floating-ip
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```typescript
|
|
305
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
306
|
+
*
|
|
307
|
+
* // Get an action by ID
|
|
308
|
+
* const action = await client.floatingIPs.getAction(12345, 67890);
|
|
309
|
+
* console.log(action.action.command);
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
async getAction(id: number, actionId: number): Promise<GetFloatingIPActionResponse> {
|
|
313
|
+
const response = await this.client.get<unknown>(`/floating_ips/${id}/actions/${actionId}`);
|
|
314
|
+
|
|
315
|
+
return validate(getFloatingIPActionResponseSchema, response, {
|
|
316
|
+
context: "Get floating IP action response",
|
|
317
|
+
detailed: true,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Assigns a Floating IP to a Server.
|
|
323
|
+
*
|
|
324
|
+
* @param id - ID of the Floating IP
|
|
325
|
+
* @param params - Server ID to assign the floating IP to
|
|
326
|
+
* @returns Promise resolving to the action
|
|
327
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-assign-a-floating-ip-to-a-server
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```typescript
|
|
331
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
332
|
+
*
|
|
333
|
+
* // Assign floating IP to a server
|
|
334
|
+
* const result = await client.floatingIPs.assignToServer(12345, {
|
|
335
|
+
* assignee_id: 67890
|
|
336
|
+
* });
|
|
337
|
+
* console.log(`Action ID: ${result.action.id}`);
|
|
338
|
+
* ```
|
|
339
|
+
*/
|
|
340
|
+
async assignToServer(
|
|
341
|
+
id: number,
|
|
342
|
+
params: AssignFloatingIPToServerParams,
|
|
343
|
+
): Promise<AssignFloatingIPToServerResponse> {
|
|
344
|
+
const validatedParams = validate(assignFloatingIPToServerRequestSchema, params, {
|
|
345
|
+
context: "Assign floating IP to server request",
|
|
346
|
+
detailed: true,
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
const response = await this.client.post<unknown>(
|
|
350
|
+
`/floating_ips/${id}/actions/assign`,
|
|
351
|
+
validatedParams,
|
|
352
|
+
);
|
|
353
|
+
|
|
354
|
+
return validate(assignFloatingIPToServerResponseSchema, response, {
|
|
355
|
+
context: "Assign floating IP to server response",
|
|
356
|
+
detailed: true,
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Changes the hostname that will appear when getting the hostname belonging to this Floating IP.
|
|
362
|
+
*
|
|
363
|
+
* @param id - ID of the Floating IP
|
|
364
|
+
* @param params - Reverse DNS configuration
|
|
365
|
+
* @returns Promise resolving to the action
|
|
366
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-change-reverse-dns-records-for-a-floating-ip
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```typescript
|
|
370
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
371
|
+
*
|
|
372
|
+
* // Change reverse DNS
|
|
373
|
+
* const result = await client.floatingIPs.changeReverseDNS(12345, {
|
|
374
|
+
* ip: '1.2.3.4',
|
|
375
|
+
* dns_ptr: 'server.example.com'
|
|
376
|
+
* });
|
|
377
|
+
* console.log(`Action ID: ${result.action.id}`);
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
async changeReverseDNS(
|
|
381
|
+
id: number,
|
|
382
|
+
params: ChangeFloatingIPReverseDNSParams,
|
|
383
|
+
): Promise<ChangeFloatingIPReverseDNSResponse> {
|
|
384
|
+
const validatedParams = validate(changeFloatingIPReverseDNSRequestSchema, params, {
|
|
385
|
+
context: "Change floating IP reverse DNS request",
|
|
386
|
+
detailed: true,
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
const response = await this.client.post<unknown>(
|
|
390
|
+
`/floating_ips/${id}/actions/change_dns_ptr`,
|
|
391
|
+
validatedParams,
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
return validate(changeFloatingIPReverseDNSResponseSchema, response, {
|
|
395
|
+
context: "Change floating IP reverse DNS response",
|
|
396
|
+
detailed: true,
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Changes the Protection configuration of a Floating IP.
|
|
402
|
+
*
|
|
403
|
+
* @param id - ID of the Floating IP
|
|
404
|
+
* @param params - Protection configuration
|
|
405
|
+
* @returns Promise resolving to the action
|
|
406
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-change-floating-ip-protection
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* ```typescript
|
|
410
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
411
|
+
*
|
|
412
|
+
* // Enable delete protection
|
|
413
|
+
* const result = await client.floatingIPs.changeProtection(12345, {
|
|
414
|
+
* delete: true
|
|
415
|
+
* });
|
|
416
|
+
* console.log(`Action ID: ${result.action.id}`);
|
|
417
|
+
* ```
|
|
418
|
+
*/
|
|
419
|
+
async changeProtection(
|
|
420
|
+
id: number,
|
|
421
|
+
params: ChangeFloatingIPProtectionParams,
|
|
422
|
+
): Promise<ChangeFloatingIPProtectionResponse> {
|
|
423
|
+
const validatedParams = validate(changeFloatingIPProtectionRequestSchema, params, {
|
|
424
|
+
context: "Change floating IP protection request",
|
|
425
|
+
detailed: true,
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
const response = await this.client.post<unknown>(
|
|
429
|
+
`/floating_ips/${id}/actions/change_protection`,
|
|
430
|
+
validatedParams,
|
|
431
|
+
);
|
|
432
|
+
|
|
433
|
+
return validate(changeFloatingIPProtectionResponseSchema, response, {
|
|
434
|
+
context: "Change floating IP protection response",
|
|
435
|
+
detailed: true,
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Unassigns a Floating IP, resulting in it being unreachable.
|
|
441
|
+
*
|
|
442
|
+
* @param id - ID of the Floating IP
|
|
443
|
+
* @returns Promise resolving to the action
|
|
444
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-unassign-a-floating-ip
|
|
445
|
+
*
|
|
446
|
+
* @example
|
|
447
|
+
* ```typescript
|
|
448
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
449
|
+
*
|
|
450
|
+
* // Unassign floating IP
|
|
451
|
+
* const result = await client.floatingIPs.unassign(12345);
|
|
452
|
+
* console.log(`Action ID: ${result.action.id}`);
|
|
453
|
+
* ```
|
|
454
|
+
*/
|
|
455
|
+
async unassign(id: number): Promise<UnassignFloatingIPResponse> {
|
|
456
|
+
const response = await this.client.post<unknown>(
|
|
457
|
+
`/floating_ips/${id}/actions/unassign`,
|
|
458
|
+
{},
|
|
459
|
+
);
|
|
460
|
+
|
|
461
|
+
return validate(unassignFloatingIPResponseSchema, response, {
|
|
462
|
+
context: "Unassign floating IP response",
|
|
463
|
+
detailed: true,
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for Hetzner Cloud Floating IPs API
|
|
3
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { actionSchema, actionResourceSchema } from "../../apis/actions/schemas";
|
|
8
|
+
import { paginationMetaSchema } from "../../apis/common/schemas";
|
|
9
|
+
import { locationSchema } from "../../apis/servers/schemas";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Floating IP type schema
|
|
13
|
+
*/
|
|
14
|
+
export const floatingIpTypeSchema = z.enum(["ipv4", "ipv6"]);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Floating IP DNS pointer schema
|
|
18
|
+
*/
|
|
19
|
+
export const floatingIpDnsPointerSchema = z.object({
|
|
20
|
+
ip: z.string(),
|
|
21
|
+
dns_ptr: z.string(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Floating IP protection schema
|
|
26
|
+
*/
|
|
27
|
+
export const floatingIpProtectionSchema = z.object({
|
|
28
|
+
delete: z.boolean(),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Floating IP schema
|
|
33
|
+
*/
|
|
34
|
+
export const floatingIpSchema = z
|
|
35
|
+
.object({
|
|
36
|
+
id: z.number(),
|
|
37
|
+
name: z.string().nullable(),
|
|
38
|
+
description: z.string().nullable(),
|
|
39
|
+
ip: z.string(),
|
|
40
|
+
type: floatingIpTypeSchema,
|
|
41
|
+
server: z.number().nullable(),
|
|
42
|
+
dns_ptr: z.array(floatingIpDnsPointerSchema),
|
|
43
|
+
location: locationSchema,
|
|
44
|
+
labels: z.record(z.string(), z.string()),
|
|
45
|
+
blocking: z.array(actionResourceSchema).optional(),
|
|
46
|
+
created: z.string(),
|
|
47
|
+
protection: floatingIpProtectionSchema,
|
|
48
|
+
})
|
|
49
|
+
.passthrough();
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* List Floating IPs response schema
|
|
53
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-list-floating-ips
|
|
54
|
+
*/
|
|
55
|
+
export const listFloatingIPsResponseSchema = z.object({
|
|
56
|
+
floating_ips: z.array(floatingIpSchema),
|
|
57
|
+
meta: z
|
|
58
|
+
.object({
|
|
59
|
+
pagination: paginationMetaSchema,
|
|
60
|
+
})
|
|
61
|
+
.optional(),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Create Floating IP request schema
|
|
66
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-create-a-floating-ip
|
|
67
|
+
*/
|
|
68
|
+
export const createFloatingIPRequestSchema = z.object({
|
|
69
|
+
type: floatingIpTypeSchema,
|
|
70
|
+
name: z.string().optional(),
|
|
71
|
+
description: z.string().nullable().optional(),
|
|
72
|
+
location: z.string().optional(),
|
|
73
|
+
server: z.number().optional(),
|
|
74
|
+
home_location: z.string().optional(),
|
|
75
|
+
labels: z.record(z.string(), z.string()).optional(),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Create Floating IP response schema
|
|
80
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-create-a-floating-ip
|
|
81
|
+
*/
|
|
82
|
+
export const createFloatingIPResponseSchema = z.object({
|
|
83
|
+
floating_ip: floatingIpSchema,
|
|
84
|
+
action: actionSchema,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Get Floating IP response schema
|
|
89
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-get-a-floating-ip
|
|
90
|
+
*/
|
|
91
|
+
export const getFloatingIPResponseSchema = z.object({
|
|
92
|
+
floating_ip: floatingIpSchema,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Update Floating IP request schema
|
|
97
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-update-a-floating-ip
|
|
98
|
+
*/
|
|
99
|
+
export const updateFloatingIPRequestSchema = z.object({
|
|
100
|
+
name: z.string().nullable().optional(),
|
|
101
|
+
description: z.string().nullable().optional(),
|
|
102
|
+
labels: z.record(z.string(), z.string()).optional(),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Update Floating IP response schema
|
|
107
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-update-a-floating-ip
|
|
108
|
+
*/
|
|
109
|
+
export const updateFloatingIPResponseSchema = z.object({
|
|
110
|
+
floating_ip: floatingIpSchema,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Delete Floating IP response schema
|
|
115
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-delete-a-floating-ip
|
|
116
|
+
*/
|
|
117
|
+
export const deleteFloatingIPResponseSchema = z.object({
|
|
118
|
+
action: actionSchema.optional(),
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* List Floating IP Actions response schema
|
|
123
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-list-actions-for-a-floating-ip
|
|
124
|
+
*/
|
|
125
|
+
export const listFloatingIPActionsResponseSchema = z.object({
|
|
126
|
+
actions: z.array(actionSchema),
|
|
127
|
+
meta: z
|
|
128
|
+
.object({
|
|
129
|
+
pagination: paginationMetaSchema,
|
|
130
|
+
})
|
|
131
|
+
.optional(),
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Get Floating IP Action response schema
|
|
136
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-get-an-action-for-a-floating-ip
|
|
137
|
+
*/
|
|
138
|
+
export const getFloatingIPActionResponseSchema = z.object({
|
|
139
|
+
action: actionSchema,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Assign Floating IP to Server request schema
|
|
144
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-assign-a-floating-ip-to-a-server
|
|
145
|
+
*/
|
|
146
|
+
export const assignFloatingIPToServerRequestSchema = z.object({
|
|
147
|
+
assignee_id: z.number(),
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Assign Floating IP to Server response schema
|
|
152
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-assign-a-floating-ip-to-a-server
|
|
153
|
+
*/
|
|
154
|
+
export const assignFloatingIPToServerResponseSchema = z.object({
|
|
155
|
+
action: actionSchema,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Change Floating IP reverse DNS request schema
|
|
160
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-change-reverse-dns-records-for-a-floating-ip
|
|
161
|
+
*/
|
|
162
|
+
export const changeFloatingIPReverseDNSRequestSchema = z.object({
|
|
163
|
+
ip: z.string(),
|
|
164
|
+
dns_ptr: z.string().nullable(),
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Change Floating IP reverse DNS response schema
|
|
169
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-change-reverse-dns-records-for-a-floating-ip
|
|
170
|
+
*/
|
|
171
|
+
export const changeFloatingIPReverseDNSResponseSchema = z.object({
|
|
172
|
+
action: actionSchema,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Change Floating IP Protection request schema
|
|
177
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-change-floating-ip-protection
|
|
178
|
+
*/
|
|
179
|
+
export const changeFloatingIPProtectionRequestSchema = z.object({
|
|
180
|
+
delete: z.boolean(),
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Change Floating IP Protection response schema
|
|
185
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-change-floating-ip-protection
|
|
186
|
+
*/
|
|
187
|
+
export const changeFloatingIPProtectionResponseSchema = z.object({
|
|
188
|
+
action: actionSchema,
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Unassign Floating IP request schema
|
|
193
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-unassign-a-floating-ip
|
|
194
|
+
*/
|
|
195
|
+
export const unassignFloatingIPRequestSchema = z.object({});
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Unassign Floating IP response schema
|
|
199
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-unassign-a-floating-ip
|
|
200
|
+
*/
|
|
201
|
+
export const unassignFloatingIPResponseSchema = z.object({
|
|
202
|
+
action: actionSchema,
|
|
203
|
+
});
|