mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-22 19:22:19 +00:00
41 lines
794 B
PHP
41 lines
794 B
PHP
<?php
|
|
|
|
namespace App\Actions\SshKey;
|
|
|
|
use App\Models\SshKey;
|
|
use App\Models\User;
|
|
use App\ValidationRules\SshKeyRule;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class CreateSshKey
|
|
{
|
|
/**
|
|
* @throws ValidationException
|
|
*/
|
|
public function create(User $user, array $input): SshKey
|
|
{
|
|
$key = new SshKey([
|
|
'user_id' => $user->id,
|
|
'name' => $input['name'],
|
|
'public_key' => $input['public_key'],
|
|
]);
|
|
$key->save();
|
|
|
|
return $key;
|
|
}
|
|
|
|
/**
|
|
* @throws ValidationException
|
|
*/
|
|
public static function rules(): array
|
|
{
|
|
return [
|
|
'name' => 'required',
|
|
'public_key' => [
|
|
'required',
|
|
new SshKeyRule,
|
|
],
|
|
];
|
|
}
|
|
}
|