Skip to content

Commit 415a9f0

Browse files
authored
Add volumes support (#8)
* Add basic volume support * Add basic volume support * Add Headers Response on some API Responses * Add Headers Response on some API Responses * Add Headers Response on some API Responses * Add Headers to every API Response * Add Headers to every API Response * Add Headers to every API Response * Add Headers to every API Response * Add Headers to every API Response * Add Headers to every API Response * Add Headers to every API Response * Add Headers to every API Response * Add Headers to every API Response * Add Linux Device to Volume * Add Changelog
1 parent 7e2ca60 commit 415a9f0

File tree

11 files changed

+414
-36
lines changed

11 files changed

+414
-36
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# Changelog
2+
3+
## 1.3.0 (unreleased)
4+
+ Add Volumes support (`LKDev\HetznerCloud\Models\Volumes\Volumes` & `LKDev\HetznerCloud\Models\Volumes\Volume`)
5+
6+
##### Deprecation
7+
+ Deprecate and ignore the `$backup_window` parameter on `LKDev\HetznerCloud\Models\Server\Server::enableBackups`
8+
29
## 1.2.0 (06.09.2018)
310
+ Add `httpClient`-Method to `LKDev\HetznerCloud\HetznerAPIClient`
411
+ Add `labels`-Property to `LKDev\HetznerCloud\Models\FloatingIp\FloatingIP`

src/APIResponse.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
*/
1818
class APIResponse
1919
{
20+
21+
/**
22+
* @var array
23+
*/
24+
protected $header = [];
2025
/**
2126
* @var array
2227
*/
@@ -47,14 +52,32 @@ public function setResponse(array $response)
4752
$this->response = $response;
4853
}
4954

55+
/**
56+
* @param array $header
57+
*/
58+
public function setHeader(array $header)
59+
{
60+
$this->header = $header;
61+
}
62+
63+
/**
64+
* @return array
65+
*/
66+
public function getHeader(): array
67+
{
68+
return $this->header;
69+
}
70+
5071
/**
5172
* @param array $response
73+
* @param array $header
5274
* @return APIResponse
5375
*/
54-
public static function create(array $response)
76+
public static function create(array $response, array $header = [])
5577
{
5678
$apiResponse = new APIResponse();
5779
$apiResponse->setResponse($response);
80+
$apiResponse->setHeader($header);
5881
return $apiResponse;
5982
}
6083
}

src/HetznerAPIClient.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use LKDev\HetznerCloud\Models\Servers\Servers;
1313
use LKDev\HetznerCloud\Models\Servers\Types\ServerTypes;
1414
use LKDev\HetznerCloud\Models\SSHKeys\SSHKeys;
15+
use LKDev\HetznerCloud\Models\Volumes\Volumes;
1516
use Psr\Http\Message\ResponseInterface;
1617

1718
/**
@@ -147,6 +148,14 @@ public function servers()
147148
return new Servers($this->httpClient);
148149
}
149150

151+
/**
152+
* @return Volumes
153+
*/
154+
public function volumes()
155+
{
156+
return new Volumes($this->httpClient);
157+
}
158+
150159
/**
151160
* @return ServerTypes
152161
*/

src/Models/FloatingIps/FloatingIp.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function changeProtection(bool $delete = true): APIResponse
177177
if (!HetznerAPIClient::hasError($response)) {
178178
return APIResponse::create([
179179
'action' => Action::parse(json_decode((string)$response->getBody())->action)
180-
]);
180+
], $response->getHeaders());
181181
}
182182
}
183183

@@ -199,7 +199,7 @@ public function assignTo(Server $server): APIResponse
199199
if (!HetznerAPIClient::hasError($response)) {
200200
return APIResponse::create([
201201
'action' => Action::parse(json_decode((string)$response->getBody())->action)
202-
]);
202+
], $response->getHeaders());
203203
}
204204
}
205205

@@ -216,7 +216,7 @@ public function unassign(): APIResponse
216216
if (!HetznerAPIClient::hasError($response)) {
217217
return APIResponse::create([
218218
'action' => Action::parse(json_decode((string)$response->getBody())->action)
219-
]);
219+
], $response->getHeaders());
220220
}
221221
}
222222

@@ -240,7 +240,7 @@ public function changeReverseDNS(string $ip, string $dnsPtr): APIResponse
240240
if (!HetznerAPIClient::hasError($response)) {
241241
return APIResponse::create([
242242
'action' => Action::parse(json_decode((string)$response->getBody())->action)
243-
]);
243+
], $response->getHeaders());
244244
}
245245
}
246246

