File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,30 @@ class SSHKeys extends Model
2121 */
2222 public $ sshKeys ;
2323
24+ /**
25+ * Creates a new SSH Key with the given name and public_key.
26+ *
27+ * @see https://docs.hetzner.cloud/#resources-ssh-keys-post
28+ * @param string $name
29+ * @param string $publicKey
30+ * @return \LKDev\HetznerCloud\Models\SSHKeys\SSHKey
31+ * @throws \LKDev\HetznerCloud\APIException
32+ */
33+ public function create (
34+ string $ name ,
35+ string $ publicKey
36+ ): SSHKey {
37+ $ response = $ this ->httpClient ->post ('ssh_keys ' , [
38+ 'json ' => [
39+ 'name ' => $ name ,
40+ 'public_key ' => $ publicKey ,
41+ ],
42+ ]);
43+ if (! HetznerAPIClient::hasError ($ response )) {
44+ return SSHKey::parse (json_decode ((string ) $ response ->getBody ())->ssh_key );
45+ }
46+ }
47+
2448 /**
2549 * Returns all ssh key objects.
2650 *
@@ -69,4 +93,4 @@ public static function parse( $input)
6993 {
7094 return (new self ())->setAdditionalData ($ input );
7195 }
72- }
96+ }
You can’t perform that action at this time.
0 commit comments