getAttribute('cloud_actor') ?? CloudAccess::actor(); if (!($actor['is_admin'] ?? false)) { throw new CloudError('需要管理员权限', 403); } if ($write) { CloudAccess::manage($actor); } return $actor; } public function index($request, $response, $args) { $method = strtoupper((string) $request->getMethod()); $write = $method !== 'GET'; $actor = $this->actor($request, $write); $hostId = (int) ($args['id'] ?? 0); $service = new CloudAdminHostNetworkService(); if (!$write) { $result = $service->read($hostId, $actor); $status = 200; } else { $body = CloudInput::object($request); CloudInput::only($body, [ 'network_attachment_id', 'address_family', 'name', 'cidr', 'gateway', 'gateway_on_link', 'dns_servers', 'reserved_ips', 'allocation_start', 'allocation_end', 'max_allocations', 'guest_prefix_length', 'state', 'request_key', ]); $result = $service->create($hostId, $actor, $body); $status = 201; } return $response->withJson($result, $status) ->withHeader('Cache-Control', 'private, no-store'); } public function update($request, $response, $args) { $actor = $this->actor($request, true); $body = CloudInput::object($request); CloudInput::only($body, [ 'network_attachment_id', 'address_family', 'name', 'cidr', 'gateway', 'gateway_on_link', 'dns_servers', 'reserved_ips', 'allocation_start', 'allocation_end', 'max_allocations', 'guest_prefix_length', 'state', 'expected_revision', ]); $result = (new CloudAdminHostNetworkService())->update( (int) ($args['id'] ?? 0), (string) ($args['pool_key'] ?? ''), $actor, $body ); return $response->withJson($result) ->withHeader('Cache-Control', 'private, no-store'); } }