src/Models/Images/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public function changeProtection(bool $delete = true): APIResponse
199199
if (!HetznerAPIClient::hasError($response)) {
200200
return APIResponse::create([
201201
'action' => Action::parse(json_decode((string)$response->getBody())->action)
202-
]);
202+
], $response->getHeaders());
203203
}
204204
}
205205

src/Models/SSHKeys/SSHKeys.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function create(
5555
* @return array
5656
* @throws \LKDev\HetznerCloud\APIException
5757
*/
58-
public function all(RequestOpts $requestOpts): array
58+
public function all(RequestOpts $requestOpts = null): array
5959
{
6060
if ($requestOpts == null) {
6161
$requestOpts = new RequestOpts();

src/Models/Servers/Server.php

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ class Server extends Model
108108
*/
109109
public $labels;
110110

111+
/**
112+
* @var array
113+
*/
114+
public $volumes;
115+
111116
/**
112117
*
113118
*
@@ -138,6 +143,7 @@ public function setAdditionalData($data)
138143
$this->outgoingTraffic = $data->outgoing_traffic ?: null;
139144
$this->ingoingTraffic = $data->ingoing_traffic ?: null;
140145
$this->includedTraffic = $data->included_traffic ?: null;
146+
$this->volumes = property_exists($data, 'volumes') ? $data->volumes : [];
141147
$this->protection = $data->protection ?: Protection::parse($data->protection);
142148
$this->labels = $data->labels;
143149
return $this;
@@ -168,7 +174,7 @@ public function powerOn(): APIResponse
168174
if (!HetznerAPIClient::hasError($response)) {
169175
return APIResponse::create([
170176
'action' => Action::parse(json_decode((string)$response->getBody())->action)
171-
]);
177+
], $response->getHeaders());
172178
}
173179
}
174180

@@ -185,7 +191,7 @@ public function softReboot(): APIResponse
185191
if (!HetznerAPIClient::hasError($response)) {
186192
return APIResponse::create([
187193
'action' => Action::parse(json_decode((string)$response->getBody())->action)
188-
]);
194+
], $response->getHeaders());
189195
}
190196
}
191197

@@ -202,7 +208,7 @@ public function reset(): APIResponse
202208
if (!HetznerAPIClient::hasError($response)) {
203209
return APIResponse::create([
204210
'action' => Action::parse(json_decode((string)$response->getBody())->action)
205-
]);
211+
], $response->getHeaders());
206212
}
207213
}
208214

@@ -219,7 +225,7 @@ public function shutdown(): APIResponse
219225
if (!HetznerAPIClient::hasError($response)) {
220226
return APIResponse::create([
221227
'action' => Action::parse(json_decode((string)$response->getBody())->action)
222-
]);
228+
], $response->getHeaders());
223229
}
224230
}
225231

@@ -236,7 +242,7 @@ public function powerOff(): APIResponse
236242
if (!HetznerAPIClient::hasError($response)) {
237243
return APIResponse::create([
238244
'action' => Action::parse(json_decode((string)$response->getBody())->action)
239-
]);
245+
], $response->getHeaders());
240246
}
241247
}
242248

@@ -255,7 +261,7 @@ public function resetRootPassword(): APIResponse
255261
return APIResponse::create([
256262
'action' => Action::parse($payload->action),
257263
'root_password' => $payload->root_password
258-
]);
264+
], $response->getHeaders());
259265
}
260266
}
261267

@@ -281,7 +287,7 @@ public function enableRescue($type = 'linux64', $ssh_keys = []): APIResponse
281287
return APIResponse::create([
282288
'action' => Action::parse($payload->action),
283289
'root_password' => $payload->root_password
284-
]);
290+
], $response->getHeaders());
285291
}
286292
}
287293

@@ -298,7 +304,7 @@ public function disableRescue(): APIResponse
298304
if (!HetznerAPIClient::hasError($response)) {
299305
return APIResponse::create([
300306
'action' => Action::parse(json_decode((string)$response->getBody())->action)
301-
]);
307+
], $response->getHeaders());
302308
}
303309
}
304310

@@ -325,7 +331,7 @@ public function createImage(string $description = '', string $type = 'snapshot')
325331
return APIResponse::create([
326332
'action' => Action::parse($payload->action),
327333
'image' => Image::parse($payload->image)
328-
]);
334+
], $response->getHeaders());
329335
}
330336
}
331337

@@ -347,7 +353,7 @@ public function rebuildFromImage(Image $image): APIResponse
347353
if (!HetznerAPIClient::hasError($response)) {
348354
return APIResponse::create([
349355
'action' => Action::parse(json_decode((string)$response->getBody())->action)
350-
]);
356+
], $response->getHeaders());
351357
}
352358
}
353359

@@ -371,29 +377,24 @@ public function changeType(ServerType $serverType, bool $upgradeDisk = false): A
371377
if (!HetznerAPIClient::hasError($response)) {
372378
return APIResponse::create([
373379
'action' => Action::parse(json_decode((string)$response->getBody())->action)
374-
]);
380+
], $response->getHeaders());
375381
}
376382
}
377383

378384
/**
379385
* Enables and configures the automatic daily backup option for the server. Enabling automatic backups will increase the price of the server by 20%
380386
*
381387
* @see https://docs.hetzner.cloud/#resources-server-actions-post-11
382-
* @param string|null $backupWindow
383388
* @return APIResponse
384389
* @throws \LKDev\HetznerCloud\APIException
385390
*/
386391
public function enableBackups(string $backupWindow = null): APIResponse
387392
{
388-
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/enable_backup'), [
389-
'json' => [
390-
'backup_window' => $backupWindow,
391-
],
392-
]);
393+
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/enable_backup'));
393394
if (!HetznerAPIClient::hasError($response)) {
394395
return APIResponse::create([
395396
'action' => Action::parse(json_decode((string)$response->getBody())->action)
396-
]);
397+
], $response->getHeaders());
397398
}
398399
}
399400

