mirror of
https://github.com/anikeen-com/id.git
synced 2026-03-15 06:36:14 +00:00
refactored code
Signed-off-by: Maurice Preuß (envoyr) <hello@envoyr.com>
This commit is contained in:
@@ -3,16 +3,14 @@
|
||||
|
||||
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 Anikeen\Id\Resources\SshKeys;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
|
||||
trait ManagesSshKeys
|
||||
{
|
||||
use Get, Post, Delete;
|
||||
use Get;
|
||||
|
||||
/**
|
||||
* Get currently authed user with Bearer Token.
|
||||
@@ -20,35 +18,9 @@ trait ManagesSshKeys
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function sshKeysByUserId(string $sskKeyId): Result
|
||||
public function sshKeysByUserId(string $sskKeyId): SshKeys
|
||||
{
|
||||
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));
|
||||
return (new SshKeys($this->get(sprintf('v1/users/%s/ssh-keys/json', $sskKeyId))))
|
||||
->setParent($this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user