43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Actions;
|
|
|
|
use App\Models\Host;
|
|
use App\Models\ProvisioningRun;
|
|
use App\Provisioning\Jobs\AdvanceRunJob;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
|
|
/**
|
|
* Registers a fresh host and kicks off its onboarding run. The one-time root
|
|
* password lives encrypted in the run context and is scrubbed after SSH trust
|
|
* is established.
|
|
*/
|
|
class StartHostOnboarding
|
|
{
|
|
/**
|
|
* @param array{name: string, datacenter: string, public_ip: string, root_password: string} $input
|
|
*/
|
|
public function run(array $input): Host
|
|
{
|
|
$host = Host::create([
|
|
'name' => $input['name'],
|
|
'datacenter' => $input['datacenter'],
|
|
'public_ip' => $input['public_ip'],
|
|
'status' => 'pending',
|
|
]);
|
|
|
|
$run = ProvisioningRun::create([
|
|
'subject_type' => Host::class,
|
|
'subject_id' => $host->id,
|
|
'pipeline' => 'host',
|
|
'status' => ProvisioningRun::STATUS_PENDING,
|
|
'current_step' => 0,
|
|
'context' => ['root_password' => Crypt::encryptString($input['root_password'])],
|
|
]);
|
|
|
|
AdvanceRunJob::dispatch($run->uuid);
|
|
|
|
return $host;
|
|
}
|
|
}
|