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.
94 lines
3.2 KiB
PHTML
94 lines
3.2 KiB
PHTML
|
1 month ago
|
<?php
|
||
|
|
|
||
|
|
namespace App\Controllers;
|
||
|
|
|
||
|
|
use App\Services\Cloud\CloudAccess;
|
||
|
|
use App\Services\Cloud\CloudInput;
|
||
|
|
use App\Services\Cloud\CloudVpcService;
|
||
|
|
|
||
|
|
/** Tenant VPC control-plane API; the public network_change API is separate. */
|
||
|
|
final class CloudVpcController
|
||
|
|
{
|
||
|
|
private function actor($request): array
|
||
|
|
{
|
||
|
|
return $request->getAttribute('cloud_actor') ?? CloudAccess::actor();
|
||
|
|
}
|
||
|
|
|
||
|
|
private function json($response, array $value, int $status = 200)
|
||
|
|
{
|
||
|
|
return $response->withJson($value, $status)
|
||
|
|
->withHeader('Cache-Control', 'no-store');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function index($request, $response)
|
||
|
|
{
|
||
|
|
return $this->json($response, ['vpcs' => CloudVpcService::listing($this->actor($request))]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function show($request, $response, $args)
|
||
|
|
{
|
||
|
|
return $this->json($response, CloudVpcService::show(
|
||
|
|
(string) $args['vpc_key'], $this->actor($request)
|
||
|
|
));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function create($request, $response)
|
||
|
|
{
|
||
|
|
$value = CloudVpcService::create($this->actor($request), CloudInput::object($request));
|
||
|
|
return $this->json($response, $value, 202);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function addSubnet($request, $response, $args)
|
||
|
|
{
|
||
|
|
$value = CloudVpcService::addSubnet((string) $args['vpc_key'],
|
||
|
|
$this->actor($request), CloudInput::object($request));
|
||
|
|
return $this->json($response, $value, 202);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function removeSubnet($request, $response, $args)
|
||
|
|
{
|
||
|
|
$value = CloudVpcService::removeSubnet((string) $args['vpc_key'],
|
||
|
|
(string) $args['subnet_key'], $this->actor($request), CloudInput::object($request));
|
||
|
|
return $this->json($response, $value, 202);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function attachMember($request, $response, $args)
|
||
|
|
{
|
||
|
|
$value = CloudVpcService::attachMember((string) $args['vpc_key'],
|
||
|
|
$this->actor($request), CloudInput::object($request));
|
||
|
|
return $this->json($response, $value, 202);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function detachMember($request, $response, $args)
|
||
|
|
{
|
||
|
|
$value = CloudVpcService::detachMember((string) $args['vpc_key'],
|
||
|
|
(string) $args['member_key'], $this->actor($request), CloudInput::object($request));
|
||
|
|
return $this->json($response, $value, 202);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function routes($request, $response, $args)
|
||
|
|
{
|
||
|
|
return $this->json($response, CloudVpcService::replaceRoutes(
|
||
|
|
(string) $args['vpc_key'], $this->actor($request), CloudInput::object($request)
|
||
|
|
), 202);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function acl($request, $response, $args)
|
||
|
|
{
|
||
|
|
return $this->json($response, CloudVpcService::replaceAcl(
|
||
|
|
(string) $args['vpc_key'], $this->actor($request), CloudInput::object($request)
|
||
|
|
), 202);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function reconcile($request, $response, $args)
|
||
|
|
{
|
||
|
|
// Reconcile is a separate, explicit operation. It never creates or
|
||
|
|
// claims a general VM-job/public-network row. It is also the
|
||
|
|
// explicit retry path for a control-plane operation paused until the
|
||
|
|
// later private data-plane readback phase.
|
||
|
|
return $this->json($response, CloudVpcService::reconcile(
|
||
|
|
(string) $args['vpc_key'], $this->actor($request), true
|
||
|
|
), 200);
|
||
|
|
}
|
||
|
|
}
|