2024-09-19 17:27:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Livewire\Security\PrivateKey;
|
|
|
|
|
|
|
|
|
|
use App\Models\PrivateKey;
|
2025-08-26 08:27:31 +00:00
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
2024-09-23 17:51:31 +00:00
|
|
|
use Livewire\Component;
|
2024-09-19 17:27:25 +00:00
|
|
|
|
|
|
|
|
class Index extends Component
|
|
|
|
|
{
|
2025-08-26 08:27:31 +00:00
|
|
|
use AuthorizesRequests;
|
|
|
|
|
|
2026-07-08 10:58:27 +00:00
|
|
|
public function generatePrivateKey(string $type)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$this->authorize('create', PrivateKey::class);
|
|
|
|
|
|
|
|
|
|
if (! in_array($type, ['ed25519', 'rsa'], true)) {
|
|
|
|
|
$this->dispatch('error', 'Invalid private key type.');
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$keyData = PrivateKey::generateNewKeyPair($type);
|
|
|
|
|
$privateKey = PrivateKey::createAndStore([
|
|
|
|
|
'name' => $keyData['name'],
|
|
|
|
|
'description' => $keyData['description'],
|
|
|
|
|
'private_key' => $keyData['private_key'],
|
|
|
|
|
'team_id' => currentTeam()->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return redirectRoute($this, 'security.private-key.show', ['private_key_uuid' => $privateKey->uuid]);
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return handleError($e, $this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-19 17:27:25 +00:00
|
|
|
public function render()
|
|
|
|
|
{
|
2025-10-17 21:04:24 +00:00
|
|
|
$privateKeys = PrivateKey::ownedByCurrentTeam(['name', 'uuid', 'is_git_related', 'description', 'team_id'])->get();
|
2024-09-19 17:27:25 +00:00
|
|
|
|
|
|
|
|
return view('livewire.security.private-key.index', [
|
|
|
|
|
'privateKeys' => $privateKeys,
|
|
|
|
|
])->layout('components.layout');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function cleanupUnusedKeys()
|
|
|
|
|
{
|
2026-02-25 13:20:29 +00:00
|
|
|
try {
|
|
|
|
|
$this->authorize('create', PrivateKey::class);
|
|
|
|
|
PrivateKey::cleanupUnusedKeys();
|
|
|
|
|
$this->dispatch('success', 'Unused keys have been cleaned up.');
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return handleError($e, $this);
|
|
|
|
|
}
|
2024-09-19 17:27:25 +00:00
|
|
|
}
|
|
|
|
|
}
|