Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| SSHKeyService | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
| getSSHKey | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSSHKeys | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| updateSSHKey | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| deleteSSHKey | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createSSHKey | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Vultr\VultrPhp\Services\SSHKeys; |
| 6 | |
| 7 | use Vultr\VultrPhp\Services\VultrService; |
| 8 | use Vultr\VultrPhp\Util\ListOptions; |
| 9 | |
| 10 | /** |
| 11 | * SSH key service handler, for all ssh-keys endpoints. |
| 12 | * |
| 13 | * @see https://www.vultr.com/api/#tag/ssh |
| 14 | */ |
| 15 | class SSHKeyService extends VultrService |
| 16 | { |
| 17 | /** |
| 18 | * @param $ssh_key_id - string - UUID of the ssh key |
| 19 | * @throws SSHKeyException |
| 20 | * @throws VultrException |
| 21 | * @return SSHKey |
| 22 | */ |
| 23 | public function getSSHKey(string $ssh_key_id) : SSHKey |
| 24 | { |
| 25 | return $this->getObject('ssh-keys/'.$ssh_key_id, new SSHKey()); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @param $options - ListOptions|null - Interact via reference. |
| 30 | * @throws SSHKeyException |
| 31 | * @return SSHKey[] |
| 32 | */ |
| 33 | public function getSSHKeys(?ListOptions &$options = null) : array |
| 34 | { |
| 35 | return $this->getListObjects('ssh-keys', new SSHKey(), $options); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @param $ssh_key - SSHKey |
| 40 | * @throws SSHKeyException |
| 41 | * @return void |
| 42 | */ |
| 43 | public function updateSSHKey(SSHKey $ssh_key) : void |
| 44 | { |
| 45 | $this->patchObject('ssh-keys/'.$ssh_key->getId(), $ssh_key); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @param $ssh_key_id - string - UUID of the ssh key |
| 50 | * @throws SSHKeyException |
| 51 | * @return void |
| 52 | */ |
| 53 | public function deleteSSHKey(string $ssh_key_id) : void |
| 54 | { |
| 55 | $this->deleteObject('ssh-keys/'.$ssh_key_id, new SSHKey()); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @param $name - string - what are you going to call the key. |
| 60 | * @param $ssh_key - string - full ssh key |
| 61 | * @throws SSHKeyException |
| 62 | * @return void |
| 63 | */ |
| 64 | public function createSSHKey(string $name, string $ssh_key) : SSHKey |
| 65 | { |
| 66 | return $this->createObject('ssh-keys', new SSHKey(), [ |
| 67 | 'name' => $name, |
| 68 | 'ssh_key' => $ssh_key |
| 69 | ]); |
| 70 | } |
| 71 | } |
| 72 |