You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/app/Services/Cloud/CloudPortableRestoreRequest...

54 lines
1.4 KiB
PHP

<?php
namespace App\Services\Cloud;
/** Immutable, secret-free guest inputs required by RestoreBackupRequest. */
final class CloudPortableRestoreRequestInput
{
private readonly array $value;
private readonly string $json;
private readonly string $sha256;
private function __construct(array $value)
{
$this->value = $value;
$this->json = json_encode(
$value,
JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES
| JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_LINE_TERMINATORS
);
$this->sha256 = hash('sha256', $this->json);
}
public static function fromSpec(array $spec): self
{
$fix = $spec['debian_12_network_fix'] ?? null;
if (!is_bool($fix)) {
throw new CloudError('备份缺少可信的 Debian 网络修正快照', 409);
}
$policy = CloudPlatformTestNetworkPolicy::assertSnapshot(
$spec['platform_network_policy_snapshot'] ?? null
);
return new self([
'contract' => 1,
'debian_12_network_fix' => $fix,
'platform_network_policy_snapshot' => $policy,
]);
}
public function toArray(): array
{
return $this->value;
}
public function json(): string
{
return $this->json;
}
public function sha256(): string
{
return $this->sha256;
}
}