1, 'token' => 'ptla_1234567890abcdef', 'panel_url' => 'https://panel.example.com', 'allow_insecure' => false, ]; /** * Create node deployment token. */ #[Endpoint('Create node deploy token', 'Creates or reuses an application API key that can deploy the specified node.')] #[ScribeResponse(self::DEPLOY_TOKEN_EXAMPLE, description: 'Deploy token returned.')] public function __invoke(DeployTokenRequest $request, CreatesApiKeys $keyCreator, Encrypter $encrypter, Node $node): JsonResponse { $permissions = []; foreach (AdminAcl::getResourceList() as $resource) { $permissions[AdminAcl::COLUMN_IDENTIFIER.$resource] = $resource === AdminAcl::RESOURCE_NODES ? AdminAcl::READ | AdminAcl::WRITE : AdminAcl::NONE; } $key = ApiKey::query() ->where('user_id', $request->user()->id) ->where('key_type', ApiKey::TYPE_APPLICATION) ->where($permissions) ->first(); if (! $key) { $key = $keyCreator->create(ApiKey::TYPE_APPLICATION, [ 'user_id' => $request->user()->id, 'memo' => 'Automatically generated node deployment key.', 'allowed_ips' => [], ], $permissions); } Activity::event('admin:node.deploy-token') ->subject($node) ->property('name', $node->name) ->log(); return new JsonResponse([ 'node' => $node->id, 'token' => $key->identifier.JsonValueGuard::string($encrypter->decrypt($key->token)), 'panel_url' => config('app.url'), 'allow_insecure' => config('app.debug'), ]); } }