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.
67 lines
2.0 KiB
PHP
67 lines
2.0 KiB
PHP
<?php
|
|
namespace App\Controllers;
|
|
|
|
use App\Services\Cloud\CloudAccess;
|
|
use App\Services\Cloud\CloudError;
|
|
use App\Services\Cloud\CloudInput;
|
|
use App\Services\Cloud\CloudPlatformTestNetworkPolicy;
|
|
|
|
/** Database-only administrator API for future-instance test restrictions. */
|
|
final class CloudAdminPlatformPolicyController
|
|
{
|
|
private function actor($request, bool $write = false): array
|
|
{
|
|
$actor = $request->getAttribute('cloud_actor')
|
|
?? CloudAccess::actor(false);
|
|
if (!($actor['is_admin'] ?? false)) {
|
|
throw new CloudError('需要管理员权限', 403);
|
|
}
|
|
if ($write) {
|
|
CloudAccess::manage($actor);
|
|
}
|
|
return $actor;
|
|
}
|
|
|
|
private function json($response, array $payload, int $status = 200)
|
|
{
|
|
return $response->withJson(['test_policy' => $payload], $status)
|
|
->withHeader('Cache-Control', 'private, no-store');
|
|
}
|
|
|
|
public function index($request, $response)
|
|
{
|
|
$this->actor($request);
|
|
return $this->json($response,
|
|
CloudPlatformTestNetworkPolicy::page());
|
|
}
|
|
|
|
public function create($request, $response)
|
|
{
|
|
$actor = $this->actor($request, true);
|
|
return $this->json($response,
|
|
CloudPlatformTestNetworkPolicy::create(
|
|
CloudInput::object($request), $actor
|
|
), 201);
|
|
}
|
|
|
|
public function update($request, $response, $args)
|
|
{
|
|
$actor = $this->actor($request, true);
|
|
return $this->json($response,
|
|
CloudPlatformTestNetworkPolicy::update(
|
|
(string) ($args['rule_key'] ?? ''),
|
|
CloudInput::object($request), $actor
|
|
));
|
|
}
|
|
|
|
public function delete($request, $response, $args)
|
|
{
|
|
$actor = $this->actor($request, true);
|
|
return $this->json($response,
|
|
CloudPlatformTestNetworkPolicy::delete(
|
|
(string) ($args['rule_key'] ?? ''),
|
|
CloudInput::object($request), $actor
|
|
));
|
|
}
|
|
}
|