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.
56 lines
1.8 KiB
PHP
56 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Services\Cloud\CloudAccess;
|
|
use App\Services\Cloud\CloudError;
|
|
use App\Services\Cloud\CloudHostVpcTransportService;
|
|
use App\Services\Cloud\CloudInput;
|
|
|
|
/** Thin administrator boundary for compute-node VPC transport intent. */
|
|
final class CloudAdminHostVpcController
|
|
{
|
|
private function actor($request, bool $manage): array
|
|
{
|
|
$actor = $request->getAttribute('cloud_actor') ?? CloudAccess::actor();
|
|
if (!($actor['is_admin'] ?? false)) {
|
|
throw new CloudError('需要管理员权限', 403);
|
|
}
|
|
if ($manage) {
|
|
CloudAccess::manage($actor);
|
|
}
|
|
return $actor;
|
|
}
|
|
|
|
public function configuration($request, $response, $args)
|
|
{
|
|
$write = strtoupper((string) $request->getMethod()) !== 'GET';
|
|
$this->actor($request, $write);
|
|
$hostId = (int) ($args['id'] ?? 0);
|
|
if (!$write) {
|
|
$result = CloudHostVpcTransportService::read($hostId);
|
|
} else {
|
|
$body = CloudInput::object($request);
|
|
$result = CloudHostVpcTransportService::save($hostId, $body);
|
|
}
|
|
return $response->withJson($result)
|
|
->withHeader('Cache-Control', 'private, no-store');
|
|
}
|
|
|
|
public function discover($request, $response, $args)
|
|
{
|
|
$actor = $this->actor($request, true);
|
|
return $response->withJson(CloudHostVpcTransportService::discover(
|
|
(int) ($args['id'] ?? 0), $actor
|
|
))->withHeader('Cache-Control', 'private, no-store');
|
|
}
|
|
|
|
public function test($request, $response, $args)
|
|
{
|
|
$actor = $this->actor($request, true);
|
|
return $response->withJson(CloudHostVpcTransportService::test(
|
|
(int) ($args['id'] ?? 0), $actor
|
|
))->withHeader('Cache-Control', 'private, no-store');
|
|
}
|
|
}
|