Skip to content

Commit 4899229

Browse files
committed
Allow setting of "null" $dnsPtr value on changeReverseDNS of FloatingIP & Server, this resets the DNS PTR to the default value
Signed-off-by: Lukas Kämmerling <[email protected]>
1 parent c7d98af commit 4899229

File tree

5 files changed

+86
-60
lines changed

5 files changed

+86
-60
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## master
44
* Add support for creating Certificates
55
* Add support for creating resources with labels
6+
* Allow setting of "null" `$dnsPtr` value on `changeReverseDNS` of FloatingIP & Server, this resets the DNS PTR to the default value
67

78
## 2.2.2 (05.10.2020)
89

src/Models/FloatingIps/FloatingIp.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,11 @@ public function unassign(): ?APIResponse
245245
*
246246
* @see https://docs.hetzner.cloud/#floating-ip-actions-change-reverse-dns-entry-for-a-floating-ip
247247
* @param string $ip
248-
* @param string $dnsPtr
248+
* @param string|null $dnsPtr
249249
* @return APIResponse|null
250250
* @throws \LKDev\HetznerCloud\APIException
251251
*/
252-
public function changeReverseDNS(string $ip, string $dnsPtr): ?APIResponse
252+
public function changeReverseDNS(string $ip, string $dnsPtr=null): ?APIResponse
253253
{
254254
$response = $this->httpClient->post('floating_ips/'.$this->id.'/actions/change_dns_ptr', [
255255
'json' => [

src/Models/Servers/Server.php

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ public function reload()
193193
public function powerOn(): ?APIResponse
194194
{
195195
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/poweron'));
196-
if (! HetznerAPIClient::hasError($response)) {
196+
if (!HetznerAPIClient::hasError($response)) {
197197
return APIResponse::create([
198-
'action' => Action::parse(json_decode((string) $response->getBody())->action),
198+
'action' => Action::parse(json_decode((string)$response->getBody())->action),
199199
], $response->getHeaders());
200200
}
201201

@@ -212,9 +212,9 @@ public function powerOn(): ?APIResponse
212212
public function softReboot(): ?APIResponse
213213
{
214214
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/reboot'));
215-
if (! HetznerAPIClient::hasError($response)) {
215+
if (!HetznerAPIClient::hasError($response)) {
216216
return APIResponse::create([
217-
'action' => Action::parse(json_decode((string) $response->getBody())->action),
217+
'action' => Action::parse(json_decode((string)$response->getBody())->action),
218218
], $response->getHeaders());
219219
}
220220

@@ -231,9 +231,9 @@ public function softReboot(): ?APIResponse
231231
public function reset(): ?APIResponse
232232
{
233233
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/reset'));
234-
if (! HetznerAPIClient::hasError($response)) {
234+
if (!HetznerAPIClient::hasError($response)) {
235235
return APIResponse::create([
236-
'action' => Action::parse(json_decode((string) $response->getBody())->action),
236+
'action' => Action::parse(json_decode((string)$response->getBody())->action),
237237
], $response->getHeaders());
238238
}
239239

@@ -250,9 +250,9 @@ public function reset(): ?APIResponse
250250
public function shutdown(): ?APIResponse
251251
{
252252
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/shutdown'));
253-
if (! HetznerAPIClient::hasError($response)) {
253+
if (!HetznerAPIClient::hasError($response)) {
254254
return APIResponse::create([
255-
'action' => Action::parse(json_decode((string) $response->getBody())->action),
255+
'action' => Action::parse(json_decode((string)$response->getBody())->action),
256256
], $response->getHeaders());
257257
}
258258

@@ -269,9 +269,9 @@ public function shutdown(): ?APIResponse
269269
public function powerOff(): ?APIResponse
270270
{
271271
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/poweroff'));
272-
if (! HetznerAPIClient::hasError($response)) {
272+
if (!HetznerAPIClient::hasError($response)) {
273273
return APIResponse::create([
274-
'action' => Action::parse(json_decode((string) $response->getBody())->action),
274+
'action' => Action::parse(json_decode((string)$response->getBody())->action),
275275
], $response->getHeaders());
276276
}
277277

@@ -288,8 +288,8 @@ public function powerOff(): ?APIResponse
288288
public function resetRootPassword(): ?APIResponse
289289
{
290290
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/reset_password'));
291-
if (! HetznerAPIClient::hasError($response)) {
292-
$payload = json_decode((string) $response->getBody());
291+
if (!HetznerAPIClient::hasError($response)) {
292+
$payload = json_decode((string)$response->getBody());
293293

294294
return APIResponse::create([
295295
'action' => Action::parse($payload->action),
@@ -317,8 +317,8 @@ public function enableRescue($type = 'linux64', $ssh_keys = []): ?APIResponse
317317
'ssh_keys' => $ssh_keys,
318318
],
319319
]);
320-
if (! HetznerAPIClient::hasError($response)) {
321-
$payload = json_decode((string) $response->getBody());
320+
if (!HetznerAPIClient::hasError($response)) {
321+
$payload = json_decode((string)$response->getBody());
322322

323323
return APIResponse::create([
324324
'action' => Action::parse($payload->action),
@@ -339,9 +339,9 @@ public function enableRescue($type = 'linux64', $ssh_keys = []): ?APIResponse
339339
public function disableRescue(): ?APIResponse
340340
{
341341
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/disable_rescue'));
342-
if (! HetznerAPIClient::hasError($response)) {
342+
if (!HetznerAPIClient::hasError($response)) {
343343
return APIResponse::create([
344-
'action' => Action::parse(json_decode((string) $response->getBody())->action),
344+
'action' => Action::parse(json_decode((string)$response->getBody())->action),
345345
], $response->getHeaders());
346346
}
347347

@@ -364,14 +364,14 @@ public function createImage(string $description = '', string $type = 'snapshot',
364364
'description' => $description,
365365
'type' => $type,
366366
];
367-
if (! empty($labels)) {
367+
if (!empty($labels)) {
368368
$payload['labels'] = $labels;
369369
}
370370
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/create_image'), [
371371
'json' => $payload,
372372
]);
373-
if (! HetznerAPIClient::hasError($response)) {
374-
$payload = json_decode((string) $response->getBody());
373+
if (!HetznerAPIClient::hasError($response)) {
374+
$payload = json_decode((string)$response->getBody());
375375

376376
return APIResponse::create([
377377
'action' => Action::parse($payload->action),
@@ -397,8 +397,8 @@ public function rebuildFromImage(Image $image): ?APIResponse
397397
'image' => $image->id ?: $image->name,
398398
],
399399
]);
400-
if (! HetznerAPIClient::hasError($response)) {
401-
$payload = json_decode((string) $response->getBody());
400+
if (!HetznerAPIClient::hasError($response)) {
401+
$payload = json_decode((string)$response->getBody());
402402

403403
return APIResponse::create(array_merge([
404404
'action' => Action::parse($payload->action),
@@ -425,9 +425,9 @@ public function changeType(ServerType $serverType, bool $upgradeDisk = false): ?
425425
'upgrade_disk' => $upgradeDisk,
426426
],
427427
]);
428-
if (! HetznerAPIClient::hasError($response)) {
428+
if (!HetznerAPIClient::hasError($response)) {
429429
return APIResponse::create([
430-
'action' => Action::parse(json_decode((string) $response->getBody())->action),
430+
'action' => Action::parse(json_decode((string)$response->getBody())->action),
431431
], $response->getHeaders());
432432
}
433433

@@ -444,9 +444,9 @@ public function changeType(ServerType $serverType, bool $upgradeDisk = false): ?
444444
public function enableBackups(string $backupWindow = null): ?APIResponse
445445
{
446446
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/enable_backup'));
447-
if (! HetznerAPIClient::hasError($response)) {
447+
if (!HetznerAPIClient::hasError($response)) {
448448
return APIResponse::create([
449-
'action' => Action::parse(json_decode((string) $response->getBody())->action),
449+
'action' => Action::parse(json_decode((string)$response->getBody())->action),
450450
], $response->getHeaders());
451451
}
452452

@@ -463,9 +463,9 @@ public function enableBackups(string $backupWindow = null): ?APIResponse
463463
public function disableBackups(): ?APIResponse
464464
{
465465
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/disable_backup'));
466-
if (! HetznerAPIClient::hasError($response)) {
466+
if (!HetznerAPIClient::hasError($response)) {
467467
return APIResponse::create([
468-
'action' => Action::parse(json_decode((string) $response->getBody())->action),
468+
'action' => Action::parse(json_decode((string)$response->getBody())->action),
469469
], $response->getHeaders());
470470
}
471471

@@ -487,9 +487,9 @@ public function attachISO(ISO $iso): ?APIResponse
487487
'iso' => $iso->name ?: $iso->id,
488488
],
489489
]);
490-
if (! HetznerAPIClient::hasError($response)) {
490+
if (!HetznerAPIClient::hasError($response)) {
491491
return APIResponse::create([
492-
'action' => Action::parse(json_decode((string) $response->getBody())->action),
492+
'action' => Action::parse(json_decode((string)$response->getBody())->action),
493493
], $response->getHeaders());
494494
}
495495

@@ -506,9 +506,9 @@ public function attachISO(ISO $iso): ?APIResponse
506506
public function detachISO(): ?APIResponse
507507
{
508508
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/detach_iso'));
509-
if (! HetznerAPIClient::hasError($response)) {
509+
if (!HetznerAPIClient::hasError($response)) {
510510
return APIResponse::create([
511-
'action' => Action::parse(json_decode((string) $response->getBody())->action),
511+
'action' => Action::parse(json_decode((string)$response->getBody())->action),
512512
], $response->getHeaders());
513513
}
514514

@@ -520,21 +520,21 @@ public function detachISO(): ?APIResponse
520520
*
521521
* @see https://docs.hetzner.cloud/#resources-server-actions-post-15
522522
* @param string $ip
523-
* @param string $dnsPtr
523+
* @param string|null $dnsPtr
524524
* @return APIResponse|null
525525
* @throws \LKDev\HetznerCloud\APIException
526526
*/
527-
public function changeReverseDNS(string $ip, string $dnsPtr): ?APIResponse
527+
public function changeReverseDNS(string $ip, string $dnsPtr = null): ?APIResponse
528528
{
529529
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/change_dns_ptr'), [
530530
'json' => [
531531
'ip' => $ip,
532532
'dns_ptr' => $dnsPtr,
533533
],
534534
]);
535-
if (! HetznerAPIClient::hasError($response)) {
535+
if (!HetznerAPIClient::hasError($response)) {
536536
return APIResponse::create([
537-
'action' => Action::parse(json_decode((string) $response->getBody())->action),
537+
'action' => Action::parse(json_decode((string)$response->getBody())->action),
538538
], $response->getHeaders());
539539
}
540540

@@ -554,10 +554,10 @@ public function changeReverseDNS(string $ip, string $dnsPtr): ?APIResponse
554554
*/
555555
public function metrics(string $type, string $start, string $end, int $step = null)
556556
{
557-
$response = $this->httpClient->get($this->replaceServerIdInUri('servers/{id}/metrics?').http_build_query(compact('type', 'start', 'end', 'step')));
558-
if (! HetznerAPIClient::hasError($response)) {
557+
$response = $this->httpClient->get($this->replaceServerIdInUri('servers/{id}/metrics?') . http_build_query(compact('type', 'start', 'end', 'step')));
558+
if (!HetznerAPIClient::hasError($response)) {
559559
return APIResponse::create([
560-
'metrics' => json_decode((string) $response->getBody())->metrics,
560+
'metrics' => json_decode((string)$response->getBody())->metrics,
561561
], $response->getHeaders());
562562
}
563563

@@ -574,9 +574,9 @@ public function metrics(string $type, string $start, string $end, int $step = nu
574574
public function delete(): ?APIResponse
575575
{
576576
$response = $this->httpClient->delete($this->replaceServerIdInUri('servers/{id}'));
577-
if (! HetznerAPIClient::hasError($response)) {
577+
if (!HetznerAPIClient::hasError($response)) {
578578
return APIResponse::create([
579-
'action' => Action::parse(json_decode((string) $response->getBody())->action),
579+
'action' => Action::parse(json_decode((string)$response->getBody())->action),
580580
], $response->getHeaders());
581581
}
582582

@@ -596,9 +596,9 @@ public function update(array $data)
596596
$response = $this->httpClient->put($this->replaceServerIdInUri('servers/{id}'), [
597597
'json' => $data,
598598
]);
599-
if (! HetznerAPIClient::hasError($response)) {
599+
if (!HetznerAPIClient::hasError($response)) {
600600
return APIResponse::create([
601-
'server' => self::parse(json_decode((string) $response->getBody())->server),
601+
'server' => self::parse(json_decode((string)$response->getBody())->server),
602602
], $response->getHeaders());
603603
}
604604

@@ -615,8 +615,8 @@ public function update(array $data)
615615
public function requestConsole(): ?APIResponse
616616
{
617617
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/request_console'));
618-
if (! HetznerAPIClient::hasError($response)) {
619-
$payload = json_decode((string) $response->getBody());
618+
if (!HetznerAPIClient::hasError($response)) {
619+
$payload = json_decode((string)$response->getBody());
620620

621621
return APIResponse::create([
622622
'action' => Action::parse($payload->action),
@@ -645,9 +645,9 @@ public function changeProtection(bool $delete = true, bool $rebuild = true): ?AP
645645
'rebuild' => $rebuild,
646646
],
647647
]);
648-
if (! HetznerAPIClient::hasError($response)) {
648+
if (!HetznerAPIClient::hasError($response)) {
649649
return APIResponse::create([
650-
'action' => Action::parse(json_decode((string) $response->getBody())->action),
650+
'action' => Action::parse(json_decode((string)$response->getBody())->action),
651651
], $response->getHeaders());
652652
}
653653

@@ -675,9 +675,9 @@ public function attachToNetwork(Network $network, string $ip = null, array $alia
675675
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/attach_to_network'), [
676676
'json' => $payload,
677677
]);
678-
if (! HetznerAPIClient::hasError($response)) {
678+
if (!HetznerAPIClient::hasError($response)) {
679679
return APIResponse::create([
680-
'action' => Action::parse(json_decode((string) $response->getBody())->action),
680+
'action' => Action::parse(json_decode((string)$response->getBody())->action),
681681
], $response->getHeaders());
682682
}
683683

@@ -698,9 +698,9 @@ public function detachFromNetwork(Network $network)
698698
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/detach_from_network'), [
699699
'json' => $payload,
700700
]);
701-
if (! HetznerAPIClient::hasError($response)) {
701+
if (!HetznerAPIClient::hasError($response)) {
702702
return APIResponse::create([
703-
'action' => Action::parse(json_decode((string) $response->getBody())->action),
703+
'action' => Action::parse(json_decode((string)$response->getBody())->action),
704704
], $response->getHeaders());
705705
}
706706

@@ -722,9 +722,9 @@ public function changeAliasIPs(Network $network, array $aliasIps)
722722
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/change_alias_ips'), [
723723
'json' => $payload,
724724
]);
725-
if (! HetznerAPIClient::hasError($response)) {
725+
if (!HetznerAPIClient::hasError($response)) {
726726
return APIResponse::create([
727-
'action' => Action::parse(json_decode((string) $response->getBody())->action),
727+
'action' => Action::parse(json_decode((string)$response->getBody())->action),
728728
], $response->getHeaders());
729729
}
730730

0 commit comments

Comments
 (0)