feat: generate ssh key

This commit is contained in:
Andras Bacsai
2023-09-15 11:55:58 +02:00
parent 019670d5d1
commit cf28490acc
4 changed files with 35 additions and 7 deletions

View File

@@ -4,13 +4,15 @@ namespace App\Http\Livewire\PrivateKey;
use App\Models\PrivateKey;
use Livewire\Component;
use phpseclib3\Crypt\PublicKeyLoader;
class Create extends Component
{
public string|null $from = null;
public ?string $from = null;
public string $name;
public string|null $description = null;
public ?string $description = null;
public string $value;
public ?string $publicKey = null;
protected $rules = [
'name' => 'required|string',
'value' => 'required|string',
@@ -20,6 +22,23 @@ class Create extends Component
'value' => 'private Key',
];
public function generateNewKey()
{
$this->name = generate_random_name();
$this->description = 'Created by Coolify';
['private' => $this->value, 'public' => $this->publicKey] = generateSSHKey();
}
public function updated($updateProperty)
{
if ($updateProperty === 'value') {
try {
$this->publicKey = PublicKeyLoader::load($this->$updateProperty)->getPublicKey()->toString('OpenSSH',['comment' => '']);
} catch (\Throwable $e) {
$this->publicKey = "Invalid private key";
}
}
$this->validateOnly($updateProperty);
}
public function createPrivateKey()
{
$this->validate();

View File

@@ -24,6 +24,7 @@ class Textarea extends Component
public bool $disabled = false,
public bool $readonly = false,
public string|null $helper = null,
public bool $realtimeValidation = false,
public string $defaultClass = "textarea bg-coolgray-200 rounded text-white scrollbar disabled:bg-coolgray-200/50 disabled:border-none placeholder:text-coolgray-500 read-only:text-neutral-500 read-only:bg-coolgray-200/50"
) {
//