refactored code

Signed-off-by: Maurice Preuß (envoyr) <hello@envoyr.com>
This commit is contained in:
2025-04-30 03:45:10 +02:00
parent 85702fcb2c
commit 4b23f6ddbb
42 changed files with 1139 additions and 594 deletions

View File

@@ -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);
}
}