From 9e2686f8ff3f849682cb4317798035138e70d85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20K=C3=A4mmerling?= Date: Wed, 25 Nov 2020 14:30:13 +0100 Subject: [PATCH 1/2] Improve Server Object Typing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Kämmerling --- CHANGELOG.md | 4 + src/Models/Certificates/Certificate.php | 2 +- src/Models/Servers/Server.php | 135 ++++++++++-------- src/Models/Servers/ServerPrivateNet.php | 41 ++++++ src/Models/Servers/ServerPublicNet.php | 47 ++++++ src/Models/Servers/ServerPublicNetIPv4.php | 48 +++++++ src/Models/Servers/ServerPublicNetIPv6.php | 52 +++++++ .../Servers/ServerPublicNetIPv6DnsPtr.php | 36 +++++ 8 files changed, 303 insertions(+), 62 deletions(-) create mode 100644 src/Models/Servers/ServerPrivateNet.php create mode 100644 src/Models/Servers/ServerPublicNet.php create mode 100644 src/Models/Servers/ServerPublicNetIPv4.php create mode 100644 src/Models/Servers/ServerPublicNetIPv6.php create mode 100644 src/Models/Servers/ServerPublicNetIPv6DnsPtr.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 80c6ae0..37145ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## unreleased +* Feature: Add Certificate Support +* Improvements: Improve typing and structure of Server response + ## 2.2.1 (22.07.2020) * Make package requirements less strict * Bugfix: getByName functions had a wrong return type and failed when a resource was not found by name [#50](https://github.com/LKDevelopment/hetzner-cloud-php-sdk/issues/50) diff --git a/src/Models/Certificates/Certificate.php b/src/Models/Certificates/Certificate.php index 88def2c..9703334 100644 --- a/src/Models/Certificates/Certificate.php +++ b/src/Models/Certificates/Certificate.php @@ -130,7 +130,7 @@ public function delete(): bool */ public static function parse($input) { - return new self($input->id, $input->name, $input->certificate, $input->created, $input->not_valid_before, $input->not_valid_after, $input->domain_names, $input->fingerprint, $input->used_by, $input->labels); + return new self($input->id, $input->name, $input->certificate, $input->created, $input->not_valid_before, $input->not_valid_after, $input->domain_names, $input->fingerprint, $input->used_by, get_object_vars($input->labels)); } /** diff --git a/src/Models/Servers/Server.php b/src/Models/Servers/Server.php index 1f867c8..1956e99 100644 --- a/src/Models/Servers/Server.php +++ b/src/Models/Servers/Server.php @@ -44,12 +44,12 @@ class Server extends Model implements Resource public $created; /** - * @var array + * @var ServerPublicNet */ public $publicNet; /** - * @var array + * @var ServerPrivateNet[] */ public $privateNet; /** @@ -103,7 +103,7 @@ class Server extends Model implements Resource public $includedTraffic; /** - * @var array|\LKDev\HetznerCloud\Models\Protection + * @var \LKDev\HetznerCloud\Models\Protection */ public $protection; @@ -140,13 +140,13 @@ public function setAdditionalData($data) { $this->name = $data->name; $this->status = $data->status ?: null; - $this->publicNet = $data->public_net ?: null; - $this->privateNet = property_exists($data, 'private_net') ? $data->private_net : []; - $this->serverType = $data->server_type ?: ServerType::parse($data->server_type); - $this->datacenter = $data->datacenter ?: Datacenter::parse($data->datacenter); + $this->publicNet = property_exists($data, 'public_net') ? ServerPublicNet::parse($data->public_net) : null; + $this->privateNet = property_exists($data, 'private_net') ? $this->parsePrivateNet($data->private_net) : []; + $this->serverType = property_exists($data, 'server_type') ? ServerType::parse($data->server_type) : null; + $this->datacenter = property_exists($data, 'datacenter') ? Datacenter::parse($data->datacenter) : null; $this->created = $data->created; - $this->image = $data->image ?: Image::parse($data->image); - $this->iso = $data->iso ?: ISO::parse($data->iso); + $this->image = property_exists($data, 'image') ? Image::parse($data->image) : null; + $this->iso = property_exists($data, 'iso') ? ISO::parse($data->iso) : null; $this->rescueEnabled = $data->rescue_enabled ?: null; $this->locked = $data->locked ?: null; $this->backupWindow = $data->backup_window ?: null; @@ -154,13 +154,26 @@ public function setAdditionalData($data) $this->ingoingTraffic = $data->ingoing_traffic ?: null; $this->includedTraffic = $data->included_traffic ?: null; $this->volumes = property_exists($data, 'volumes') ? $data->volumes : []; - $this->protection = $data->protection ?: Protection::parse($data->protection); - $this->labels = $data->labels; + $this->labels = get_object_vars($data->labels); $this->primaryDiskSize = $data->primary_disk_size ?: null; return $this; } + /** + * @param \stdClass[] $privateNets + * @return ServerPrivateNet[] + */ + protected function parsePrivateNet(array $privateNets) + { + $parsed = []; + foreach ($privateNets as $privateNet) { + $parsed[] = new ServerPrivateNet($privateNet->network, $privateNet->ip, $privateNet->alias_ips, $privateNet->mac_address); + } + return $parsed; + + } + /** * Reload the data of the server. * @@ -193,9 +206,9 @@ public function reload() public function powerOn(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/poweron')); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string) $response->getBody())->action), + 'action' => Action::parse(json_decode((string)$response->getBody())->action), ], $response->getHeaders()); } @@ -212,9 +225,9 @@ public function powerOn(): ?APIResponse public function softReboot(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/reboot')); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string) $response->getBody())->action), + 'action' => Action::parse(json_decode((string)$response->getBody())->action), ], $response->getHeaders()); } @@ -231,9 +244,9 @@ public function softReboot(): ?APIResponse public function reset(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/reset')); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string) $response->getBody())->action), + 'action' => Action::parse(json_decode((string)$response->getBody())->action), ], $response->getHeaders()); } @@ -250,9 +263,9 @@ public function reset(): ?APIResponse public function shutdown(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/shutdown')); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string) $response->getBody())->action), + 'action' => Action::parse(json_decode((string)$response->getBody())->action), ], $response->getHeaders()); } @@ -269,9 +282,9 @@ public function shutdown(): ?APIResponse public function powerOff(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/poweroff')); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string) $response->getBody())->action), + 'action' => Action::parse(json_decode((string)$response->getBody())->action), ], $response->getHeaders()); } @@ -288,8 +301,8 @@ public function powerOff(): ?APIResponse public function resetRootPassword(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/reset_password')); - if (! HetznerAPIClient::hasError($response)) { - $payload = json_decode((string) $response->getBody()); + if (!HetznerAPIClient::hasError($response)) { + $payload = json_decode((string)$response->getBody()); return APIResponse::create([ 'action' => Action::parse($payload->action), @@ -317,8 +330,8 @@ public function enableRescue($type = 'linux64', $ssh_keys = []): ?APIResponse 'ssh_keys' => $ssh_keys, ], ]); - if (! HetznerAPIClient::hasError($response)) { - $payload = json_decode((string) $response->getBody()); + if (!HetznerAPIClient::hasError($response)) { + $payload = json_decode((string)$response->getBody()); return APIResponse::create([ 'action' => Action::parse($payload->action), @@ -339,9 +352,9 @@ public function enableRescue($type = 'linux64', $ssh_keys = []): ?APIResponse public function disableRescue(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/disable_rescue')); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string) $response->getBody())->action), + 'action' => Action::parse(json_decode((string)$response->getBody())->action), ], $response->getHeaders()); } @@ -364,14 +377,14 @@ public function createImage(string $description = '', string $type = 'snapshot', 'description' => $description, 'type' => $type, ]; - if (! empty($labels)) { + if (!empty($labels)) { $payload['labels'] = $labels; } $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/create_image'), [ 'json' => $payload, ]); - if (! HetznerAPIClient::hasError($response)) { - $payload = json_decode((string) $response->getBody()); + if (!HetznerAPIClient::hasError($response)) { + $payload = json_decode((string)$response->getBody()); return APIResponse::create([ 'action' => Action::parse($payload->action), @@ -397,8 +410,8 @@ public function rebuildFromImage(Image $image): ?APIResponse 'image' => $image->id ?: $image->name, ], ]); - if (! HetznerAPIClient::hasError($response)) { - $payload = json_decode((string) $response->getBody()); + if (!HetznerAPIClient::hasError($response)) { + $payload = json_decode((string)$response->getBody()); return APIResponse::create(array_merge([ 'action' => Action::parse($payload->action), @@ -425,9 +438,9 @@ public function changeType(ServerType $serverType, bool $upgradeDisk = false): ? 'upgrade_disk' => $upgradeDisk, ], ]); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string) $response->getBody())->action), + 'action' => Action::parse(json_decode((string)$response->getBody())->action), ], $response->getHeaders()); } @@ -444,9 +457,9 @@ public function changeType(ServerType $serverType, bool $upgradeDisk = false): ? public function enableBackups(string $backupWindow = null): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/enable_backup')); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string) $response->getBody())->action), + 'action' => Action::parse(json_decode((string)$response->getBody())->action), ], $response->getHeaders()); } @@ -463,9 +476,9 @@ public function enableBackups(string $backupWindow = null): ?APIResponse public function disableBackups(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/disable_backup')); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string) $response->getBody())->action), + 'action' => Action::parse(json_decode((string)$response->getBody())->action), ], $response->getHeaders()); } @@ -487,9 +500,9 @@ public function attachISO(ISO $iso): ?APIResponse 'iso' => $iso->name ?: $iso->id, ], ]); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string) $response->getBody())->action), + 'action' => Action::parse(json_decode((string)$response->getBody())->action), ], $response->getHeaders()); } @@ -506,9 +519,9 @@ public function attachISO(ISO $iso): ?APIResponse public function detachISO(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/detach_iso')); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string) $response->getBody())->action), + 'action' => Action::parse(json_decode((string)$response->getBody())->action), ], $response->getHeaders()); } @@ -532,9 +545,9 @@ public function changeReverseDNS(string $ip, string $dnsPtr): ?APIResponse 'dns_ptr' => $dnsPtr, ], ]); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string) $response->getBody())->action), + 'action' => Action::parse(json_decode((string)$response->getBody())->action), ], $response->getHeaders()); } @@ -554,10 +567,10 @@ public function changeReverseDNS(string $ip, string $dnsPtr): ?APIResponse */ public function metrics(string $type, string $start, string $end, int $step = null) { - $response = $this->httpClient->get($this->replaceServerIdInUri('servers/{id}/metrics?').http_build_query(compact('type', 'start', 'end', 'step'))); - if (! HetznerAPIClient::hasError($response)) { + $response = $this->httpClient->get($this->replaceServerIdInUri('servers/{id}/metrics?') . http_build_query(compact('type', 'start', 'end', 'step'))); + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'metrics' => json_decode((string) $response->getBody())->metrics, + 'metrics' => json_decode((string)$response->getBody())->metrics, ], $response->getHeaders()); } @@ -574,9 +587,9 @@ public function metrics(string $type, string $start, string $end, int $step = nu public function delete(): ?APIResponse { $response = $this->httpClient->delete($this->replaceServerIdInUri('servers/{id}')); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string) $response->getBody())->action), + 'action' => Action::parse(json_decode((string)$response->getBody())->action), ], $response->getHeaders()); } @@ -596,9 +609,9 @@ public function update(array $data) $response = $this->httpClient->put($this->replaceServerIdInUri('servers/{id}'), [ 'json' => $data, ]); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'server' => self::parse(json_decode((string) $response->getBody())->server), + 'server' => self::parse(json_decode((string)$response->getBody())->server), ], $response->getHeaders()); } @@ -615,8 +628,8 @@ public function update(array $data) public function requestConsole(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/request_console')); - if (! HetznerAPIClient::hasError($response)) { - $payload = json_decode((string) $response->getBody()); + if (!HetznerAPIClient::hasError($response)) { + $payload = json_decode((string)$response->getBody()); return APIResponse::create([ 'action' => Action::parse($payload->action), @@ -645,9 +658,9 @@ public function changeProtection(bool $delete = true, bool $rebuild = true): ?AP 'rebuild' => $rebuild, ], ]); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string) $response->getBody())->action), + 'action' => Action::parse(json_decode((string)$response->getBody())->action), ], $response->getHeaders()); } @@ -675,9 +688,9 @@ public function attachToNetwork(Network $network, string $ip = null, array $alia $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/attach_to_network'), [ 'json' => $payload, ]); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string) $response->getBody())->action), + 'action' => Action::parse(json_decode((string)$response->getBody())->action), ], $response->getHeaders()); } @@ -698,9 +711,9 @@ public function detachFromNetwork(Network $network) $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/detach_from_network'), [ 'json' => $payload, ]); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string) $response->getBody())->action), + 'action' => Action::parse(json_decode((string)$response->getBody())->action), ], $response->getHeaders()); } @@ -722,9 +735,9 @@ public function changeAliasIPs(Network $network, array $aliasIps) $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/change_alias_ips'), [ 'json' => $payload, ]); - if (! HetznerAPIClient::hasError($response)) { + if (!HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string) $response->getBody())->action), + 'action' => Action::parse(json_decode((string)$response->getBody())->action), ], $response->getHeaders()); } diff --git a/src/Models/Servers/ServerPrivateNet.php b/src/Models/Servers/ServerPrivateNet.php new file mode 100644 index 0000000..a7ed0b0 --- /dev/null +++ b/src/Models/Servers/ServerPrivateNet.php @@ -0,0 +1,41 @@ +network = $network; + $this->ip = $ip; + $this->aliasIps = $aliasIps; + $this->macAddress = $macAddress; + } +} diff --git a/src/Models/Servers/ServerPublicNet.php b/src/Models/Servers/ServerPublicNet.php new file mode 100644 index 0000000..959c83a --- /dev/null +++ b/src/Models/Servers/ServerPublicNet.php @@ -0,0 +1,47 @@ +ipv4 = $ipv4; + $this->ipv6 = $ipv6; + $this->floatingIps = $floatingIps; + } + + /** + * @param \stdClass $data + * @return ServerPublicNet + */ + public static function parse(\stdClass $data) + { + return new ServerPublicNet(ServerPublicNetIPv4::parse($data->ipv4), ServerPublicNetIPv6::parse($data->ipv6), $data->floating_ips); + } +} diff --git a/src/Models/Servers/ServerPublicNetIPv4.php b/src/Models/Servers/ServerPublicNetIPv4.php new file mode 100644 index 0000000..b2f3431 --- /dev/null +++ b/src/Models/Servers/ServerPublicNetIPv4.php @@ -0,0 +1,48 @@ +ip = $ip; + $this->blocked = $blocked; + $this->dnsPtr = $dnsPtr; + } + + /** + * @param \stdClass $data + * @return ServerPublicNetIPv4 + */ + public static function parse(\stdClass $data) + { + return new self($data->ip, $data->blocked, $data->dns_ptr); + } + +} diff --git a/src/Models/Servers/ServerPublicNetIPv6.php b/src/Models/Servers/ServerPublicNetIPv6.php new file mode 100644 index 0000000..48aaf22 --- /dev/null +++ b/src/Models/Servers/ServerPublicNetIPv6.php @@ -0,0 +1,52 @@ +ip = $ip; + $this->blocked = $blocked; + $this->dnsPtr = $dnsPtr; + } + + /** + * @param \stdClass $data + * @return ServerPublicNetIPv6 + */ + public static function parse(\stdClass $data) + { + $dnsPtrs = []; + foreach ($data->dns_ptr as $dnsPtr) { + $dnsPtrs[] = new ServerPublicNetIPv6DnsPtr($dnsPtr->ip, $dnsPtr->dns_ptr); + } + return new self($data->ip, $data->blocked, $dnsPtrs); + } + +} diff --git a/src/Models/Servers/ServerPublicNetIPv6DnsPtr.php b/src/Models/Servers/ServerPublicNetIPv6DnsPtr.php new file mode 100644 index 0000000..af2ac7d --- /dev/null +++ b/src/Models/Servers/ServerPublicNetIPv6DnsPtr.php @@ -0,0 +1,36 @@ +ip = $ip; + $this->dnsPtr = $dnsPtr; + } + + + +} From 3b442db968cb951c7ac118ae866a80cccb0edf9b Mon Sep 17 00:00:00 2001 From: LKaemmerling Date: Wed, 25 Nov 2020 13:46:16 +0000 Subject: [PATCH 2/2] Apply fixes from StyleCI --- src/Models/Servers/Server.php | 102 +++++++++--------- src/Models/Servers/ServerPrivateNet.php | 3 - src/Models/Servers/ServerPublicNet.php | 5 +- src/Models/Servers/ServerPublicNetIPv4.php | 6 +- src/Models/Servers/ServerPublicNetIPv6.php | 7 +- .../Servers/ServerPublicNetIPv6DnsPtr.php | 8 +- 6 files changed, 56 insertions(+), 75 deletions(-) diff --git a/src/Models/Servers/Server.php b/src/Models/Servers/Server.php index 1956e99..2bb840b 100644 --- a/src/Models/Servers/Server.php +++ b/src/Models/Servers/Server.php @@ -170,8 +170,8 @@ protected function parsePrivateNet(array $privateNets) foreach ($privateNets as $privateNet) { $parsed[] = new ServerPrivateNet($privateNet->network, $privateNet->ip, $privateNet->alias_ips, $privateNet->mac_address); } - return $parsed; + return $parsed; } /** @@ -206,9 +206,9 @@ public function reload() public function powerOn(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/poweron')); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string)$response->getBody())->action), + 'action' => Action::parse(json_decode((string) $response->getBody())->action), ], $response->getHeaders()); } @@ -225,9 +225,9 @@ public function powerOn(): ?APIResponse public function softReboot(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/reboot')); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string)$response->getBody())->action), + 'action' => Action::parse(json_decode((string) $response->getBody())->action), ], $response->getHeaders()); } @@ -244,9 +244,9 @@ public function softReboot(): ?APIResponse public function reset(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/reset')); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string)$response->getBody())->action), + 'action' => Action::parse(json_decode((string) $response->getBody())->action), ], $response->getHeaders()); } @@ -263,9 +263,9 @@ public function reset(): ?APIResponse public function shutdown(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/shutdown')); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string)$response->getBody())->action), + 'action' => Action::parse(json_decode((string) $response->getBody())->action), ], $response->getHeaders()); } @@ -282,9 +282,9 @@ public function shutdown(): ?APIResponse public function powerOff(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/poweroff')); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string)$response->getBody())->action), + 'action' => Action::parse(json_decode((string) $response->getBody())->action), ], $response->getHeaders()); } @@ -301,8 +301,8 @@ public function powerOff(): ?APIResponse public function resetRootPassword(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/reset_password')); - if (!HetznerAPIClient::hasError($response)) { - $payload = json_decode((string)$response->getBody()); + if (! HetznerAPIClient::hasError($response)) { + $payload = json_decode((string) $response->getBody()); return APIResponse::create([ 'action' => Action::parse($payload->action), @@ -330,8 +330,8 @@ public function enableRescue($type = 'linux64', $ssh_keys = []): ?APIResponse 'ssh_keys' => $ssh_keys, ], ]); - if (!HetznerAPIClient::hasError($response)) { - $payload = json_decode((string)$response->getBody()); + if (! HetznerAPIClient::hasError($response)) { + $payload = json_decode((string) $response->getBody()); return APIResponse::create([ 'action' => Action::parse($payload->action), @@ -352,9 +352,9 @@ public function enableRescue($type = 'linux64', $ssh_keys = []): ?APIResponse public function disableRescue(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/disable_rescue')); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string)$response->getBody())->action), + 'action' => Action::parse(json_decode((string) $response->getBody())->action), ], $response->getHeaders()); } @@ -377,14 +377,14 @@ public function createImage(string $description = '', string $type = 'snapshot', 'description' => $description, 'type' => $type, ]; - if (!empty($labels)) { + if (! empty($labels)) { $payload['labels'] = $labels; } $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/create_image'), [ 'json' => $payload, ]); - if (!HetznerAPIClient::hasError($response)) { - $payload = json_decode((string)$response->getBody()); + if (! HetznerAPIClient::hasError($response)) { + $payload = json_decode((string) $response->getBody()); return APIResponse::create([ 'action' => Action::parse($payload->action), @@ -410,8 +410,8 @@ public function rebuildFromImage(Image $image): ?APIResponse 'image' => $image->id ?: $image->name, ], ]); - if (!HetznerAPIClient::hasError($response)) { - $payload = json_decode((string)$response->getBody()); + if (! HetznerAPIClient::hasError($response)) { + $payload = json_decode((string) $response->getBody()); return APIResponse::create(array_merge([ 'action' => Action::parse($payload->action), @@ -438,9 +438,9 @@ public function changeType(ServerType $serverType, bool $upgradeDisk = false): ? 'upgrade_disk' => $upgradeDisk, ], ]); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string)$response->getBody())->action), + 'action' => Action::parse(json_decode((string) $response->getBody())->action), ], $response->getHeaders()); } @@ -457,9 +457,9 @@ public function changeType(ServerType $serverType, bool $upgradeDisk = false): ? public function enableBackups(string $backupWindow = null): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/enable_backup')); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string)$response->getBody())->action), + 'action' => Action::parse(json_decode((string) $response->getBody())->action), ], $response->getHeaders()); } @@ -476,9 +476,9 @@ public function enableBackups(string $backupWindow = null): ?APIResponse public function disableBackups(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/disable_backup')); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string)$response->getBody())->action), + 'action' => Action::parse(json_decode((string) $response->getBody())->action), ], $response->getHeaders()); } @@ -500,9 +500,9 @@ public function attachISO(ISO $iso): ?APIResponse 'iso' => $iso->name ?: $iso->id, ], ]); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string)$response->getBody())->action), + 'action' => Action::parse(json_decode((string) $response->getBody())->action), ], $response->getHeaders()); } @@ -519,9 +519,9 @@ public function attachISO(ISO $iso): ?APIResponse public function detachISO(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/detach_iso')); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string)$response->getBody())->action), + 'action' => Action::parse(json_decode((string) $response->getBody())->action), ], $response->getHeaders()); } @@ -545,9 +545,9 @@ public function changeReverseDNS(string $ip, string $dnsPtr): ?APIResponse 'dns_ptr' => $dnsPtr, ], ]); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string)$response->getBody())->action), + 'action' => Action::parse(json_decode((string) $response->getBody())->action), ], $response->getHeaders()); } @@ -567,10 +567,10 @@ public function changeReverseDNS(string $ip, string $dnsPtr): ?APIResponse */ public function metrics(string $type, string $start, string $end, int $step = null) { - $response = $this->httpClient->get($this->replaceServerIdInUri('servers/{id}/metrics?') . http_build_query(compact('type', 'start', 'end', 'step'))); - if (!HetznerAPIClient::hasError($response)) { + $response = $this->httpClient->get($this->replaceServerIdInUri('servers/{id}/metrics?').http_build_query(compact('type', 'start', 'end', 'step'))); + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'metrics' => json_decode((string)$response->getBody())->metrics, + 'metrics' => json_decode((string) $response->getBody())->metrics, ], $response->getHeaders()); } @@ -587,9 +587,9 @@ public function metrics(string $type, string $start, string $end, int $step = nu public function delete(): ?APIResponse { $response = $this->httpClient->delete($this->replaceServerIdInUri('servers/{id}')); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string)$response->getBody())->action), + 'action' => Action::parse(json_decode((string) $response->getBody())->action), ], $response->getHeaders()); } @@ -609,9 +609,9 @@ public function update(array $data) $response = $this->httpClient->put($this->replaceServerIdInUri('servers/{id}'), [ 'json' => $data, ]); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'server' => self::parse(json_decode((string)$response->getBody())->server), + 'server' => self::parse(json_decode((string) $response->getBody())->server), ], $response->getHeaders()); } @@ -628,8 +628,8 @@ public function update(array $data) public function requestConsole(): ?APIResponse { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/request_console')); - if (!HetznerAPIClient::hasError($response)) { - $payload = json_decode((string)$response->getBody()); + if (! HetznerAPIClient::hasError($response)) { + $payload = json_decode((string) $response->getBody()); return APIResponse::create([ 'action' => Action::parse($payload->action), @@ -658,9 +658,9 @@ public function changeProtection(bool $delete = true, bool $rebuild = true): ?AP 'rebuild' => $rebuild, ], ]); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string)$response->getBody())->action), + 'action' => Action::parse(json_decode((string) $response->getBody())->action), ], $response->getHeaders()); } @@ -688,9 +688,9 @@ public function attachToNetwork(Network $network, string $ip = null, array $alia $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/attach_to_network'), [ 'json' => $payload, ]); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string)$response->getBody())->action), + 'action' => Action::parse(json_decode((string) $response->getBody())->action), ], $response->getHeaders()); } @@ -711,9 +711,9 @@ public function detachFromNetwork(Network $network) $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/detach_from_network'), [ 'json' => $payload, ]); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string)$response->getBody())->action), + 'action' => Action::parse(json_decode((string) $response->getBody())->action), ], $response->getHeaders()); } @@ -735,9 +735,9 @@ public function changeAliasIPs(Network $network, array $aliasIps) $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/change_alias_ips'), [ 'json' => $payload, ]); - if (!HetznerAPIClient::hasError($response)) { + if (! HetznerAPIClient::hasError($response)) { return APIResponse::create([ - 'action' => Action::parse(json_decode((string)$response->getBody())->action), + 'action' => Action::parse(json_decode((string) $response->getBody())->action), ], $response->getHeaders()); } diff --git a/src/Models/Servers/ServerPrivateNet.php b/src/Models/Servers/ServerPrivateNet.php index a7ed0b0..d419dc3 100644 --- a/src/Models/Servers/ServerPrivateNet.php +++ b/src/Models/Servers/ServerPrivateNet.php @@ -1,10 +1,7 @@ ip, $data->blocked, $data->dns_ptr); } - } diff --git a/src/Models/Servers/ServerPublicNetIPv6.php b/src/Models/Servers/ServerPublicNetIPv6.php index 48aaf22..4f58cc1 100644 --- a/src/Models/Servers/ServerPublicNetIPv6.php +++ b/src/Models/Servers/ServerPublicNetIPv6.php @@ -1,12 +1,9 @@ dns_ptr as $dnsPtr) { $dnsPtrs[] = new ServerPublicNetIPv6DnsPtr($dnsPtr->ip, $dnsPtr->dns_ptr); } + return new self($data->ip, $data->blocked, $dnsPtrs); } - } diff --git a/src/Models/Servers/ServerPublicNetIPv6DnsPtr.php b/src/Models/Servers/ServerPublicNetIPv6DnsPtr.php index af2ac7d..92124de 100644 --- a/src/Models/Servers/ServerPublicNetIPv6DnsPtr.php +++ b/src/Models/Servers/ServerPublicNetIPv6DnsPtr.php @@ -1,12 +1,9 @@ ip = $ip; $this->dnsPtr = $dnsPtr; } - - - }