mirror of
https://github.com/anikeen-com/id.git
synced 2026-03-14 22:26:14 +00:00
refactored code
Signed-off-by: Maurice Preuß (envoyr) <hello@envoyr.com>
This commit is contained in:
54
src/Id/Concerns/ManagesSshKeys.php
Normal file
54
src/Id/Concerns/ManagesSshKeys.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Anikeen\Id\Concerns;
|
||||
|
||||
use Anikeen\Id\ApiOperations\Delete;
|
||||
use Anikeen\Id\ApiOperations\Get;
|
||||
use Anikeen\Id\ApiOperations\Post;
|
||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||
use Anikeen\Id\Result;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
|
||||
trait ManagesSshKeys
|
||||
{
|
||||
use Get, Post, Delete;
|
||||
|
||||
/**
|
||||
* Get currently authed user with Bearer Token.
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function sshKeysByUserId(string $sskKeyId): Result
|
||||
{
|
||||
return $this->get(sprintf('v1/users/%s/ssh-keys/json', $sskKeyId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates ssh key for the currently authed user.
|
||||
*
|
||||
* @param string $publicKey The public key to be added
|
||||
* @param string|null $name The name of the key (optional)
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function createSshKey(string $publicKey, string $name = null): Result
|
||||
{
|
||||
return $this->post('v1/ssh-keys', [
|
||||
'public_key' => $publicKey,
|
||||
'name' => $name,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given ssh key for the currently authed user.
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function deleteSshKey(int $sshKeyId): Result
|
||||
{
|
||||
return $this->delete(sprintf('v1/ssh-keys/%s', $sshKeyId));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user