Path: blob/1.0-develop/app/Http/Controllers/Api/Client/SSHKeyController.php
10279 views
<?php12namespace Pterodactyl\Http\Controllers\Api\Client;34use Illuminate\Http\JsonResponse;5use Pterodactyl\Facades\Activity;6use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;7use Pterodactyl\Transformers\Api\Client\UserSSHKeyTransformer;8use Pterodactyl\Http\Requests\Api\Client\Account\StoreSSHKeyRequest;910class SSHKeyController extends ClientApiController11{12/**13* Returns all the SSH keys that have been configured for the logged-in14* user account.15*/16public function index(ClientApiRequest $request): array17{18return $this->fractal->collection($request->user()->sshKeys)19->transformWith($this->getTransformer(UserSSHKeyTransformer::class))20->toArray();21}2223/**24* Stores a new SSH key for the authenticated user's account.25*/26public function store(StoreSSHKeyRequest $request): array27{28$model = $request->user()->sshKeys()->create([29'name' => $request->input('name'),30'public_key' => $request->getPublicKey(),31'fingerprint' => $request->getKeyFingerprint(),32]);3334Activity::event('user:ssh-key.create')35->subject($model)36->property('fingerprint', $request->getKeyFingerprint())37->log();3839return $this->fractal->item($model)40->transformWith($this->getTransformer(UserSSHKeyTransformer::class))41->toArray();42}4344/**45* Deletes an SSH key from the user's account.46*/47public function delete(ClientApiRequest $request): JsonResponse48{49$this->validate($request, ['fingerprint' => ['required', 'string']]);5051$key = $request->user()->sshKeys()52->where('fingerprint', $request->input('fingerprint'))53->first();5455if (!is_null($key)) {56$key->delete();5758Activity::event('user:ssh-key.delete')59->subject($key)60->property('fingerprint', $key->fingerprint)61->log();62}6364return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);65}66}676869