@@ -410,7 +411,7 @@ public function disableBackups(): APIResponse
410411
if (!HetznerAPIClient::hasError($response)) {
411412
return APIResponse::create([
412413
'action' => Action::parse(json_decode((string)$response->getBody())->action)
413-
]);
414+
], $response->getHeaders());
414415
}
415416
}
416417

@@ -432,7 +433,7 @@ public function attachISO(ISO $iso): APIResponse
432433
if (!HetznerAPIClient::hasError($response)) {
433434
return APIResponse::create([
434435
'action' => Action::parse(json_decode((string)$response->getBody())->action)
435-
]);
436+
], $response->getHeaders());
436437
}
437438
}
438439

@@ -449,7 +450,7 @@ public function detachISO(): APIResponse
449450
if (!HetznerAPIClient::hasError($response)) {
450451
return APIResponse::create([
451452
'action' => Action::parse(json_decode((string)$response->getBody())->action)
452-
]);
453+
], $response->getHeaders());
453454
}
454455
}
455456

@@ -473,7 +474,7 @@ public function changeReverseDNS(string $ip, string $dnsPtr): APIResponse
473474
if (!HetznerAPIClient::hasError($response)) {
474475
return APIResponse::create([
475476
'action' => Action::parse(json_decode((string)$response->getBody())->action)
476-
]);
477+
], $response->getHeaders());
477478
}
478479
}
479480

@@ -505,7 +506,7 @@ public function delete(): APIResponse
505506
if (!HetznerAPIClient::hasError($response)) {
506507
return APIResponse::create([
507508
'action' => Action::parse(json_decode((string)$response->getBody())->action)
508-
]);
509+
], $response->getHeaders());
509510
}
510511
}
511512

@@ -527,7 +528,7 @@ public function update(array $data)
527528
if (!HetznerAPIClient::hasError($response)) {
528529
return APIResponse::create([
529530
'server' => Server::parse(json_decode((string)$response->getBody())->server)
530-
]);
531+
], $response->getHeaders());
531532
}
532533
}
533534

@@ -561,7 +562,7 @@ public function requestConsole(): APIResponse
561562
'action' => Action::parse($payload->action),
562563
'wss_url' => $payload->wss_url,
563564
'password' => $payload->password
564-
]);
565+
], $response->getHeaders());
565566
}
566567
}
567568

@@ -585,7 +586,7 @@ public function changeProtection(bool $delete = true, bool $rebuild = true): API
585586
if (!HetznerAPIClient::hasError($response)) {
586587
return APIResponse::create([
587588
'action' => Action::parse(json_decode((string)$response->getBody())->action)
588-
]);
589+
], $response->getHeaders());
589590
}
590591
}
591592

src/Models/Servers/Servers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function createInDatacenter(
105105
'action' => Action::parse($payload->action),
106106
'server' => Server::parse($payload->server),
107107
], (property_exists($payload, 'root_password')) ? ['root_password' => $payload->root_password] : []
108-
));
108+
), $response->getHeaders());
109109

110110
}
111111
}
@@ -149,7 +149,7 @@ public function createInLocation(string $name,
149149
'action' => Action::parse($payload->action),
150150
'server' => Server::parse($payload->server),
151151
], (property_exists($payload, 'root_password')) ? ['root_password' => $payload->root_password] : []
152-
));
152+
), $response->getHeaders());
153153

154154
}
155155
}

0 commit comments

Comments
 (0)