forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSSHKeyController.php
More file actions
61 lines (51 loc) · 1.91 KB
/
SSHKeyController.php
File metadata and controls
61 lines (51 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace Pterodactyl\Http\Controllers\Api\Client;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Facades\Activity;
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
use Pterodactyl\Transformers\Api\Client\UserSSHKeyTransformer;
use Pterodactyl\Http\Requests\Api\Client\Account\StoreSSHKeyRequest;
class SSHKeyController extends ClientApiController
{
/**
* Returns all of the SSH keys that have been configured for the logged in
* user account.
*/
public function index(ClientApiRequest $request): array
{
return $this->fractal->collection($request->user()->sshKeys)
->transformWith($this->getTransformer(UserSSHKeyTransformer::class))
->toArray();
}
/**
* Stores a new SSH key for the authenticated user's account.
*/
public function store(StoreSSHKeyRequest $request): array
{
$model = $request->user()->sshKeys()->create([
'name' => $request->input('name'),
'public_key' => $request->getPublicKey(),
'fingerprint' => $request->getKeyFingerprint(),
]);
Activity::event('user:ssh-key.create')
->subject($model)
->property('fingerprint', $request->getKeyFingerprint())
->log();
return $this->fractal->item($model)
->transformWith($this->getTransformer(UserSSHKeyTransformer::class))
->toArray();
}
/**
* Deletes an SSH key from the user's account.
*/
public function delete(ClientApiRequest $request, string $identifier): JsonResponse
{
$key = $request->user()->sshKeys()->where('fingerprint', $identifier)->firstOrFail();
$key->delete();
Activity::event('user:ssh-key.delete')
->subject($key)
->property('fingerprint', $key->fingerprint)
->log();
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
}
}