mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-19 17:34:45 +02:00

* Convert route options to fluent methods Laravel 8 adopts the tuple syntax for controller actions. Since the old options array is incompatible with this syntax, Shift converted them to use modern, fluent methods. * Slim `lang` files * Shift core files * Validate via object directly within Controllers * Use `Gate` facade for controller authorization * Dispatch jobs directly * Remove base controller inheritance * Default config files In an effort to make upgrading the constantly changing config files easier, Shift defaulted them and merged your true customizations - where ENV variables may not be used. * Set new `ENV` variables * Add new Laravel `composer run dev` script * Add `storage/app/private` folder * Bump Composer dependencies * Convert `$casts` property to method * Adopt Laravel type hints * Shift cleanup * Apply suggestions from code review Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> * Add old key as backup * Update composer * Remove extra line * Update this --------- Co-authored-by: Shift <shift@laravelshift.com> Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
74 lines
2.1 KiB
PHP
74 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\Client;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
use App\Facades\Activity;
|
|
use App\Http\Requests\Api\Client\ClientApiRequest;
|
|
use App\Transformers\Api\Client\UserSSHKeyTransformer;
|
|
use App\Http\Requests\Api\Client\Account\StoreSSHKeyRequest;
|
|
|
|
class SSHKeyController extends ClientApiController
|
|
{
|
|
/**
|
|
* List ssh keys
|
|
*
|
|
* Returns all 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();
|
|
}
|
|
|
|
/**
|
|
* Create ssh keys
|
|
*
|
|
* 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();
|
|
}
|
|
|
|
/**
|
|
* Delete ssh keys
|
|
*
|
|
* Deletes an SSH key from the user's account.
|
|
*/
|
|
public function delete(ClientApiRequest $request): JsonResponse
|
|
{
|
|
$request->validate(['fingerprint' => ['required', 'string']]);
|
|
|
|
$key = $request->user()->sshKeys()
|
|
->where('fingerprint', $request->input('fingerprint'))
|
|
->first();
|
|
|
|
if (!is_null($key)) {
|
|
$key->delete();
|
|
|
|
Activity::event('user:ssh-key.delete')
|
|
->subject($key)
|
|
->property('fingerprint', $key->fingerprint)
|
|
->log();
|
|
}
|
|
|
|
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
|
}
|
|
}
|