hetzner-robot-cli 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/LICENSE +21 -0
- package/README.md +440 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +934 -0
- package/dist/client.d.ts +256 -0
- package/dist/client.js +656 -0
- package/dist/config.d.ts +41 -0
- package/dist/config.js +109 -0
- package/dist/formatter.d.ts +85 -0
- package/dist/formatter.js +617 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +9 -0
- package/dist/types.d.ts +352 -0
- package/dist/types.js +5 -0
- package/package.json +89 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
# hetzner-robot-cli
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/hetzner-robot-cli)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
Feature-complete CLI and Node.js library for the [Hetzner Robot API](https://robot.hetzner.com/doc/webservice/en.html) (dedicated servers).
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- **Complete API Coverage**: Servers, Reset, Boot (Rescue/Linux/VNC/Windows), IPs, Subnets, Failover, rDNS, SSH Keys, Firewall, vSwitch, Storage Box, Traffic, Wake-on-LAN, Ordering
|
|
11
|
+
- **CLI & Library**: Use from command line or import in your Node.js/TypeScript projects
|
|
12
|
+
- **TypeScript**: Full type definitions included
|
|
13
|
+
- **Secure Auth**: Multiple authentication methods including stdin for secure password passing
|
|
14
|
+
- **Interactive Mode**: Menu-driven interface for common operations
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# Global CLI installation
|
|
20
|
+
npm install -g hetzner-robot-cli
|
|
21
|
+
|
|
22
|
+
# Project dependency
|
|
23
|
+
npm install hetzner-robot-cli
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Getting Credentials
|
|
27
|
+
|
|
28
|
+
1. Go to [robot.hetzner.com](https://robot.hetzner.com)
|
|
29
|
+
2. Navigate to: **Settings > Web service settings**
|
|
30
|
+
3. Create a new web service user
|
|
31
|
+
|
|
32
|
+
> **Note:** This is separate from your main Hetzner account login.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Library Usage
|
|
37
|
+
|
|
38
|
+
### Basic Example
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { HetznerRobotClient } from 'hetzner-robot-cli';
|
|
42
|
+
|
|
43
|
+
const client = new HetznerRobotClient('username', 'password');
|
|
44
|
+
|
|
45
|
+
// List all servers
|
|
46
|
+
const servers = await client.listServers();
|
|
47
|
+
console.log(servers);
|
|
48
|
+
|
|
49
|
+
// Get server details
|
|
50
|
+
const server = await client.getServer('123.456.78.90');
|
|
51
|
+
console.log(server);
|
|
52
|
+
|
|
53
|
+
// Reset a server
|
|
54
|
+
await client.resetServer(123456, 'sw'); // software reset
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Server Management
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { HetznerRobotClient } from 'hetzner-robot-cli';
|
|
61
|
+
|
|
62
|
+
const client = new HetznerRobotClient(
|
|
63
|
+
process.env.HETZNER_USER!,
|
|
64
|
+
process.env.HETZNER_PASSWORD!
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// List servers
|
|
68
|
+
const servers = await client.listServers();
|
|
69
|
+
|
|
70
|
+
// Get server details
|
|
71
|
+
const details = await client.getServer(123456);
|
|
72
|
+
|
|
73
|
+
// Rename server
|
|
74
|
+
await client.updateServerName(123456, 'my-new-name');
|
|
75
|
+
|
|
76
|
+
// Cancel server
|
|
77
|
+
await client.cancelServer(123456, '2024-12-31', ['price']);
|
|
78
|
+
|
|
79
|
+
// Revoke cancellation
|
|
80
|
+
await client.revokeCancellation(123456);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Reset Operations
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
// Get reset options
|
|
87
|
+
const options = await client.getResetOptions(123456);
|
|
88
|
+
console.log('Available reset types:', options.reset.type);
|
|
89
|
+
|
|
90
|
+
// Execute reset
|
|
91
|
+
// Types: 'sw' (software), 'hw' (hardware), 'man' (manual), 'power', 'power_long'
|
|
92
|
+
await client.resetServer(123456, 'sw');
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Boot Configuration (Rescue Mode)
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
// Activate rescue system
|
|
99
|
+
const rescue = await client.activateRescue(123456, 'linux', 64, ['ssh-key-fingerprint']);
|
|
100
|
+
console.log('Rescue password:', rescue.rescue.password);
|
|
101
|
+
|
|
102
|
+
// Deactivate rescue
|
|
103
|
+
await client.deactivateRescue(123456);
|
|
104
|
+
|
|
105
|
+
// Get last rescue activation
|
|
106
|
+
const lastRescue = await client.getLastRescue(123456);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Linux Installation
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
// Get available distributions
|
|
113
|
+
const linux = await client.getLinux(123456);
|
|
114
|
+
console.log('Available distros:', linux.linux.dist);
|
|
115
|
+
|
|
116
|
+
// Activate Linux installation
|
|
117
|
+
await client.activateLinux(123456, 'Debian-1210-bookworm-amd64-base', 64, 'en', ['ssh-fingerprint']);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Failover IP Management
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
// List failover IPs
|
|
124
|
+
const failovers = await client.listFailovers();
|
|
125
|
+
|
|
126
|
+
// Switch failover to another server
|
|
127
|
+
await client.switchFailover('failover-ip', 'target-server-ip');
|
|
128
|
+
|
|
129
|
+
// Delete failover routing
|
|
130
|
+
await client.deleteFailoverRouting('failover-ip');
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### SSH Key Management
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
// List SSH keys
|
|
137
|
+
const keys = await client.listSshKeys();
|
|
138
|
+
|
|
139
|
+
// Add SSH key
|
|
140
|
+
const newKey = await client.createSshKey('my-key', 'ssh-rsa AAAA...');
|
|
141
|
+
|
|
142
|
+
// Delete SSH key
|
|
143
|
+
await client.deleteSshKey('fingerprint');
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Storage Box
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
// List storage boxes
|
|
150
|
+
const boxes = await client.listStorageBoxes();
|
|
151
|
+
|
|
152
|
+
// Get storage box details
|
|
153
|
+
const box = await client.getStorageBox(123);
|
|
154
|
+
|
|
155
|
+
// Create snapshot
|
|
156
|
+
await client.createStorageBoxSnapshot(123);
|
|
157
|
+
|
|
158
|
+
// List snapshots
|
|
159
|
+
const snapshots = await client.listStorageBoxSnapshots(123);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Firewall
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
// Get firewall config
|
|
166
|
+
const firewall = await client.getFirewall(123456);
|
|
167
|
+
|
|
168
|
+
// Enable/disable firewall
|
|
169
|
+
await client.updateFirewall(123456, 'active');
|
|
170
|
+
await client.updateFirewall(123456, 'disabled');
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Full Type Support
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
import {
|
|
177
|
+
HetznerRobotClient,
|
|
178
|
+
Server,
|
|
179
|
+
ServerDetails,
|
|
180
|
+
Reset,
|
|
181
|
+
ResetType,
|
|
182
|
+
RescueConfig,
|
|
183
|
+
Failover,
|
|
184
|
+
SshKey,
|
|
185
|
+
StorageBox,
|
|
186
|
+
} from 'hetzner-robot-cli';
|
|
187
|
+
|
|
188
|
+
// All responses are fully typed
|
|
189
|
+
const servers: { server: Server }[] = await client.listServers();
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## CLI Usage
|
|
195
|
+
|
|
196
|
+
### Authentication
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Interactive login (saves to ~/.hetzner-cli/config.json)
|
|
200
|
+
hetzner auth login
|
|
201
|
+
|
|
202
|
+
# Environment variables
|
|
203
|
+
export HETZNER_ROBOT_USER=myuser
|
|
204
|
+
export HETZNER_ROBOT_PASSWORD=mypassword
|
|
205
|
+
|
|
206
|
+
# Command-line flags
|
|
207
|
+
hetzner server list --user myuser --password mypassword
|
|
208
|
+
|
|
209
|
+
# Secure: read password from stdin (not in shell history)
|
|
210
|
+
echo "$PASSWORD" | hetzner server list --user myuser --password -
|
|
211
|
+
|
|
212
|
+
# With 1Password
|
|
213
|
+
op read "op://vault/item/password" | hetzner server list -u $(op read "op://vault/item/user") -p -
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Server Commands
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
hetzner server list # List all servers
|
|
220
|
+
hetzner server get 123456 # Get server details
|
|
221
|
+
hetzner server rename 123456 new-name # Rename server
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Reset Commands
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
hetzner reset options 123456 # Show reset options
|
|
228
|
+
hetzner reset execute 123456 # Software reset (default)
|
|
229
|
+
hetzner reset execute 123456 -t hw # Hardware reset
|
|
230
|
+
hetzner reset execute 123456 -i # Interactive type selection
|
|
231
|
+
hetzner reset execute 123 456 789 -y # Reset multiple, skip confirmation
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Boot Commands
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
hetzner boot status 123456 # Show boot config
|
|
238
|
+
hetzner boot rescue activate 123456 --os linux # Activate rescue
|
|
239
|
+
hetzner boot rescue deactivate 123456 # Deactivate rescue
|
|
240
|
+
hetzner boot linux options 123456 # Show Linux distros
|
|
241
|
+
hetzner boot linux activate 123456 -d Debian-12... # Install Linux
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### IP & Network Commands
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
hetzner ip list # List IPs
|
|
248
|
+
hetzner subnet list # List subnets
|
|
249
|
+
hetzner failover list # List failover IPs
|
|
250
|
+
hetzner failover switch 1.2.3.4 5.6.7.8 # Switch failover
|
|
251
|
+
hetzner rdns list # List reverse DNS
|
|
252
|
+
hetzner rdns set 1.2.3.4 host.example.com
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### SSH Key Commands
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
hetzner key list # List SSH keys
|
|
259
|
+
hetzner key add my-key -f ~/.ssh/id_rsa.pub
|
|
260
|
+
hetzner key delete ab:cd:ef:12:34:56
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Storage Box Commands
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
hetzner storagebox list # List storage boxes
|
|
267
|
+
hetzner storagebox get 123 # Get details
|
|
268
|
+
hetzner storagebox snapshot list 123 # List snapshots
|
|
269
|
+
hetzner storagebox snapshot create 123 # Create snapshot
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Other Commands
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
hetzner firewall get 123456 # Get firewall config
|
|
276
|
+
hetzner vswitch list # List vSwitches
|
|
277
|
+
hetzner traffic query --ip 1.2.3.4 # Query traffic
|
|
278
|
+
hetzner wol send 123456 # Wake on LAN
|
|
279
|
+
hetzner cancel status 123456 # Cancellation status
|
|
280
|
+
hetzner order products # List products
|
|
281
|
+
hetzner order market # Server auction
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Interactive Mode
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
hetzner interactive
|
|
288
|
+
# or
|
|
289
|
+
hetzner i
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### JSON Output
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
hetzner server list --json # Raw JSON output
|
|
296
|
+
hetzner server list --json | jq '.[].server.server_ip'
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## API Reference
|
|
302
|
+
|
|
303
|
+
### HetznerRobotClient
|
|
304
|
+
|
|
305
|
+
#### Constructor
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
new HetznerRobotClient(username: string, password: string)
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
#### Server Methods
|
|
312
|
+
|
|
313
|
+
| Method | Description |
|
|
314
|
+
|--------|-------------|
|
|
315
|
+
| `listServers()` | List all servers |
|
|
316
|
+
| `getServer(id)` | Get server details |
|
|
317
|
+
| `updateServerName(id, name)` | Rename server |
|
|
318
|
+
| `getCancellation(id)` | Get cancellation status |
|
|
319
|
+
| `cancelServer(id, date?, reasons?)` | Cancel server |
|
|
320
|
+
| `revokeCancellation(id)` | Revoke cancellation |
|
|
321
|
+
|
|
322
|
+
#### Reset Methods
|
|
323
|
+
|
|
324
|
+
| Method | Description |
|
|
325
|
+
|--------|-------------|
|
|
326
|
+
| `listResetOptions()` | List all reset options |
|
|
327
|
+
| `getResetOptions(id)` | Get reset options for server |
|
|
328
|
+
| `resetServer(id, type?)` | Reset server (sw/hw/man/power/power_long) |
|
|
329
|
+
|
|
330
|
+
#### Boot Methods
|
|
331
|
+
|
|
332
|
+
| Method | Description |
|
|
333
|
+
|--------|-------------|
|
|
334
|
+
| `getBootConfig(id)` | Get all boot configs |
|
|
335
|
+
| `activateRescue(id, os, arch?, keys?)` | Activate rescue |
|
|
336
|
+
| `deactivateRescue(id)` | Deactivate rescue |
|
|
337
|
+
| `activateLinux(id, dist, arch?, lang?, keys?)` | Activate Linux install |
|
|
338
|
+
| `deactivateLinux(id)` | Deactivate Linux |
|
|
339
|
+
| `activateVnc(id, dist, arch?, lang?)` | Activate VNC install |
|
|
340
|
+
| `activateWindows(id, dist, lang?)` | Activate Windows install |
|
|
341
|
+
|
|
342
|
+
#### IP Methods
|
|
343
|
+
|
|
344
|
+
| Method | Description |
|
|
345
|
+
|--------|-------------|
|
|
346
|
+
| `listIps()` | List all IPs |
|
|
347
|
+
| `getIp(ip)` | Get IP details |
|
|
348
|
+
| `updateIp(ip, warnings?, hourly?, daily?, monthly?)` | Update IP settings |
|
|
349
|
+
| `generateIpMac(ip)` | Generate separate MAC |
|
|
350
|
+
| `deleteIpMac(ip)` | Delete MAC |
|
|
351
|
+
|
|
352
|
+
#### Failover Methods
|
|
353
|
+
|
|
354
|
+
| Method | Description |
|
|
355
|
+
|--------|-------------|
|
|
356
|
+
| `listFailovers()` | List failover IPs |
|
|
357
|
+
| `getFailover(ip)` | Get failover details |
|
|
358
|
+
| `switchFailover(ip, targetIp)` | Switch routing |
|
|
359
|
+
| `deleteFailoverRouting(ip)` | Delete routing |
|
|
360
|
+
|
|
361
|
+
#### SSH Key Methods
|
|
362
|
+
|
|
363
|
+
| Method | Description |
|
|
364
|
+
|--------|-------------|
|
|
365
|
+
| `listSshKeys()` | List SSH keys |
|
|
366
|
+
| `getSshKey(fingerprint)` | Get key details |
|
|
367
|
+
| `createSshKey(name, data)` | Add SSH key |
|
|
368
|
+
| `updateSshKey(fingerprint, name)` | Rename key |
|
|
369
|
+
| `deleteSshKey(fingerprint)` | Delete key |
|
|
370
|
+
|
|
371
|
+
#### Firewall Methods
|
|
372
|
+
|
|
373
|
+
| Method | Description |
|
|
374
|
+
|--------|-------------|
|
|
375
|
+
| `getFirewall(id)` | Get firewall config |
|
|
376
|
+
| `updateFirewall(id, status, rules?)` | Update firewall |
|
|
377
|
+
| `deleteFirewall(id)` | Delete all rules |
|
|
378
|
+
| `listFirewallTemplates()` | List templates |
|
|
379
|
+
|
|
380
|
+
#### vSwitch Methods
|
|
381
|
+
|
|
382
|
+
| Method | Description |
|
|
383
|
+
|--------|-------------|
|
|
384
|
+
| `listVSwitches()` | List vSwitches |
|
|
385
|
+
| `getVSwitch(id)` | Get vSwitch details |
|
|
386
|
+
| `createVSwitch(name, vlan)` | Create vSwitch |
|
|
387
|
+
| `updateVSwitch(id, name?, vlan?)` | Update vSwitch |
|
|
388
|
+
| `deleteVSwitch(id, date?)` | Delete vSwitch |
|
|
389
|
+
| `addServerToVSwitch(vswitchId, serverId)` | Add server |
|
|
390
|
+
| `removeServerFromVSwitch(vswitchId, serverId)` | Remove server |
|
|
391
|
+
|
|
392
|
+
#### Storage Box Methods
|
|
393
|
+
|
|
394
|
+
| Method | Description |
|
|
395
|
+
|--------|-------------|
|
|
396
|
+
| `listStorageBoxes()` | List storage boxes |
|
|
397
|
+
| `getStorageBox(id)` | Get details |
|
|
398
|
+
| `updateStorageBox(id, ...)` | Update settings |
|
|
399
|
+
| `resetStorageBoxPassword(id)` | Reset password |
|
|
400
|
+
| `listStorageBoxSnapshots(id)` | List snapshots |
|
|
401
|
+
| `createStorageBoxSnapshot(id)` | Create snapshot |
|
|
402
|
+
| `deleteStorageBoxSnapshot(id, name)` | Delete snapshot |
|
|
403
|
+
| `revertStorageBoxSnapshot(id, name)` | Revert to snapshot |
|
|
404
|
+
|
|
405
|
+
#### Other Methods
|
|
406
|
+
|
|
407
|
+
| Method | Description |
|
|
408
|
+
|--------|-------------|
|
|
409
|
+
| `listRdns()` | List reverse DNS |
|
|
410
|
+
| `createRdns(ip, ptr)` | Create rDNS |
|
|
411
|
+
| `deleteRdns(ip)` | Delete rDNS |
|
|
412
|
+
| `getTraffic(ips, subnets, from, to, type)` | Query traffic |
|
|
413
|
+
| `sendWol(id)` | Send Wake-on-LAN |
|
|
414
|
+
| `listServerProducts()` | List products |
|
|
415
|
+
| `listServerMarketProducts()` | List auction servers |
|
|
416
|
+
|
|
417
|
+
---
|
|
418
|
+
|
|
419
|
+
## Development
|
|
420
|
+
|
|
421
|
+
```bash
|
|
422
|
+
# Install dependencies
|
|
423
|
+
npm install
|
|
424
|
+
|
|
425
|
+
# Build
|
|
426
|
+
npm run build
|
|
427
|
+
|
|
428
|
+
# Run tests
|
|
429
|
+
npm test
|
|
430
|
+
|
|
431
|
+
# Run tests with coverage
|
|
432
|
+
npm run test:coverage
|
|
433
|
+
|
|
434
|
+
# Watch mode
|
|
435
|
+
npm run test:watch
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
## License
|
|
439
|
+
|
|
440
|
+
MIT
|
package/dist/cli.d.ts
ADDED