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.
35 lines
1.0 KiB
PHP
35 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Cloud;
|
|
|
|
use App\Models\CloudInstance;
|
|
|
|
/** One canonical eligibility contract for tenant, administrator and jobs. */
|
|
final class CloudInstanceSettingsGuard
|
|
{
|
|
public static function assertSupported(CloudInstance $instance): void
|
|
{
|
|
try {
|
|
$spec = json_decode(
|
|
(string) $instance->spec_json,
|
|
true,
|
|
64,
|
|
JSON_THROW_ON_ERROR
|
|
);
|
|
if (!is_array($spec) || array_is_list($spec)
|
|
|| ($spec['managed'] ?? false) !== true
|
|
|| ($spec['os_source'] ?? null) !== 'cloud_template') {
|
|
throw new \InvalidArgumentException();
|
|
}
|
|
CloudPublicNetworkSnapshot::fromArray(
|
|
$spec['public_network'] ?? null
|
|
);
|
|
} catch (\Throwable) {
|
|
throw new CloudError(
|
|
'当前虚拟机不是支持实例设置的面板云镜像实例',
|
|
409
|
|
);
|
|
}
|
|
}
|
|
}
|