From bc7ff3ec3f61eaa2f953aba65fe1cc69f3fcfaa8 Mon Sep 17 00:00:00 2001 From: Kristers Andersons <35456491+Indianos@users.noreply.github.com> Date: Wed, 30 Jul 2025 11:43:32 +0300 Subject: [PATCH 1/2] Add created field in SSHKey model --- src/Models/SSHKeys/SSHKey.php | 45 +++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/src/Models/SSHKeys/SSHKey.php b/src/Models/SSHKeys/SSHKey.php index 298295e..643a297 100644 --- a/src/Models/SSHKeys/SSHKey.php +++ b/src/Models/SSHKeys/SSHKey.php @@ -4,7 +4,7 @@ * Created by PhpStorm. * User: lukaskammerling * Date: 28.01.18 - * Time: 21:00. + * Time: 21:00 */ namespace LKDev\HetznerCloud\Models\SSHKeys; @@ -40,23 +40,34 @@ class SSHKey extends Model implements Resource */ public $labels; + /** + * @var \DateTimeInterface + */ + public $created; + /** * SSHKey constructor. * * @param int $id * @param string $name - * @param string $fingerprint - * @param string $publicKey - * @param array $labels */ - public function __construct(int $id, string $name, string $fingerprint, string $publicKey, array $labels = []) + public function __construct(int $id, string $name) { $this->id = $id; $this->name = $name; - $this->fingerprint = $fingerprint; - $this->public_key = $publicKey; - $this->labels = $labels; + parent::__construct(); + + // @deprecated code + if (func_num_args() > 2) { + $this->fingerprint = func_get_arg(2); + if (func_get_arg(3)) { + $this->public_key = func_get_arg(3); + } + if (func_get_arg(4)) { + $this->labels = func_get_arg(4); + } + } } /** @@ -69,14 +80,14 @@ public function __construct(int $id, string $name, string $fingerprint, string $ * * @throws \LKDev\HetznerCloud\APIException */ - public function update(array $data): ?self + public function update(array $data): ?static { $response = $this->httpClient->put('ssh_keys/'.$this->id, [ 'json' => $data, ]); if (! HetznerAPIClient::hasError($response)) { - return self::parse(json_decode((string) $response->getBody())->ssh_key); + return static::parse(json_decode((string) $response->getBody())->ssh_key); } return null; @@ -94,7 +105,7 @@ public function update(array $data): ?self * * @deprecated 1.2.0 */ - public function changeName(string $newName): ?self + public function changeName(string $newName): ?static { return $this->update(['name' => $newName]); } @@ -124,7 +135,7 @@ public function delete(): bool */ public static function parse($input) { - return new self($input->id, $input->name, $input->fingerprint, $input->public_key, get_object_vars($input->labels)); + return (new static($input->id, $input->name))->setAdditionalData($input); } /** @@ -138,4 +149,14 @@ public function reload() { return HetznerAPIClient::$instance->sshKeys()->get($this->id); } + + public function setAdditionalData($data): static + { + $this->fingerprint = $data->fingerprint; + $this->public_key = $data->public_key; + $this->labels = get_object_vars($data->labels); + $this->created = new \DateTime($data->created); + + return $this; + } } From be9a0cf24829c1355a4942f3341dc36d9ee80f01 Mon Sep 17 00:00:00 2001 From: Kristers Andersons <35456491+Indianos@users.noreply.github.com> Date: Wed, 30 Jul 2025 11:46:46 +0300 Subject: [PATCH 2/2] Update SSHKey.php --- src/Models/SSHKeys/SSHKey.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/SSHKeys/SSHKey.php b/src/Models/SSHKeys/SSHKey.php index 643a297..3828f34 100644 --- a/src/Models/SSHKeys/SSHKey.php +++ b/src/Models/SSHKeys/SSHKey.php @@ -4,7 +4,7 @@ * Created by PhpStorm. * User: lukaskammerling * Date: 28.01.18 - * Time: 21:00 + * Time: 21:00. */ namespace LKDev\HetznerCloud\Models\SSHKeys;