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) { $write = strtoupper((string) $request->getMethod()) !== 'GET'; $actor = $this->actor($request, $write); $service = new CloudHostNetworkAttachmentService(); $hostId = (int) ($args['id'] ?? 0); if (!$write) { $result = $service->read($hostId, $actor); $status = 200; } else { $body = CloudInput::object($request); CloudInput::only($body, [ 'name', 'line_id', 'network_selector', 'state', 'priority', '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, [ 'name', 'line_id', 'network_selector', 'state', 'priority', 'expected_revision', ]); $result = (new CloudHostNetworkAttachmentService())->update( (int) ($args['id'] ?? 0), (string) ($args['attachment_key'] ?? ''), $actor, $body ); return $response->withJson($result) ->withHeader('Cache-Control', 'private, no-store'); } public function discover($request, $response, $args) { $actor = $this->actor($request, true); CloudInput::only(CloudInput::object($request), []); $result = (new CloudHostNetworkAttachmentService())->discover( (int) ($args['id'] ?? 0), $actor ); return $response->withJson($result) ->withHeader('Cache-Control', 'private, no-store'); } public function test($request, $response, $args) { $actor = $this->actor($request, true); $body = CloudInput::object($request); CloudInput::only($body, ['expected_revision']); $result = (new CloudHostNetworkAttachmentService())->test( (int) ($args['id'] ?? 0), (string) ($args['attachment_key'] ?? ''), $actor, $body ); return $response->withJson($result) ->withHeader('Cache-Control', 'private, no-store'); } }