47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\OpenStack;
|
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* Range l'adresse de la console série dans Redis sous un jeton aléatoire,
|
|
* pour 5 minutes (étape 9). Le navigateur ne reçoit que ce jeton, jamais
|
|
* l'URL ni le jeton Nova sous-jacent. Format lu par proxy-console/main.go :
|
|
* ne pas changer les noms de champs sans mettre à jour les deux côtés.
|
|
*/
|
|
class JetonConsole
|
|
{
|
|
private const DUREE_MINUTES = 5;
|
|
|
|
public function __construct(private readonly NovaClient $nova) {}
|
|
|
|
public function pourEcriture(string $instanceId): string
|
|
{
|
|
return $this->creer($instanceId, 'ecriture');
|
|
}
|
|
|
|
public function pourLecture(string $instanceId): string
|
|
{
|
|
return $this->creer($instanceId, 'lecture');
|
|
}
|
|
|
|
private function creer(string $instanceId, string $role): string
|
|
{
|
|
$jeton = Str::random(40);
|
|
$url = $this->nova->consoleSerielle($instanceId);
|
|
|
|
Redis::setex(
|
|
"console:{$jeton}",
|
|
self::DUREE_MINUTES * 60,
|
|
json_encode([
|
|
'url' => $url,
|
|
'instance_id' => $instanceId,
|
|
'role' => $role,
|
|
]),
|
|
);
|
|
|
|
return $jeton;
|
|
}
|
|
}
|