2023-05-03 10:38:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\PrivateKey;
|
|
|
|
|
|
|
|
use App\Models\PrivateKey;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Create extends Component
|
|
|
|
{
|
2023-07-26 11:23:47 +00:00
|
|
|
public string|null $from = null;
|
2023-05-12 13:39:07 +00:00
|
|
|
public string $name;
|
2023-05-15 12:54:03 +00:00
|
|
|
public string|null $description = null;
|
2023-05-12 13:39:07 +00:00
|
|
|
public string $value;
|
2023-06-07 14:47:10 +00:00
|
|
|
protected $rules = [
|
|
|
|
'name' => 'required|string',
|
|
|
|
'value' => 'required|string',
|
|
|
|
];
|
|
|
|
protected $validationAttributes = [
|
2023-06-16 10:35:40 +00:00
|
|
|
'name' => 'name',
|
|
|
|
'value' => 'private Key',
|
2023-06-07 14:47:10 +00:00
|
|
|
];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-03 10:38:57 +00:00
|
|
|
public function createPrivateKey()
|
|
|
|
{
|
2023-06-07 14:47:10 +00:00
|
|
|
$this->validate();
|
|
|
|
try {
|
|
|
|
$this->value = trim($this->value);
|
|
|
|
if (!str_ends_with($this->value, "\n")) {
|
|
|
|
$this->value .= "\n";
|
|
|
|
}
|
|
|
|
$private_key = PrivateKey::create([
|
|
|
|
'name' => $this->name,
|
|
|
|
'description' => $this->description,
|
|
|
|
'private_key' => $this->value,
|
2023-08-22 15:44:49 +00:00
|
|
|
'team_id' => currentTeam()->id
|
2023-06-07 14:47:10 +00:00
|
|
|
]);
|
|
|
|
if ($this->from === 'server') {
|
|
|
|
return redirect()->route('server.create');
|
|
|
|
}
|
|
|
|
return redirect()->route('private-key.show', ['private_key_uuid' => $private_key->uuid]);
|
|
|
|
} catch (\Exception $e) {
|
2023-06-09 13:55:21 +00:00
|
|
|
return general_error_handler(err: $e, that: $this);
|
2023-05-16 09:39:18 +00:00
|
|
|
}
|
2023-05-03 10:38:57 +00:00
|
|
|
}
|
|
|
|
}
|