Skip to content

Commit

Permalink
Merge pull request #3 from jmjmjm/master
Browse files Browse the repository at this point in the history
Added create method to SSHKeys
  • Loading branch information
Lukas Kämmerling authored Feb 15, 2018
2 parents fd58477 + 9af076b commit 3e86cdb
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/Models/SSHKeys/SSHKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,30 @@ class SSHKeys extends Model
*/
public $sshKeys;

/**
* Creates a new SSH Key with the given name and public_key.
*
* @see https://docs.hetzner.cloud/#resources-ssh-keys-post
* @param string $name
* @param string $publicKey
* @return \LKDev\HetznerCloud\Models\SSHKeys\SSHKey
* @throws \LKDev\HetznerCloud\APIException
*/
public function create(
string $name,
string $publicKey
): SSHKey {
$response = $this->httpClient->post('ssh_keys', [
'json' => [
'name' => $name,
'public_key' => $publicKey,
],
]);
if (! HetznerAPIClient::hasError($response)) {
return SSHKey::parse(json_decode((string) $response->getBody())->ssh_key);
}
}

/**
* Returns all ssh key objects.
*
Expand Down Expand Up @@ -69,4 +93,4 @@ public static function parse( $input)
{
return (new self())->setAdditionalData($input);
}
}
}

0 comments on commit 3e86cdb

Please sign in to comment.