From 8cc37822cc004cee5fd0fade3b0bfc0516e653e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 11 Sep 2026 11:08:14 +0200 Subject: [PATCH 1/7] feat(organization): move project API key management under the organization API Project key endpoints now live in the Organization module at /v1/organization/projects/:projectId/keys (SDK namespace organization, methods createProjectKey, createEphemeralProjectKey, listProjectKeys, getProjectKey, updateProjectKey, deleteProjectKey). The previous paths /v1/project/keys and /v1/projects/:projectId/keys (plus /jwts) stay as aliases so the console, the PHP migration source and existing SDKs keep working; the alias without a path segment falls back to the request project through a closure default. Each action resolves the target project by ID, requires it to belong to the organization, and refuses project-bound keys that name a sibling project of the same organization. Also: onboarding tracks organization.createProjectKey and persists to the project named in the path when the request project is console; request filters V21/V22/V24 follow the renamed SDK methods; closure param defaults are no longer emitted into specs; the Organization e2e suite joins phpunit.xml and the CI matrix (its paths carried a double /v1 prefix and stale project-shape assertions, both fixed). Co-Authored-By: Claude Fable 5.1 --- .github/workflows/ci.yml | 1 + app/config/onboarding.php | 2 +- app/controllers/shared/api.php | 15 +- phpunit.xml | 1 + .../Http/Projects/Keys/Action.php | 36 +++ .../Http/Projects}/Keys/Create.php | 30 +- .../Http/Projects}/Keys/Delete.php | 32 ++- .../Http/Projects}/Keys/Ephemeral/Create.php | 35 ++- .../Http/Projects}/Keys/Get.php | 30 +- .../Http/Projects}/Keys/Update.php | 33 ++- .../Http/Projects}/Keys/XList.php | 31 +- .../Modules/Organization/Services/Http.php | 14 + .../Modules/Project/Services/Http.php | 14 - src/Appwrite/SDK/Specification/Format.php | 3 +- src/Appwrite/Utopia/Request/Filters/V21.php | 2 +- src/Appwrite/Utopia/Request/Filters/V22.php | 4 +- src/Appwrite/Utopia/Request/Filters/V24.php | 2 +- .../{Project => Organization}/KeysBase.php | 272 +++++++++++++++++- .../KeysConsoleClientTest.php | 2 +- .../KeysCustomServerTest.php | 2 +- .../KeysIntegrationTest.php | 4 +- .../Services/Organization/ProjectsBase.php | 87 +++--- tests/unit/SDK/Specification/FormatTest.php | 8 + 23 files changed, 508 insertions(+), 152 deletions(-) create mode 100644 src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Action.php rename src/Appwrite/Platform/Modules/{Project/Http/Project => Organization/Http/Projects}/Keys/Create.php (83%) rename src/Appwrite/Platform/Modules/{Project/Http/Project => Organization/Http/Projects}/Keys/Delete.php (73%) rename src/Appwrite/Platform/Modules/{Project/Http/Project => Organization/Http/Projects}/Keys/Ephemeral/Create.php (72%) rename src/Appwrite/Platform/Modules/{Project/Http/Project => Organization/Http/Projects}/Keys/Get.php (69%) rename src/Appwrite/Platform/Modules/{Project/Http/Project => Organization/Http/Projects}/Keys/Update.php (77%) rename src/Appwrite/Platform/Modules/{Project/Http/Project => Organization/Http/Projects}/Keys/XList.php (82%) rename tests/e2e/Services/{Project => Organization}/KeysBase.php (75%) rename tests/e2e/Services/{Project => Organization}/KeysConsoleClientTest.php (85%) rename tests/e2e/Services/{Project => Organization}/KeysCustomServerTest.php (85%) rename tests/e2e/Services/{Project => Organization}/KeysIntegrationTest.php (96%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca756e5710..f3c96096c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -221,6 +221,7 @@ jobs: { name: 'Notifications', runner: runner4, functional: true, processes: null }, { name: 'Migrations', runner: runner4, functional: true, processes: 1, documentsdb: true }, { name: 'Project', runner: runner4, functional: true, processes: null }, + { name: 'Organization', runner: runner4, functional: true, processes: null }, { name: 'Presences', runner: runner4, functional: true, processes: null }, ]; core.setOutput('services', JSON.stringify(services)); diff --git a/app/config/onboarding.php b/app/config/onboarding.php index 21a105b878..a27295acfe 100644 --- a/app/config/onboarding.php +++ b/app/config/onboarding.php @@ -13,7 +13,7 @@ return [ 'project.createWindowsPlatform' => true, 'project.createLinuxPlatform' => true, // Connect — API key - 'project.createKey' => true, + 'organization.createProjectKey' => true, // Auth 'users.create' => true, diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index c13e9a02af..22f3663ab2 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -1190,7 +1190,7 @@ Http::shutdown() * cannot suppress RequestCompleted or usage metrics on the same request. */ $statusCode = $response->getStatusCode(); - if ($statusCode < 200 || $statusCode >= 300 || $project->getId() === 'console') { + if ($statusCode < 200 || $statusCode >= 300) { return; } @@ -1228,6 +1228,19 @@ Http::shutdown() return; } + // Organization routes act on the project named in the path, not on the console project. + if ($project->getId() === 'console') { + $projectId = (string) ($route->getParamsValues()['projectId'] ?? ''); + if ($projectId === '') { + return; + } + + $project = $authorization->skip(fn () => $dbForPlatform->getDocument('projects', $projectId)); + if ($project->isEmpty()) { + return; + } + } + $byMethod = $project->getAttribute('onboarding', []); $status = \is_array($byMethod) ? ($byMethod[$method]['status'] ?? null) : null; if ($status === ONBOARDING_STATUS_COMPLETED || $status === ONBOARDING_STATUS_SKIPPED) { diff --git a/phpunit.xml b/phpunit.xml index 65c4e31d0c..575340538c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -39,6 +39,7 @@ ./tests/e2e/Services/Migrations ./tests/e2e/Services/Notifications ./tests/e2e/Services/Project + ./tests/e2e/Services/Organization ./tests/e2e/Services/Advisor ./tests/e2e/Services/Usage ./tests/e2e/Services/Functions/FunctionsBase.php diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Action.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Action.php new file mode 100644 index 0000000000..c009f7d8b9 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Action.php @@ -0,0 +1,36 @@ +getDocument('projects', $projectId); + + if ($project->isEmpty() || $project->getId() === 'console') { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } + + if ($project->getAttribute('teamInternalId') !== $team->getSequence()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } + + if ($apiKey !== null && !$apiKey->isProjectCheckDisabled() && $apiKey->getProjectId() !== '' && $apiKey->getProjectId() !== $project->getId()) { + throw new Exception(Exception::USER_UNAUTHORIZED); + } + + return $project; + } +} diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Create.php similarity index 83% rename from src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php rename to src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Create.php index 20062b5aaf..53f0717e68 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Create.php @@ -1,12 +1,10 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_POST) - ->setHttpPath('/v1/project/keys') + ->setHttpPath('/v1/organization/projects/:projectId/keys') + ->httpAlias('/v1/project/keys') ->httpAlias('/v1/projects/:projectId/keys') ->desc('Create project key') - ->groups(['api', 'project']) + ->groups(['api', 'organization']) ->label('scope', 'keys.write') ->label('event', 'keys.[keyId].create') ->label('audits.event', 'project.key.create') ->label('audits.resource', 'project.key/{response.$id}') ->label('sdk', new Method( - namespace: 'project', + namespace: 'organization', group: 'keys', - name: 'createKey', + name: 'createProjectKey', description: <<param('projectId', fn (Document $project) => $project->getId(), new UID(), 'Project unique ID.', true, ['project']) ->param('keyId', '', fn (Database $dbForPlatform) => new CustomId(false, $dbForPlatform->getAdapter()->getMaxUIDLength()), 'Key ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForPlatform']) ->param('name', null, new Text(128), 'Key name. Max length: 128 chars.') ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_SCOPES_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_SCOPES_SIZE . ' scopes are allowed.', optional: false, enum: new Enum(name: 'ProjectKeyScopes')) @@ -71,13 +72,14 @@ class Create extends Base ->inject('response') ->inject('queueForEvents') ->inject('dbForPlatform') - ->inject('project') + ->inject('team') ->inject('authorization') ->inject('apiKey') ->callback($this->action(...)); } public function action( + string $projectId, string $keyId, string $name, array $scopes, @@ -85,7 +87,7 @@ class Create extends Base Response $response, QueueEvent $queueForEvents, Database $dbForPlatform, - Document $project, + Document $team, Authorization $authorization, ?Key $apiKey, ) { @@ -94,6 +96,8 @@ class Create extends Base throw new Exception(Exception::KEY_CREATION_DENIED); } + $project = $this->getProject($projectId, $team, $dbForPlatform, $apiKey); + $keyId = ($keyId == 'unique()') ? ID::unique() : $keyId; $key = new Document([ diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Delete.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Delete.php similarity index 73% rename from src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Delete.php rename to src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Delete.php index c5da673e22..91b923e339 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Delete.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Delete.php @@ -1,10 +1,10 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_DELETE) - ->setHttpPath('/v1/project/keys/:keyId') + ->setHttpPath('/v1/organization/projects/:projectId/keys/:keyId') + ->httpAlias('/v1/project/keys/:keyId') ->httpAlias('/v1/projects/:projectId/keys/:keyId') ->desc('Delete project key') - ->groups(['api', 'project']) + ->groups(['api', 'organization']) ->label('scope', 'keys.write') ->label('event', 'keys.[keyId].delete') ->label('audits.event', 'project.key.delete') ->label('audits.resource', 'project.key/{request.keyId}') ->label('sdk', new Method( - namespace: 'project', + namespace: 'organization', group: 'keys', - name: 'deleteKey', + name: 'deleteProjectKey', description: <<param('projectId', fn (Document $project) => $project->getId(), new UID(), 'Project unique ID.', true, ['project']) ->param('keyId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Key ID.', false, ['dbForPlatform']) ->inject('response') ->inject('dbForPlatform') ->inject('queueForEvents') - ->inject('project') + ->inject('team') ->inject('authorization') + ->inject('apiKey') ->callback($this->action(...)); } public function action( + string $projectId, string $keyId, Response $response, Database $dbForPlatform, Event $queueForEvents, - Document $project, + Document $team, Authorization $authorization, + ?Key $apiKey, ) { + $project = $this->getProject($projectId, $team, $dbForPlatform, $apiKey); + $key = $authorization->skip(fn () => $dbForPlatform->getDocument('keys', $keyId)); if ($key->isEmpty() || $key->getAttribute('resourceType', '') !== 'projects' || $key->getAttribute('resourceInternalId', '') !== $project->getSequence()) { @@ -79,7 +85,7 @@ class Delete extends Base if (!$authorization->skip(fn () => $dbForPlatform->deleteDocument('keys', $key->getId()))) { throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove document from DB'); - }; + } $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Ephemeral/Create.php similarity index 72% rename from src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php rename to src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Ephemeral/Create.php index 7edd4ed4e9..1677883e26 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Ephemeral/Create.php @@ -1,19 +1,21 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_POST) - ->setHttpPath('/v1/project/keys/ephemeral') + ->setHttpPath('/v1/organization/projects/:projectId/keys/ephemeral') + ->httpAlias('/v1/project/keys/ephemeral') ->httpAlias('/v1/projects/:projectId/jwts') ->desc('Create ephemeral project key') - ->groups(['api', 'project']) + ->groups(['api', 'organization']) ->label('scope', 'keys.write') ->label('event', 'keys.[keyId].create') ->label('audits.event', 'project.key.create') ->label('audits.resource', 'project.key/{response.$id}') ->label('sdk', new Method( - namespace: 'project', + namespace: 'organization', group: 'keys', - name: 'createEphemeralKey', + name: 'createEphemeralProjectKey', description: <<param('projectId', fn (Document $project) => $project->getId(), new UID(), 'Project unique ID.', true, ['project']) ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_SCOPES_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_SCOPES_SIZE . ' scopes are allowed.', optional: false, enum: new Enum(name: 'ProjectKeyScopes')) ->param('duration', null, new Range(1, 3600), 'Time in seconds before ephemeral key expires. Maximum duration is 3600 seconds.', optional: false, example: 600) ->inject('response') ->inject('queueForEvents') - ->inject('project') + ->inject('dbForPlatform') + ->inject('team') + ->inject('apiKey') ->callback($this->action(...)); } public function action( + string $projectId, array $scopes, int $duration, Response $response, QueueEvent $queueForEvents, - Document $project, + Database $dbForPlatform, + Document $team, + ?Key $apiKey, ) { + $project = $this->getProject($projectId, $team, $dbForPlatform, $apiKey); + $keyId = ID::unique(); $jwt = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', $duration, 0); diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Get.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Get.php similarity index 69% rename from src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Get.php rename to src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Get.php index e43c669e4f..9eab435f94 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Get.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Get.php @@ -1,9 +1,9 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) - ->setHttpPath('/v1/project/keys/:keyId') + ->setHttpPath('/v1/organization/projects/:projectId/keys/:keyId') + ->httpAlias('/v1/project/keys/:keyId') ->httpAlias('/v1/projects/:projectId/keys/:keyId') ->desc('Get project key') - ->groups(['api', 'project']) + ->groups(['api', 'organization']) ->label('scope', 'keys.read') ->label('sdk', new Method( - namespace: 'project', + namespace: 'organization', group: 'keys', - name: 'getKey', + name: 'getProjectKey', description: <<param('projectId', fn (Document $project) => $project->getId(), new UID(), 'Project unique ID.', true, ['project']) ->param('keyId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Key ID.', false, ['dbForPlatform']) ->inject('response') ->inject('dbForPlatform') - ->inject('project') + ->inject('team') ->inject('authorization') + ->inject('apiKey') ->callback($this->action(...)); } public function action( + string $projectId, string $keyId, Response $response, Database $dbForPlatform, - Document $project, + Document $team, Authorization $authorization, + ?Key $apiKey, ) { + $project = $this->getProject($projectId, $team, $dbForPlatform, $apiKey); + $key = $authorization->skip(fn () => $dbForPlatform->getDocument('keys', $keyId)); if ($key->isEmpty() || $key->getAttribute('resourceType', '') !== 'projects' || $key->getAttribute('resourceInternalId', '') !== $project->getSequence()) { diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Update.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Update.php similarity index 77% rename from src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Update.php rename to src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Update.php index c7156fb66e..c45231c068 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Update.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Update.php @@ -1,11 +1,10 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_PUT) - ->setHttpPath('/v1/project/keys/:keyId') + $this + ->setHttpMethod(Action::HTTP_REQUEST_METHOD_PUT) + ->setHttpPath('/v1/organization/projects/:projectId/keys/:keyId') + ->httpAlias('/v1/project/keys/:keyId') ->httpAlias('/v1/projects/:projectId/keys/:keyId') ->desc('Update project key') - ->groups(['api', 'project']) + ->groups(['api', 'organization']) ->label('scope', 'keys.write') ->label('event', 'keys.[keyId].update') ->label('audits.event', 'project.key.update') ->label('audits.resource', 'project.key/{response.$id}') ->label('sdk', new Method( - namespace: 'project', + namespace: 'organization', group: 'keys', - name: 'updateKey', + name: 'updateProjectKey', description: <<param('projectId', fn (Document $project) => $project->getId(), new UID(), 'Project unique ID.', true, ['project']) ->param('keyId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Key ID.', false, ['dbForPlatform']) ->param('name', null, new Text(128), 'Key name. Max length: 128 chars.') ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_SCOPES_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_SCOPES_SIZE . ' scopes are allowed.', optional: false, enum: new Enum(name: 'ProjectKeyScopes')) @@ -66,12 +68,14 @@ class Update extends Base ->inject('response') ->inject('queueForEvents') ->inject('dbForPlatform') - ->inject('project') + ->inject('team') ->inject('authorization') + ->inject('apiKey') ->callback($this->action(...)); } public function action( + string $projectId, string $keyId, string $name, array $scopes, @@ -79,9 +83,12 @@ class Update extends Base Response $response, QueueEvent $queueForEvents, Database $dbForPlatform, - Document $project, + Document $team, Authorization $authorization, + ?Key $apiKey, ) { + $project = $this->getProject($projectId, $team, $dbForPlatform, $apiKey); + $key = $authorization->skip(fn () => $dbForPlatform->getDocument('keys', $keyId)); if ($key->isEmpty() || $key->getAttribute('resourceType', '') !== 'projects' || $key->getAttribute('resourceInternalId', '') !== $project->getSequence()) { diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/XList.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/XList.php similarity index 82% rename from src/Appwrite/Platform/Modules/Project/Http/Project/Keys/XList.php rename to src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/XList.php index d243e6f2c3..0dc599b024 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/XList.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/XList.php @@ -1,9 +1,9 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) - ->setHttpPath('/v1/project/keys') + ->setHttpPath('/v1/organization/projects/:projectId/keys') + ->httpAlias('/v1/project/keys') ->httpAlias('/v1/projects/:projectId/keys') ->desc('List project keys') - ->groups(['api', 'project']) + ->groups(['api', 'organization']) ->label('scope', 'keys.read') ->label('sdk', new Method( - namespace: 'project', + namespace: 'organization', group: 'keys', - name: 'listKeys', + name: 'listProjectKeys', description: <<param('projectId', fn (Document $project) => $project->getId(), new UID(), 'Project unique ID.', true, ['project']) ->param('queries', [], new Keys(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Keys::ALLOWED_ATTRIBUTES), true) ->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true) - ->inject('project') ->inject('response') ->inject('dbForPlatform') + ->inject('team') ->inject('authorization') + ->inject('apiKey') ->callback($this->action(...)); } @@ -66,13 +69,17 @@ class XList extends Base * @param array $queries */ public function action( + string $projectId, array $queries, bool $includeTotal, - Document $project, Response $response, Database $dbForPlatform, + Document $team, Authorization $authorization, + ?Key $apiKey, ) { + $project = $this->getProject($projectId, $team, $dbForPlatform, $apiKey); + try { $queries = Query::parseQueries($queries); } catch (QueryException $e) { diff --git a/src/Appwrite/Platform/Modules/Organization/Services/Http.php b/src/Appwrite/Platform/Modules/Organization/Services/Http.php index 49a8f7d832..ae2a0dd1c0 100644 --- a/src/Appwrite/Platform/Modules/Organization/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Organization/Services/Http.php @@ -6,6 +6,12 @@ use Appwrite\Platform\Modules\Organization\Http\Init as Init; use Appwrite\Platform\Modules\Organization\Http\Projects\Create as CreateProject; use Appwrite\Platform\Modules\Organization\Http\Projects\Delete as DeleteProject; use Appwrite\Platform\Modules\Organization\Http\Projects\Get as GetProject; +use Appwrite\Platform\Modules\Organization\Http\Projects\Keys\Create as CreateProjectKey; +use Appwrite\Platform\Modules\Organization\Http\Projects\Keys\Delete as DeleteProjectKey; +use Appwrite\Platform\Modules\Organization\Http\Projects\Keys\Ephemeral\Create as CreateEphemeralProjectKey; +use Appwrite\Platform\Modules\Organization\Http\Projects\Keys\Get as GetProjectKey; +use Appwrite\Platform\Modules\Organization\Http\Projects\Keys\Update as UpdateProjectKey; +use Appwrite\Platform\Modules\Organization\Http\Projects\Keys\XList as ListProjectKeys; use Appwrite\Platform\Modules\Organization\Http\Projects\Update as UpdateProject; use Appwrite\Platform\Modules\Organization\Http\Projects\XList as ListProjects; use Utopia\Platform\Service; @@ -25,5 +31,13 @@ class Http extends Service $this->addAction(GetProject::getName(), new GetProject()); $this->addAction(UpdateProject::getName(), new UpdateProject()); $this->addAction(DeleteProject::getName(), new DeleteProject()); + + // Project keys + $this->addAction(CreateProjectKey::getName(), new CreateProjectKey()); + $this->addAction(CreateEphemeralProjectKey::getName(), new CreateEphemeralProjectKey()); + $this->addAction(ListProjectKeys::getName(), new ListProjectKeys()); + $this->addAction(GetProjectKey::getName(), new GetProjectKey()); + $this->addAction(UpdateProjectKey::getName(), new UpdateProjectKey()); + $this->addAction(DeleteProjectKey::getName(), new DeleteProjectKey()); } } diff --git a/src/Appwrite/Platform/Modules/Project/Services/Http.php b/src/Appwrite/Platform/Modules/Project/Services/Http.php index a003f4221c..dcb50de969 100644 --- a/src/Appwrite/Platform/Modules/Project/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Project/Services/Http.php @@ -6,12 +6,6 @@ use Appwrite\Platform\Modules\Project\Http\Init; use Appwrite\Platform\Modules\Project\Http\Project\AuthMethods\Update as UpdateAuthMethod; use Appwrite\Platform\Modules\Project\Http\Project\Delete as DeleteProject; use Appwrite\Platform\Modules\Project\Http\Project\Get as GetProject; -use Appwrite\Platform\Modules\Project\Http\Project\Keys\Create as CreateKey; -use Appwrite\Platform\Modules\Project\Http\Project\Keys\Delete as DeleteKey; -use Appwrite\Platform\Modules\Project\Http\Project\Keys\Ephemeral\Create as CreateEphemeralKey; -use Appwrite\Platform\Modules\Project\Http\Project\Keys\Get as GetKey; -use Appwrite\Platform\Modules\Project\Http\Project\Keys\Update as UpdateKey; -use Appwrite\Platform\Modules\Project\Http\Project\Keys\XList as ListKeys; use Appwrite\Platform\Modules\Project\Http\Project\Labels\Update as UpdateProjectLabels; use Appwrite\Platform\Modules\Project\Http\Project\MockPhone\Create as CreateMockPhone; use Appwrite\Platform\Modules\Project\Http\Project\MockPhone\Delete as DeleteMockPhone; @@ -140,14 +134,6 @@ class Http extends Service $this->addAction(DeleteVariable::getName(), new DeleteVariable()); $this->addAction(UpdateVariable::getName(), new UpdateVariable()); - // Keys - $this->addAction(CreateKey::getName(), new CreateKey()); - $this->addAction(CreateEphemeralKey::getName(), new CreateEphemeralKey()); - $this->addAction(ListKeys::getName(), new ListKeys()); - $this->addAction(GetKey::getName(), new GetKey()); - $this->addAction(DeleteKey::getName(), new DeleteKey()); - $this->addAction(UpdateKey::getName(), new UpdateKey()); - // Platforms $this->addAction(ListPlatforms::getName(), new ListPlatforms()); $this->addAction(GetPlatform::getName(), new GetPlatform()); diff --git a/src/Appwrite/SDK/Specification/Format.php b/src/Appwrite/SDK/Specification/Format.php index 5bc393ef7e..9b13122ad6 100644 --- a/src/Appwrite/SDK/Specification/Format.php +++ b/src/Appwrite/SDK/Specification/Format.php @@ -540,7 +540,8 @@ abstract class Format 'nullable' => $nullable, ]; - $config['emitDefault'] = !$config['required'] && !\is_null($default); + // A closure default is resolved per request from injected resources and has no spec representation. + $config['emitDefault'] = !$config['required'] && !\is_null($default) && !($default instanceof \Closure); return $config; } diff --git a/src/Appwrite/Utopia/Request/Filters/V21.php b/src/Appwrite/Utopia/Request/Filters/V21.php index 357f00cfdc..1f90e8b360 100644 --- a/src/Appwrite/Utopia/Request/Filters/V21.php +++ b/src/Appwrite/Utopia/Request/Filters/V21.php @@ -71,7 +71,7 @@ class V21 extends Filter case 'webhooks.create': $content = $this->fillWebhookid($content); break; - case 'project.createKey': + case 'organization.createProjectKey': $content = $this->fillKeyId($content); break; case 'project.createVariable': diff --git a/src/Appwrite/Utopia/Request/Filters/V22.php b/src/Appwrite/Utopia/Request/Filters/V22.php index 7e4c5b8e41..7d3d6bf725 100644 --- a/src/Appwrite/Utopia/Request/Filters/V22.php +++ b/src/Appwrite/Utopia/Request/Filters/V22.php @@ -79,8 +79,8 @@ class V22 extends Filter case 'project.updateProtocol': $content = $this->parseUpdateProtocolStatus($content); break; - case 'project.createKey': - case 'project.updateKey': + case 'organization.createProjectKey': + case 'organization.updateProjectKey': $content = $this->parseKeyScopes($content); break; case 'webhooks.create': diff --git a/src/Appwrite/Utopia/Request/Filters/V24.php b/src/Appwrite/Utopia/Request/Filters/V24.php index f62c1f8c0b..2045b2545b 100644 --- a/src/Appwrite/Utopia/Request/Filters/V24.php +++ b/src/Appwrite/Utopia/Request/Filters/V24.php @@ -10,7 +10,7 @@ class V24 extends Filter public function parse(array $content, string $model): array { switch ($model) { - case 'project.createStandardKey': + case 'organization.createProjectKey': $content = $this->fillKeyId($content); $content = $this->parseKeyScopes($content); break; diff --git a/tests/e2e/Services/Project/KeysBase.php b/tests/e2e/Services/Organization/KeysBase.php similarity index 75% rename from tests/e2e/Services/Project/KeysBase.php rename to tests/e2e/Services/Organization/KeysBase.php index c56a055b76..30a19ffaeb 100644 --- a/tests/e2e/Services/Project/KeysBase.php +++ b/tests/e2e/Services/Organization/KeysBase.php @@ -1,6 +1,6 @@ 'admin', ]; - $key = $this->client->call(Client::METHOD_POST, '/project/keys', $headers, [ + $key = $this->client->call(Client::METHOD_POST, $this->keysPath(), $headers, [ 'keyId' => ID::unique(), 'name' => 'V22 Compat Key', 'scopes' => null, @@ -136,7 +137,7 @@ trait KeysBase ]; $headers = array_merge($headers, $this->getHeaders()); - $updated = $this->client->call(Client::METHOD_PUT, '/project/keys/' . $keyId, $headers, [ + $updated = $this->client->call(Client::METHOD_PUT, $this->keysPath() . '/' . $keyId, $headers, [ 'name' => 'V22 Update Compat Key', 'scopes' => null, ]); @@ -245,7 +246,7 @@ trait KeysBase public function testCreateKeyRequiresSession(): void { // A request authorized with a standard API key cannot create a key - $response = $this->client->call(Client::METHOD_POST, '/project/keys', [ + $response = $this->client->call(Client::METHOD_POST, $this->keysPath(), [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], @@ -262,7 +263,7 @@ trait KeysBase $ephemeral = $this->createEphemeralKey(['keys.read', 'keys.write'], 900); $this->assertSame(201, $ephemeral['headers']['status-code']); - $response = $this->client->call(Client::METHOD_POST, '/project/keys', [ + $response = $this->client->call(Client::METHOD_POST, $this->keysPath(), [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $ephemeral['body']['secret'], @@ -899,10 +900,259 @@ trait KeysBase $this->assertSame('key_not_found', $delete['body']['type']); } + // ========================================================================= + // Organization scope tests + // ========================================================================= + + public function testListKeysWithOrganizationHeader(): void + { + $key = $this->createKey( + ID::unique(), + 'Organization Header Key', + ['users.read'], + ); + $this->assertSame(201, $key['headers']['status-code']); + $keyId = $key['body']['$id']; + + $headers = $this->getOrganizationHeaders($this->getTeamId()); + + /** + * Test for SUCCESS + */ + $list = $this->client->call(Client::METHOD_GET, $this->keysPath(), $headers); + + $this->assertSame(200, $list['headers']['status-code']); + $this->assertContains($keyId, \array_column($list['body']['keys'], '$id')); + + $get = $this->client->call(Client::METHOD_GET, $this->keysPath() . '/' . $keyId, $headers); + + $this->assertSame(200, $get['headers']['status-code']); + $this->assertSame('Organization Header Key', $get['body']['name']); + + $updated = $this->client->call(Client::METHOD_PUT, $this->keysPath() . '/' . $keyId, $headers, [ + 'name' => 'Organization Header Key Updated', + 'scopes' => ['users.read', 'users.write'], + ]); + + $this->assertSame(200, $updated['headers']['status-code']); + $this->assertSame('Organization Header Key Updated', $updated['body']['name']); + + $created = $this->client->call(Client::METHOD_POST, $this->keysPath(), $headers, [ + 'keyId' => ID::unique(), + 'name' => 'Organization Header Created Key', + 'scopes' => ['users.read'], + ]); + + $this->assertSame(201, $created['headers']['status-code']); + $this->assertNotEmpty($created['body']['secret']); + + $ephemeral = $this->client->call(Client::METHOD_POST, $this->keysPath() . '/ephemeral', $headers, [ + 'scopes' => ['users.read'], + 'duration' => 900, + ]); + + $this->assertSame(201, $ephemeral['headers']['status-code']); + $this->assertStringStartsWith(API_KEY_EPHEMERAL . '_', $ephemeral['body']['secret']); + + $delete = $this->client->call(Client::METHOD_DELETE, $this->keysPath() . '/' . $created['body']['$id'], $headers); + + $this->assertSame(204, $delete['headers']['status-code']); + + /** + * Test for FAILURE - missing organization header + */ + $list = $this->client->call(Client::METHOD_GET, $this->keysPath(), $this->getConsoleHeaders()); + + $this->assertSame(401, $list['headers']['status-code']); + + // Cleanup + $this->deleteKey($keyId); + } + + public function testListKeysFromOtherOrganization(): void + { + $key = $this->createKey( + ID::unique(), + 'Other Organization Key', + ['users.read'], + ); + $this->assertSame(201, $key['headers']['status-code']); + $keyId = $key['body']['$id']; + + $otherTeam = $this->createTeamFixture($this->getConsoleHeaders(), [ + 'teamId' => ID::unique(), + 'name' => 'Other Organization', + ]); + $this->assertSame(200, $otherTeam['headers']['status-code']); + + $headers = $this->getOrganizationHeaders($otherTeam['body']['$id']); + + /** + * Test for FAILURE - project belongs to another organization + */ + $list = $this->client->call(Client::METHOD_GET, $this->keysPath(), $headers); + + $this->assertSame(404, $list['headers']['status-code']); + $this->assertSame('project_not_found', $list['body']['type']); + + $get = $this->client->call(Client::METHOD_GET, $this->keysPath() . '/' . $keyId, $headers); + + $this->assertSame(404, $get['headers']['status-code']); + $this->assertSame('project_not_found', $get['body']['type']); + + $delete = $this->client->call(Client::METHOD_DELETE, $this->keysPath() . '/' . $keyId, $headers); + + $this->assertSame(404, $delete['headers']['status-code']); + $this->assertSame('project_not_found', $delete['body']['type']); + + // Verify the key still exists + $get = $this->getKey($keyId); + $this->assertSame(200, $get['headers']['status-code']); + + // Cleanup + $this->deleteKey($keyId); + } + + public function testListKeysWithSiblingProjectKey(): void + { + $sibling = $this->client->call(Client::METHOD_POST, '/projects', $this->getConsoleHeaders(), [ + 'projectId' => ID::unique(), + 'name' => 'Sibling Project', + 'teamId' => $this->getTeamId(), + 'region' => System::getEnv('_APP_REGION', 'default'), + ]); + $this->assertSame(201, $sibling['headers']['status-code']); + $siblingId = $sibling['body']['$id']; + + $headers = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + + /** + * Test for SUCCESS - a project key reaches its own project + */ + $list = $this->client->call(Client::METHOD_GET, $this->keysPath(), $headers); + + $this->assertSame(200, $list['headers']['status-code']); + + /** + * Test for FAILURE - a project key must not reach a sibling project of the same organization + */ + $list = $this->client->call(Client::METHOD_GET, '/organization/projects/' . $siblingId . '/keys', $headers); + + $this->assertSame(401, $list['headers']['status-code']); + + $list = $this->client->call(Client::METHOD_GET, '/projects/' . $siblingId . '/keys', $headers); + + $this->assertSame(403, $list['headers']['status-code']); + $this->assertSame('project_id_missing', $list['body']['type']); + + // Cleanup + $delete = $this->client->call(Client::METHOD_DELETE, '/projects/' . $siblingId, $this->getConsoleHeaders()); + $this->assertSame(204, $delete['headers']['status-code']); + } + + public function testListKeysLegacyPaths(): void + { + $key = $this->createKey( + ID::unique(), + 'Legacy Path Key', + ['users.read'], + ); + $this->assertSame(201, $key['headers']['status-code']); + $keyId = $key['body']['$id']; + + $projectId = $this->getProject()['$id']; + + $projectHeaders = array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()); + + /** + * Test for SUCCESS - /project/keys resolves the project from the request + */ + $list = $this->client->call(Client::METHOD_GET, '/project/keys', $projectHeaders); + + $this->assertSame(200, $list['headers']['status-code']); + $this->assertContains($keyId, \array_column($list['body']['keys'], '$id')); + + $get = $this->client->call(Client::METHOD_GET, '/project/keys/' . $keyId, $projectHeaders); + + $this->assertSame(200, $get['headers']['status-code']); + $this->assertSame('Legacy Path Key', $get['body']['name']); + + $ephemeral = $this->client->call(Client::METHOD_POST, '/project/keys/ephemeral', $projectHeaders, [ + 'scopes' => ['users.read'], + 'duration' => 900, + ]); + + $this->assertSame(201, $ephemeral['headers']['status-code']); + $this->assertStringStartsWith(API_KEY_EPHEMERAL . '_', $ephemeral['body']['secret']); + + /** + * Test for SUCCESS - /projects/:projectId/keys resolves the project from the path + */ + $list = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/keys', $this->getConsoleHeaders()); + + $this->assertSame(200, $list['headers']['status-code']); + $this->assertContains($keyId, \array_column($list['body']['keys'], '$id')); + + $jwt = $this->client->call(Client::METHOD_POST, '/projects/' . $projectId . '/jwts', $this->getConsoleHeaders(), [ + 'scopes' => ['users.read'], + 'duration' => 900, + ]); + + $this->assertSame(201, $jwt['headers']['status-code']); + $this->assertStringStartsWith(API_KEY_EPHEMERAL . '_', $jwt['body']['secret']); + + // Cleanup + $this->deleteKey($keyId); + } + // ========================================================================= // Helpers // ========================================================================= + protected function keysPath(): string + { + return '/organization/projects/' . $this->getProject()['$id'] . '/keys'; + } + + protected function getTeamId(): string + { + $project = $this->client->call(Client::METHOD_GET, '/projects/' . $this->getProject()['$id'], $this->getConsoleHeaders()); + + $this->assertSame(200, $project['headers']['status-code']); + + return $project['body']['teamId']; + } + + /** + * Console session headers for the console project. + */ + protected function getConsoleHeaders(): array + { + return [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'x-appwrite-project' => 'console', + ]; + } + + /** + * Console session headers acting on behalf of an organization. + */ + protected function getOrganizationHeaders(string $teamId): array + { + return array_merge($this->getConsoleHeaders(), [ + 'x-appwrite-organization' => $teamId, + ]); + } + /** * @param array|null $scopes */ @@ -935,7 +1185,7 @@ trait KeysBase ]); } - return $this->client->call(Client::METHOD_POST, '/project/keys', $headers, $params); + return $this->client->call(Client::METHOD_POST, $this->keysPath(), $headers, $params); } /** @@ -966,7 +1216,7 @@ trait KeysBase $headers = array_merge($headers, $this->getHeaders()); } - return $this->client->call(Client::METHOD_PUT, '/project/keys/' . $keyId, $headers, $params); + return $this->client->call(Client::METHOD_PUT, $this->keysPath() . '/' . $keyId, $headers, $params); } protected function getKey(string $keyId, bool $authenticated = true): mixed @@ -980,7 +1230,7 @@ trait KeysBase $headers = array_merge($headers, $this->getHeaders()); } - return $this->client->call(Client::METHOD_GET, '/project/keys/' . $keyId, $headers); + return $this->client->call(Client::METHOD_GET, $this->keysPath() . '/' . $keyId, $headers); } /** @@ -997,7 +1247,7 @@ trait KeysBase $headers = array_merge($headers, $this->getHeaders()); } - return $this->client->call(Client::METHOD_GET, '/project/keys', $headers, [ + return $this->client->call(Client::METHOD_GET, $this->keysPath(), $headers, [ 'queries' => $queries, 'total' => $total, ]); @@ -1014,7 +1264,7 @@ trait KeysBase $headers = array_merge($headers, $this->getHeaders()); } - return $this->client->call(Client::METHOD_DELETE, '/project/keys/' . $keyId, $headers); + return $this->client->call(Client::METHOD_DELETE, $this->keysPath() . '/' . $keyId, $headers); } /** @@ -1039,6 +1289,6 @@ trait KeysBase $headers = array_merge($headers, $this->getHeaders()); } - return $this->client->call(Client::METHOD_POST, '/project/keys/ephemeral', $headers, $params); + return $this->client->call(Client::METHOD_POST, $this->keysPath() . '/ephemeral', $headers, $params); } } diff --git a/tests/e2e/Services/Project/KeysConsoleClientTest.php b/tests/e2e/Services/Organization/KeysConsoleClientTest.php similarity index 85% rename from tests/e2e/Services/Project/KeysConsoleClientTest.php rename to tests/e2e/Services/Organization/KeysConsoleClientTest.php index 43ce02fc72..8af40a80c3 100644 --- a/tests/e2e/Services/Project/KeysConsoleClientTest.php +++ b/tests/e2e/Services/Organization/KeysConsoleClientTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tests\E2E\Services\Project; +namespace Tests\E2E\Services\Organization; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; diff --git a/tests/e2e/Services/Project/KeysCustomServerTest.php b/tests/e2e/Services/Organization/KeysCustomServerTest.php similarity index 85% rename from tests/e2e/Services/Project/KeysCustomServerTest.php rename to tests/e2e/Services/Organization/KeysCustomServerTest.php index 28e7ec04a9..30f9169adb 100644 --- a/tests/e2e/Services/Project/KeysCustomServerTest.php +++ b/tests/e2e/Services/Organization/KeysCustomServerTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tests\E2E\Services\Project; +namespace Tests\E2E\Services\Organization; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; diff --git a/tests/e2e/Services/Project/KeysIntegrationTest.php b/tests/e2e/Services/Organization/KeysIntegrationTest.php similarity index 96% rename from tests/e2e/Services/Project/KeysIntegrationTest.php rename to tests/e2e/Services/Organization/KeysIntegrationTest.php index f6ec57a904..f697911b88 100644 --- a/tests/e2e/Services/Project/KeysIntegrationTest.php +++ b/tests/e2e/Services/Organization/KeysIntegrationTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tests\E2E\Services\Project; +namespace Tests\E2E\Services\Organization; use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; @@ -37,7 +37,7 @@ final class KeysIntegrationTest extends Scope // Step 1: Create an ephemeral key scoped to users.read only. $ephemeralKey = $this->client->call( Client::METHOD_POST, - '/project/keys/ephemeral', + '/organization/projects/' . $projectId . '/keys/ephemeral', $serverHeaders, [ 'scopes' => ['users.read'], diff --git a/tests/e2e/Services/Organization/ProjectsBase.php b/tests/e2e/Services/Organization/ProjectsBase.php index e5792dc1f3..2434f68190 100644 --- a/tests/e2e/Services/Organization/ProjectsBase.php +++ b/tests/e2e/Services/Organization/ProjectsBase.php @@ -27,7 +27,7 @@ trait ProjectsBase $team = $this->createTeamFixture(array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ + ], $this->getConsoleHeaders()), [ 'teamId' => $teamId, 'name' => 'Organization Test', ]); @@ -40,11 +40,22 @@ trait ProjectsBase return self::$cachedOrganization; } + /** + * Console session headers. Admin mode is rejected for the console project. + */ + protected function getConsoleHeaders(): array + { + $headers = $this->getHeaders(); + unset($headers['x-appwrite-mode']); + + return $headers; + } + protected function getOrganizationHeaders(): array { $organization = $this->setupOrganization(); - return array_merge($this->getHeaders(), [ + return array_merge($this->getConsoleHeaders(), [ 'x-appwrite-organization' => $organization['teamId'], ]); } @@ -60,7 +71,7 @@ trait ProjectsBase $project = null; for ($i = 0; $i < 3; $i++) { - $project = $this->client->call(Client::METHOD_POST, '/v1/organization/projects', array_merge([ + $project = $this->client->call(Client::METHOD_POST, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders()), [ @@ -91,7 +102,7 @@ trait ProjectsBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_POST, '/v1/organization/projects', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders()), [ @@ -105,28 +116,25 @@ trait ProjectsBase $this->assertEquals('Organization Project Test', $response['body']['name']); $this->assertEquals($teamId, $response['body']['teamId']); $this->assertEquals(PROJECT_STATUS_ACTIVE, $response['body']['status']); - $this->assertArrayHasKey('platforms', $response['body']); - $this->assertArrayHasKey('webhooks', $response['body']); - $this->assertArrayHasKey('keys', $response['body']); /** * Test for FAILURE - missing organization header */ - $response = $this->client->call(Client::METHOD_POST, '/v1/organization/projects', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ + ], $this->getConsoleHeaders()), [ 'projectId' => ID::unique(), 'name' => 'Organization Project Test', 'region' => System::getEnv('_APP_REGION', 'default'), ]); - $this->assertEquals(404, $response['headers']['status-code']); + $this->assertEquals(401, $response['headers']['status-code']); /** * Test for FAILURE - empty name */ - $response = $this->client->call(Client::METHOD_POST, '/v1/organization/projects', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders()), [ @@ -143,7 +151,7 @@ trait ProjectsBase $organization = $this->setupOrganization(); $projectId = ID::unique(); - $response = $this->client->call(Client::METHOD_POST, '/v1/organization/projects', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders()), [ @@ -157,7 +165,7 @@ trait ProjectsBase /** * Test for FAILURE - duplicate project ID */ - $response = $this->client->call(Client::METHOD_POST, '/v1/organization/projects', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders()), [ @@ -179,7 +187,7 @@ trait ProjectsBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/v1/organization/projects/' . $projectId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/organization/projects/' . $projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders())); @@ -189,14 +197,11 @@ trait ProjectsBase $this->assertEquals($projectId, $response['body']['$id']); $this->assertEquals('Organization Project Test', $response['body']['name']); $this->assertEquals(PROJECT_STATUS_ACTIVE, $response['body']['status']); - $this->assertArrayHasKey('platforms', $response['body']); - $this->assertArrayHasKey('webhooks', $response['body']); - $this->assertArrayHasKey('keys', $response['body']); /** * Test for FAILURE - project not found */ - $response = $this->client->call(Client::METHOD_GET, '/v1/organization/projects/' . ID::unique(), array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/organization/projects/' . ID::unique(), array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders())); @@ -209,17 +214,17 @@ trait ProjectsBase $otherTeam = $this->createTeamFixture(array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ + ], $this->getConsoleHeaders()), [ 'teamId' => ID::unique(), 'name' => 'Other Organization', ]); $this->assertContains($otherTeam['headers']['status-code'], [200]); $otherTeamId = $otherTeam['body']['$id'] ?? $otherTeam['body']['teamId']; - $otherProject = $this->client->call(Client::METHOD_POST, '/v1/organization/projects', array_merge([ + $otherProject = $this->client->call(Client::METHOD_POST, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - ], array_merge($this->getHeaders(), [ + ], array_merge($this->getConsoleHeaders(), [ 'x-appwrite-organization' => $otherTeamId, ])), [ 'projectId' => ID::unique(), @@ -229,7 +234,7 @@ trait ProjectsBase $this->assertEquals(201, $otherProject['headers']['status-code']); $otherProjectId = $otherProject['body']['$id']; - $response = $this->client->call(Client::METHOD_GET, '/v1/organization/projects/' . $otherProjectId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/organization/projects/' . $otherProjectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders())); @@ -245,7 +250,7 @@ trait ProjectsBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PATCH, '/v1/organization/projects/' . $projectId, array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/organization/projects/' . $projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders()), [ @@ -259,7 +264,7 @@ trait ProjectsBase /** * Test for FAILURE - project not found */ - $response = $this->client->call(Client::METHOD_PATCH, '/v1/organization/projects/' . ID::unique(), array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/organization/projects/' . ID::unique(), array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders()), [ @@ -271,7 +276,7 @@ trait ProjectsBase /** * Test for FAILURE - empty name */ - $response = $this->client->call(Client::METHOD_PATCH, '/v1/organization/projects/' . $projectId, array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/organization/projects/' . $projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders()), [ @@ -285,7 +290,7 @@ trait ProjectsBase { $organization = $this->setupOrganization(); - $project = $this->client->call(Client::METHOD_POST, '/v1/organization/projects', array_merge([ + $project = $this->client->call(Client::METHOD_POST, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders()), [ @@ -300,7 +305,7 @@ trait ProjectsBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_DELETE, '/v1/organization/projects/' . $projectId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/organization/projects/' . $projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders())); @@ -308,7 +313,7 @@ trait ProjectsBase $this->assertEquals(204, $response['headers']['status-code']); // Verify project is actually deleted - $response = $this->client->call(Client::METHOD_GET, '/v1/organization/projects/' . $projectId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/organization/projects/' . $projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders())); @@ -318,7 +323,7 @@ trait ProjectsBase /** * Test for FAILURE - project not found (already deleted) */ - $response = $this->client->call(Client::METHOD_DELETE, '/v1/organization/projects/' . $projectId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/organization/projects/' . $projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders())); @@ -332,7 +337,7 @@ trait ProjectsBase $teamId = $organization['teamId']; // Create a second project in the same organization - $project2 = $this->client->call(Client::METHOD_POST, '/v1/organization/projects', array_merge([ + $project2 = $this->client->call(Client::METHOD_POST, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders()), [ @@ -347,7 +352,7 @@ trait ProjectsBase /** * Test for SUCCESS - basic list */ - $response = $this->client->call(Client::METHOD_GET, '/v1/organization/projects', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders())); @@ -360,7 +365,7 @@ trait ProjectsBase /** * Test search queries */ - $response = $this->client->call(Client::METHOD_GET, '/v1/organization/projects', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders(), [ @@ -370,12 +375,12 @@ trait ProjectsBase $this->assertEquals(200, $response['headers']['status-code']); $this->assertGreaterThan(0, $response['body']['total']); $this->assertIsArray($response['body']['projects']); - $this->assertEquals('Second Organization Project', $response['body']['projects'][0]['name']); + $this->assertContains('Second Organization Project', \array_column($response['body']['projects'], 'name')); /** * Test pagination with limit */ - $response = $this->client->call(Client::METHOD_GET, '/v1/organization/projects', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders()), [ @@ -390,7 +395,7 @@ trait ProjectsBase /** * Test pagination with offset */ - $response = $this->client->call(Client::METHOD_GET, '/v1/organization/projects', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders()), [ @@ -405,7 +410,7 @@ trait ProjectsBase /** * Test query by name */ - $response = $this->client->call(Client::METHOD_GET, '/v1/organization/projects', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders()), [ @@ -416,12 +421,12 @@ trait ProjectsBase $this->assertEquals(200, $response['headers']['status-code']); $this->assertGreaterThanOrEqual(1, count($response['body']['projects'])); - $this->assertEquals('Second Organization Project', $response['body']['projects'][0]['name']); + $this->assertContains('Second Organization Project', \array_column($response['body']['projects'], 'name')); /** * Test cursor pagination */ - $response = $this->client->call(Client::METHOD_GET, '/v1/organization/projects', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders())); @@ -429,7 +434,7 @@ trait ProjectsBase $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['projects']); - $response = $this->client->call(Client::METHOD_GET, '/v1/organization/projects', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders()), [ @@ -444,7 +449,7 @@ trait ProjectsBase /** * Test for FAILURE - invalid cursor */ - $response = $this->client->call(Client::METHOD_GET, '/v1/organization/projects', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders()), [ @@ -461,7 +466,7 @@ trait ProjectsBase $data = $this->setupOrganizationProject(); $projectId = $data['projectId']; - $response = $this->client->call(Client::METHOD_GET, '/v1/organization/projects', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/organization/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getOrganizationHeaders()), [ diff --git a/tests/unit/SDK/Specification/FormatTest.php b/tests/unit/SDK/Specification/FormatTest.php index 47e6ed01f3..4eed7233c8 100644 --- a/tests/unit/SDK/Specification/FormatTest.php +++ b/tests/unit/SDK/Specification/FormatTest.php @@ -179,6 +179,14 @@ final class FormatTest extends TestCase $this->assertTrue($listPlatforms['emitDefault']); } + public function testClosureDefaultIsNotEmitted(): void + { + $projectId = $this->format->requestParameterConfig(true, false, fn () => 'resolved', 'organization.getProjectKey', 'projectId'); + + $this->assertFalse($projectId['required']); + $this->assertFalse($projectId['emitDefault']); + } + public function testProjectPlatformResponseTypeUsesSharedEnumMetadata(): void { $models = [ From e1f87fcb544abae7044cc1a4004b939c6b15e410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 11 Sep 2026 11:12:11 +0200 Subject: [PATCH 2/7] feat(organization): keep the project-scoped keys endpoints during the transition Restore /v1/project/keys (and its /v1/projects/:projectId aliases) in the Project module unchanged, marked with a TODO to remove once the Console, CLI and SDKs use the Organization API. The Organization actions drop their aliases and take projectId as a plain required path param, so the closure-default handling in the spec generator is no longer needed. Request filters and onboarding accept both the legacy and the new SDK method names. A one-test smoke suite covers the legacy endpoints. Co-Authored-By: Claude Fable 5.1 --- app/config/onboarding.php | 1 + .../Http/Projects/Keys/Create.php | 4 +- .../Http/Projects/Keys/Delete.php | 4 +- .../Http/Projects/Keys/Ephemeral/Create.php | 4 +- .../Organization/Http/Projects/Keys/Get.php | 4 +- .../Http/Projects/Keys/Update.php | 4 +- .../Organization/Http/Projects/Keys/XList.php | 4 +- .../Project/Http/Project/Keys/Create.php | 131 ++++++++++++++++++ .../Project/Http/Project/Keys/Delete.php | 94 +++++++++++++ .../Http/Project/Keys/Ephemeral/Create.php | 111 +++++++++++++++ .../Modules/Project/Http/Project/Keys/Get.php | 78 +++++++++++ .../Project/Http/Project/Keys/Update.php | 113 +++++++++++++++ .../Project/Http/Project/Keys/XList.php | 131 ++++++++++++++++++ .../Modules/Project/Services/Http.php | 15 ++ src/Appwrite/SDK/Specification/Format.php | 3 +- src/Appwrite/Utopia/Request/Filters/V21.php | 1 + src/Appwrite/Utopia/Request/Filters/V22.php | 2 + src/Appwrite/Utopia/Request/Filters/V24.php | 2 +- tests/e2e/Services/Organization/KeysBase.php | 64 +-------- tests/e2e/Services/Project/KeysBase.php | 83 +++++++++++ .../Project/KeysConsoleClientTest.php | 16 +++ .../Services/Project/KeysCustomServerTest.php | 16 +++ tests/unit/SDK/Specification/FormatTest.php | 8 -- 23 files changed, 801 insertions(+), 92 deletions(-) create mode 100644 src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php create mode 100644 src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Delete.php create mode 100644 src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php create mode 100644 src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Get.php create mode 100644 src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Update.php create mode 100644 src/Appwrite/Platform/Modules/Project/Http/Project/Keys/XList.php create mode 100644 tests/e2e/Services/Project/KeysBase.php create mode 100644 tests/e2e/Services/Project/KeysConsoleClientTest.php create mode 100644 tests/e2e/Services/Project/KeysCustomServerTest.php diff --git a/app/config/onboarding.php b/app/config/onboarding.php index a27295acfe..316ff88cb2 100644 --- a/app/config/onboarding.php +++ b/app/config/onboarding.php @@ -13,6 +13,7 @@ return [ 'project.createWindowsPlatform' => true, 'project.createLinuxPlatform' => true, // Connect — API key + 'project.createKey' => true, // TODO: Remove with the project-scoped keys endpoints 'organization.createProjectKey' => true, // Auth diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Create.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Create.php index 53f0717e68..74e2401167 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Create.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Create.php @@ -39,8 +39,6 @@ class Create extends Action $this ->setHttpMethod(Action::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/organization/projects/:projectId/keys') - ->httpAlias('/v1/project/keys') - ->httpAlias('/v1/projects/:projectId/keys') ->desc('Create project key') ->groups(['api', 'organization']) ->label('scope', 'keys.write') @@ -64,7 +62,7 @@ class Create extends Action ) ], )) - ->param('projectId', fn (Document $project) => $project->getId(), new UID(), 'Project unique ID.', true, ['project']) + ->param('projectId', '', new UID(), 'Project unique ID.') ->param('keyId', '', fn (Database $dbForPlatform) => new CustomId(false, $dbForPlatform->getAdapter()->getMaxUIDLength()), 'Key ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForPlatform']) ->param('name', null, new Text(128), 'Key name. Max length: 128 chars.') ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_SCOPES_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_SCOPES_SIZE . ' scopes are allowed.', optional: false, enum: new Enum(name: 'ProjectKeyScopes')) diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Delete.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Delete.php index 91b923e339..f53b40b614 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Delete.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Delete.php @@ -30,8 +30,6 @@ class Delete extends Action $this ->setHttpMethod(Action::HTTP_REQUEST_METHOD_DELETE) ->setHttpPath('/v1/organization/projects/:projectId/keys/:keyId') - ->httpAlias('/v1/project/keys/:keyId') - ->httpAlias('/v1/projects/:projectId/keys/:keyId') ->desc('Delete project key') ->groups(['api', 'organization']) ->label('scope', 'keys.write') @@ -54,7 +52,7 @@ class Delete extends Action ], contentType: ContentType::NONE )) - ->param('projectId', fn (Document $project) => $project->getId(), new UID(), 'Project unique ID.', true, ['project']) + ->param('projectId', '', new UID(), 'Project unique ID.') ->param('keyId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Key ID.', false, ['dbForPlatform']) ->inject('response') ->inject('dbForPlatform') diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Ephemeral/Create.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Ephemeral/Create.php index 1677883e26..a043dbeef0 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Ephemeral/Create.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Ephemeral/Create.php @@ -37,8 +37,6 @@ class Create extends Action $this ->setHttpMethod(Action::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/organization/projects/:projectId/keys/ephemeral') - ->httpAlias('/v1/project/keys/ephemeral') - ->httpAlias('/v1/projects/:projectId/jwts') ->desc('Create ephemeral project key') ->groups(['api', 'organization']) ->label('scope', 'keys.write') @@ -62,7 +60,7 @@ class Create extends Action ) ], )) - ->param('projectId', fn (Document $project) => $project->getId(), new UID(), 'Project unique ID.', true, ['project']) + ->param('projectId', '', new UID(), 'Project unique ID.') ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_SCOPES_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_SCOPES_SIZE . ' scopes are allowed.', optional: false, enum: new Enum(name: 'ProjectKeyScopes')) ->param('duration', null, new Range(1, 3600), 'Time in seconds before ephemeral key expires. Maximum duration is 3600 seconds.', optional: false, example: 600) ->inject('response') diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Get.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Get.php index 9eab435f94..70caad8587 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Get.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Get.php @@ -28,8 +28,6 @@ class Get extends Action $this ->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/organization/projects/:projectId/keys/:keyId') - ->httpAlias('/v1/project/keys/:keyId') - ->httpAlias('/v1/projects/:projectId/keys/:keyId') ->desc('Get project key') ->groups(['api', 'organization']) ->label('scope', 'keys.read') @@ -48,7 +46,7 @@ class Get extends Action ) ] )) - ->param('projectId', fn (Document $project) => $project->getId(), new UID(), 'Project unique ID.', true, ['project']) + ->param('projectId', '', new UID(), 'Project unique ID.') ->param('keyId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Key ID.', false, ['dbForPlatform']) ->inject('response') ->inject('dbForPlatform') diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Update.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Update.php index c45231c068..143d590580 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Update.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Update.php @@ -37,8 +37,6 @@ class Update extends Action $this ->setHttpMethod(Action::HTTP_REQUEST_METHOD_PUT) ->setHttpPath('/v1/organization/projects/:projectId/keys/:keyId') - ->httpAlias('/v1/project/keys/:keyId') - ->httpAlias('/v1/projects/:projectId/keys/:keyId') ->desc('Update project key') ->groups(['api', 'organization']) ->label('scope', 'keys.write') @@ -60,7 +58,7 @@ class Update extends Action ) ] )) - ->param('projectId', fn (Document $project) => $project->getId(), new UID(), 'Project unique ID.', true, ['project']) + ->param('projectId', '', new UID(), 'Project unique ID.') ->param('keyId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Key ID.', false, ['dbForPlatform']) ->param('name', null, new Text(128), 'Key name. Max length: 128 chars.') ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_SCOPES_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_SCOPES_SIZE . ' scopes are allowed.', optional: false, enum: new Enum(name: 'ProjectKeyScopes')) diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/XList.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/XList.php index 0dc599b024..2ec6b484a3 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/XList.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/XList.php @@ -34,8 +34,6 @@ class XList extends Action $this ->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/organization/projects/:projectId/keys') - ->httpAlias('/v1/project/keys') - ->httpAlias('/v1/projects/:projectId/keys') ->desc('List project keys') ->groups(['api', 'organization']) ->label('scope', 'keys.read') @@ -54,7 +52,7 @@ class XList extends Action ) ] )) - ->param('projectId', fn (Document $project) => $project->getId(), new UID(), 'Project unique ID.', true, ['project']) + ->param('projectId', '', new UID(), 'Project unique ID.') ->param('queries', [], new Keys(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Keys::ALLOWED_ATTRIBUTES), true) ->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php new file mode 100644 index 0000000000..2909f14c68 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php @@ -0,0 +1,131 @@ +setHttpMethod(Action::HTTP_REQUEST_METHOD_POST) + ->setHttpPath('/v1/project/keys') + ->httpAlias('/v1/projects/:projectId/keys') + ->desc('Create project key') + ->groups(['api', 'project']) + ->label('scope', 'keys.write') + ->label('event', 'keys.[keyId].create') + ->label('audits.event', 'project.key.create') + ->label('audits.resource', 'project.key/{response.$id}') + ->label('sdk', new Method( + namespace: 'project', + group: 'keys', + name: 'createKey', + description: <<param('keyId', '', fn (Database $dbForPlatform) => new CustomId(false, $dbForPlatform->getAdapter()->getMaxUIDLength()), 'Key ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForPlatform']) + ->param('name', null, new Text(128), 'Key name. Max length: 128 chars.') + ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_SCOPES_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_SCOPES_SIZE . ' scopes are allowed.', optional: false, enum: new Enum(name: 'ProjectKeyScopes')) + ->param('expire', null, new Nullable(new Datetime()), 'Expiration time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. Use null for unlimited expiration.', true) + ->inject('response') + ->inject('queueForEvents') + ->inject('dbForPlatform') + ->inject('project') + ->inject('authorization') + ->inject('apiKey') + ->callback($this->action(...)); + } + + public function action( + string $keyId, + string $name, + array $scopes, + ?string $expire, + Response $response, + QueueEvent $queueForEvents, + Database $dbForPlatform, + Document $project, + Authorization $authorization, + ?Key $apiKey, + ) { + // Dynamic supported for backwards compatibility + if ($apiKey !== null && \in_array($apiKey->getType(), [API_KEY_STANDARD, API_KEY_EPHEMERAL, 'dynamic'], true)) { + throw new Exception(Exception::KEY_CREATION_DENIED); + } + + $keyId = ($keyId == 'unique()') ? ID::unique() : $keyId; + + $key = new Document([ + '$id' => $keyId, + '$permissions' => [], + 'resourceInternalId' => $project->getSequence(), + 'resourceId' => $project->getId(), + 'resourceType' => 'projects', + 'name' => $name, + 'scopes' => $scopes, + 'expire' => $expire, + 'sdks' => [], + 'accessedAt' => null, + 'secret' => API_KEY_STANDARD . '_' . \bin2hex(\random_bytes(128)), + ]); + + try { + $key = $authorization->skip(fn () => $dbForPlatform->createDocument('keys', $key)); + } catch (DuplicateException) { + throw new Exception(Exception::KEY_ALREADY_EXISTS); + } + + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); + + $queueForEvents->setParam('keyId', $key->getId()); + + $response + ->setStatusCode(Response::STATUS_CODE_CREATED) + ->dynamic($key, Response::MODEL_KEY); + } +} diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Delete.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Delete.php new file mode 100644 index 0000000000..70670e33a7 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Delete.php @@ -0,0 +1,94 @@ +setHttpMethod(Action::HTTP_REQUEST_METHOD_DELETE) + ->setHttpPath('/v1/project/keys/:keyId') + ->httpAlias('/v1/projects/:projectId/keys/:keyId') + ->desc('Delete project key') + ->groups(['api', 'project']) + ->label('scope', 'keys.write') + ->label('event', 'keys.[keyId].delete') + ->label('audits.event', 'project.key.delete') + ->label('audits.resource', 'project.key/{request.keyId}') + ->label('sdk', new Method( + namespace: 'project', + group: 'keys', + name: 'deleteKey', + description: <<param('keyId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Key ID.', false, ['dbForPlatform']) + ->inject('response') + ->inject('dbForPlatform') + ->inject('queueForEvents') + ->inject('project') + ->inject('authorization') + ->callback($this->action(...)); + } + + public function action( + string $keyId, + Response $response, + Database $dbForPlatform, + Event $queueForEvents, + Document $project, + Authorization $authorization, + ) { + $key = $authorization->skip(fn () => $dbForPlatform->getDocument('keys', $keyId)); + + if ($key->isEmpty() || $key->getAttribute('resourceType', '') !== 'projects' || $key->getAttribute('resourceInternalId', '') !== $project->getSequence()) { + throw new Exception(Exception::KEY_NOT_FOUND); + } + + if (!$authorization->skip(fn () => $dbForPlatform->deleteDocument('keys', $key->getId()))) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove document from DB'); + }; + + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); + + $queueForEvents->setParam('keyId', $key->getId()); + + $response->noContent(); + } +} diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php new file mode 100644 index 0000000000..7a5ddaf34c --- /dev/null +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php @@ -0,0 +1,111 @@ +setHttpMethod(Action::HTTP_REQUEST_METHOD_POST) + ->setHttpPath('/v1/project/keys/ephemeral') + ->httpAlias('/v1/projects/:projectId/jwts') + ->desc('Create ephemeral project key') + ->groups(['api', 'project']) + ->label('scope', 'keys.write') + ->label('event', 'keys.[keyId].create') + ->label('audits.event', 'project.key.create') + ->label('audits.resource', 'project.key/{response.$id}') + ->label('sdk', new Method( + namespace: 'project', + group: 'keys', + name: 'createEphemeralKey', + description: <<param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_SCOPES_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_SCOPES_SIZE . ' scopes are allowed.', optional: false, enum: new Enum(name: 'ProjectKeyScopes')) + ->param('duration', null, new Range(1, 3600), 'Time in seconds before ephemeral key expires. Maximum duration is 3600 seconds.', optional: false, example: 600) + ->inject('response') + ->inject('queueForEvents') + ->inject('project') + ->callback($this->action(...)); + } + + public function action( + array $scopes, + int $duration, + Response $response, + QueueEvent $queueForEvents, + Document $project, + ) { + $keyId = ID::unique(); + + $jwt = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', $duration, 0); + + $secret = $jwt->encode([ + 'projectId' => $project->getId(), + 'scopes' => $scopes + ]); + + $now = new \DateTime(); + $expire = $now->add(new \DateInterval('PT' . $duration . 'S'))->format('Y-m-d\TH:i:s.u\Z'); + + $key = new Document([ + '$id' => $keyId, + '$createdAt' => DatabaseDateTime::now(), + '$updatedAt' => DatabaseDateTime::now(), + 'name' => '', + 'scopes' => $scopes, + 'expire' => $expire, + 'sdks' => [], + 'accessedAt' => null, + 'secret' => API_KEY_EPHEMERAL . '_' . $secret, + ]); + + $queueForEvents->setParam('keyId', $key->getId()); + + $response + ->setStatusCode(Response::STATUS_CODE_CREATED) + ->dynamic($key, Response::MODEL_EPHEMERAL_KEY); + } +} diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Get.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Get.php new file mode 100644 index 0000000000..fcb4e8b410 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Get.php @@ -0,0 +1,78 @@ +setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) + ->setHttpPath('/v1/project/keys/:keyId') + ->httpAlias('/v1/projects/:projectId/keys/:keyId') + ->desc('Get project key') + ->groups(['api', 'project']) + ->label('scope', 'keys.read') + ->label('sdk', new Method( + namespace: 'project', + group: 'keys', + name: 'getKey', + description: <<param('keyId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Key ID.', false, ['dbForPlatform']) + ->inject('response') + ->inject('dbForPlatform') + ->inject('project') + ->inject('authorization') + ->callback($this->action(...)); + } + + public function action( + string $keyId, + Response $response, + Database $dbForPlatform, + Document $project, + Authorization $authorization, + ) { + $key = $authorization->skip(fn () => $dbForPlatform->getDocument('keys', $keyId)); + + if ($key->isEmpty() || $key->getAttribute('resourceType', '') !== 'projects' || $key->getAttribute('resourceInternalId', '') !== $project->getSequence()) { + throw new Exception(Exception::KEY_NOT_FOUND); + } + + $response->dynamic($key, Response::MODEL_KEY); + } +} diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Update.php new file mode 100644 index 0000000000..557c03c712 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Update.php @@ -0,0 +1,113 @@ +setHttpMethod(Action::HTTP_REQUEST_METHOD_PUT) + ->setHttpPath('/v1/project/keys/:keyId') + ->httpAlias('/v1/projects/:projectId/keys/:keyId') + ->desc('Update project key') + ->groups(['api', 'project']) + ->label('scope', 'keys.write') + ->label('event', 'keys.[keyId].update') + ->label('audits.event', 'project.key.update') + ->label('audits.resource', 'project.key/{response.$id}') + ->label('sdk', new Method( + namespace: 'project', + group: 'keys', + name: 'updateKey', + description: <<param('keyId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Key ID.', false, ['dbForPlatform']) + ->param('name', null, new Text(128), 'Key name. Max length: 128 chars.') + ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_SCOPES_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_SCOPES_SIZE . ' scopes are allowed.', optional: false, enum: new Enum(name: 'ProjectKeyScopes')) + ->param('expire', null, new Nullable(new Datetime()), 'Expiration time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. Use null for unlimited expiration.', true) + ->inject('response') + ->inject('queueForEvents') + ->inject('dbForPlatform') + ->inject('project') + ->inject('authorization') + ->callback($this->action(...)); + } + + public function action( + string $keyId, + string $name, + array $scopes, + ?string $expire, + Response $response, + QueueEvent $queueForEvents, + Database $dbForPlatform, + Document $project, + Authorization $authorization, + ) { + $key = $authorization->skip(fn () => $dbForPlatform->getDocument('keys', $keyId)); + + if ($key->isEmpty() || $key->getAttribute('resourceType', '') !== 'projects' || $key->getAttribute('resourceInternalId', '') !== $project->getSequence()) { + throw new Exception(Exception::KEY_NOT_FOUND); + } + + $updates = new Document([ + 'name' => $name, + 'scopes' => $scopes, + 'expire' => $expire, + ]); + + try { + $key = $authorization->skip(fn () => $dbForPlatform->updateDocument('keys', $key->getId(), $updates)); + } catch (Duplicate) { + throw new Exception(Exception::KEY_ALREADY_EXISTS); + } + + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); + + $queueForEvents->setParam('keyId', $key->getId()); + + $response->dynamic($key, Response::MODEL_KEY); + } +} diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/XList.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/XList.php new file mode 100644 index 0000000000..ffa5d62506 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/XList.php @@ -0,0 +1,131 @@ +setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) + ->setHttpPath('/v1/project/keys') + ->httpAlias('/v1/projects/:projectId/keys') + ->desc('List project keys') + ->groups(['api', 'project']) + ->label('scope', 'keys.read') + ->label('sdk', new Method( + namespace: 'project', + group: 'keys', + name: 'listKeys', + description: <<param('queries', [], new Keys(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Keys::ALLOWED_ATTRIBUTES), true) + ->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true) + ->inject('project') + ->inject('response') + ->inject('dbForPlatform') + ->inject('authorization') + ->callback($this->action(...)); + } + + /** + * @param array $queries + */ + public function action( + array $queries, + bool $includeTotal, + Document $project, + Response $response, + Database $dbForPlatform, + Authorization $authorization, + ) { + try { + $queries = Query::parseQueries($queries); + } catch (QueryException $e) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage()); + } + + // Backwards compatibility + if (\count(Query::getByType($queries, [Query::TYPE_LIMIT])) === 0) { + $queries[] = Query::limit(5000); + } + + $queries[] = Query::equal('resourceType', ['projects']); + $queries[] = Query::equal('resourceInternalId', [$project->getSequence()]); + + $cursor = Query::getCursorQueries($queries, false); + $cursor = \reset($cursor); + + if ($cursor !== false) { + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + + $keyId = $cursor->getValue(); + $cursorDocument = $authorization->skip(fn () => $dbForPlatform->findOne('keys', [ + Query::equal('$id', [$keyId]), + Query::equal('resourceType', ['projects']), + Query::equal('resourceInternalId', [$project->getSequence()]), + ])); + + if ($cursorDocument->isEmpty()) { + throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Key '{$keyId}' for the 'cursor' value not found."); + } + + $cursor->setValue($cursorDocument); + } + + $filterQueries = Query::groupByType($queries)['filters']; + + try { + $keys = $authorization->skip(fn () => $dbForPlatform->find('keys', $queries)); + $total = $includeTotal ? $authorization->skip(fn () => $dbForPlatform->count('keys', $filterQueries, APP_LIMIT_COUNT)) : 0; + } catch (OrderException $e) { + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); + } + + $response->dynamic(new Document([ + 'keys' => $keys, + 'total' => $total, + ]), Response::MODEL_KEY_LIST); + } +} diff --git a/src/Appwrite/Platform/Modules/Project/Services/Http.php b/src/Appwrite/Platform/Modules/Project/Services/Http.php index dcb50de969..5d07402d20 100644 --- a/src/Appwrite/Platform/Modules/Project/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Project/Services/Http.php @@ -6,6 +6,12 @@ use Appwrite\Platform\Modules\Project\Http\Init; use Appwrite\Platform\Modules\Project\Http\Project\AuthMethods\Update as UpdateAuthMethod; use Appwrite\Platform\Modules\Project\Http\Project\Delete as DeleteProject; use Appwrite\Platform\Modules\Project\Http\Project\Get as GetProject; +use Appwrite\Platform\Modules\Project\Http\Project\Keys\Create as CreateKey; +use Appwrite\Platform\Modules\Project\Http\Project\Keys\Delete as DeleteKey; +use Appwrite\Platform\Modules\Project\Http\Project\Keys\Ephemeral\Create as CreateEphemeralKey; +use Appwrite\Platform\Modules\Project\Http\Project\Keys\Get as GetKey; +use Appwrite\Platform\Modules\Project\Http\Project\Keys\Update as UpdateKey; +use Appwrite\Platform\Modules\Project\Http\Project\Keys\XList as ListKeys; use Appwrite\Platform\Modules\Project\Http\Project\Labels\Update as UpdateProjectLabels; use Appwrite\Platform\Modules\Project\Http\Project\MockPhone\Create as CreateMockPhone; use Appwrite\Platform\Modules\Project\Http\Project\MockPhone\Delete as DeleteMockPhone; @@ -134,6 +140,15 @@ class Http extends Service $this->addAction(DeleteVariable::getName(), new DeleteVariable()); $this->addAction(UpdateVariable::getName(), new UpdateVariable()); + // Keys + // TODO: Remove once the Console, CLI and SDKs use the Organization API instead + $this->addAction(CreateKey::getName(), new CreateKey()); + $this->addAction(CreateEphemeralKey::getName(), new CreateEphemeralKey()); + $this->addAction(ListKeys::getName(), new ListKeys()); + $this->addAction(GetKey::getName(), new GetKey()); + $this->addAction(DeleteKey::getName(), new DeleteKey()); + $this->addAction(UpdateKey::getName(), new UpdateKey()); + // Platforms $this->addAction(ListPlatforms::getName(), new ListPlatforms()); $this->addAction(GetPlatform::getName(), new GetPlatform()); diff --git a/src/Appwrite/SDK/Specification/Format.php b/src/Appwrite/SDK/Specification/Format.php index 9b13122ad6..5bc393ef7e 100644 --- a/src/Appwrite/SDK/Specification/Format.php +++ b/src/Appwrite/SDK/Specification/Format.php @@ -540,8 +540,7 @@ abstract class Format 'nullable' => $nullable, ]; - // A closure default is resolved per request from injected resources and has no spec representation. - $config['emitDefault'] = !$config['required'] && !\is_null($default) && !($default instanceof \Closure); + $config['emitDefault'] = !$config['required'] && !\is_null($default); return $config; } diff --git a/src/Appwrite/Utopia/Request/Filters/V21.php b/src/Appwrite/Utopia/Request/Filters/V21.php index 1f90e8b360..e000bbe331 100644 --- a/src/Appwrite/Utopia/Request/Filters/V21.php +++ b/src/Appwrite/Utopia/Request/Filters/V21.php @@ -71,6 +71,7 @@ class V21 extends Filter case 'webhooks.create': $content = $this->fillWebhookid($content); break; + case 'project.createKey': case 'organization.createProjectKey': $content = $this->fillKeyId($content); break; diff --git a/src/Appwrite/Utopia/Request/Filters/V22.php b/src/Appwrite/Utopia/Request/Filters/V22.php index 7d3d6bf725..3c710c1e1c 100644 --- a/src/Appwrite/Utopia/Request/Filters/V22.php +++ b/src/Appwrite/Utopia/Request/Filters/V22.php @@ -79,6 +79,8 @@ class V22 extends Filter case 'project.updateProtocol': $content = $this->parseUpdateProtocolStatus($content); break; + case 'project.createKey': + case 'project.updateKey': case 'organization.createProjectKey': case 'organization.updateProjectKey': $content = $this->parseKeyScopes($content); diff --git a/src/Appwrite/Utopia/Request/Filters/V24.php b/src/Appwrite/Utopia/Request/Filters/V24.php index 2045b2545b..f62c1f8c0b 100644 --- a/src/Appwrite/Utopia/Request/Filters/V24.php +++ b/src/Appwrite/Utopia/Request/Filters/V24.php @@ -10,7 +10,7 @@ class V24 extends Filter public function parse(array $content, string $model): array { switch ($model) { - case 'organization.createProjectKey': + case 'project.createStandardKey': $content = $this->fillKeyId($content); $content = $this->parseKeyScopes($content); break; diff --git a/tests/e2e/Services/Organization/KeysBase.php b/tests/e2e/Services/Organization/KeysBase.php index 30a19ffaeb..ba4b996aaa 100644 --- a/tests/e2e/Services/Organization/KeysBase.php +++ b/tests/e2e/Services/Organization/KeysBase.php @@ -1043,75 +1043,13 @@ trait KeysBase $list = $this->client->call(Client::METHOD_GET, '/organization/projects/' . $siblingId . '/keys', $headers); $this->assertSame(401, $list['headers']['status-code']); - - $list = $this->client->call(Client::METHOD_GET, '/projects/' . $siblingId . '/keys', $headers); - - $this->assertSame(403, $list['headers']['status-code']); - $this->assertSame('project_id_missing', $list['body']['type']); + $this->assertSame('user_unauthorized', $list['body']['type']); // Cleanup $delete = $this->client->call(Client::METHOD_DELETE, '/projects/' . $siblingId, $this->getConsoleHeaders()); $this->assertSame(204, $delete['headers']['status-code']); } - public function testListKeysLegacyPaths(): void - { - $key = $this->createKey( - ID::unique(), - 'Legacy Path Key', - ['users.read'], - ); - $this->assertSame(201, $key['headers']['status-code']); - $keyId = $key['body']['$id']; - - $projectId = $this->getProject()['$id']; - - $projectHeaders = array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], $this->getHeaders()); - - /** - * Test for SUCCESS - /project/keys resolves the project from the request - */ - $list = $this->client->call(Client::METHOD_GET, '/project/keys', $projectHeaders); - - $this->assertSame(200, $list['headers']['status-code']); - $this->assertContains($keyId, \array_column($list['body']['keys'], '$id')); - - $get = $this->client->call(Client::METHOD_GET, '/project/keys/' . $keyId, $projectHeaders); - - $this->assertSame(200, $get['headers']['status-code']); - $this->assertSame('Legacy Path Key', $get['body']['name']); - - $ephemeral = $this->client->call(Client::METHOD_POST, '/project/keys/ephemeral', $projectHeaders, [ - 'scopes' => ['users.read'], - 'duration' => 900, - ]); - - $this->assertSame(201, $ephemeral['headers']['status-code']); - $this->assertStringStartsWith(API_KEY_EPHEMERAL . '_', $ephemeral['body']['secret']); - - /** - * Test for SUCCESS - /projects/:projectId/keys resolves the project from the path - */ - $list = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/keys', $this->getConsoleHeaders()); - - $this->assertSame(200, $list['headers']['status-code']); - $this->assertContains($keyId, \array_column($list['body']['keys'], '$id')); - - $jwt = $this->client->call(Client::METHOD_POST, '/projects/' . $projectId . '/jwts', $this->getConsoleHeaders(), [ - 'scopes' => ['users.read'], - 'duration' => 900, - ]); - - $this->assertSame(201, $jwt['headers']['status-code']); - $this->assertStringStartsWith(API_KEY_EPHEMERAL . '_', $jwt['body']['secret']); - - // Cleanup - $this->deleteKey($keyId); - } - // ========================================================================= // Helpers // ========================================================================= diff --git a/tests/e2e/Services/Project/KeysBase.php b/tests/e2e/Services/Project/KeysBase.php new file mode 100644 index 0000000000..da4f629267 --- /dev/null +++ b/tests/e2e/Services/Project/KeysBase.php @@ -0,0 +1,83 @@ + 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()); + + // Key creation is denied for key-authorized requests, so always use a console session + $consoleHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'origin' => 'http://localhost', + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'x-appwrite-mode' => 'admin', + ]; + + /** + * Test for SUCCESS + */ + $key = $this->client->call(Client::METHOD_POST, '/project/keys', $consoleHeaders, [ + 'keyId' => ID::unique(), + 'name' => 'Legacy Key', + 'scopes' => ['users.read'], + ]); + + $this->assertSame(201, $key['headers']['status-code']); + $this->assertNotEmpty($key['body']['secret']); + $keyId = $key['body']['$id']; + + $get = $this->client->call(Client::METHOD_GET, '/project/keys/' . $keyId, $projectHeaders); + + $this->assertSame(200, $get['headers']['status-code']); + $this->assertSame('Legacy Key', $get['body']['name']); + + $list = $this->client->call(Client::METHOD_GET, '/project/keys', $projectHeaders); + + $this->assertSame(200, $list['headers']['status-code']); + $this->assertContains($keyId, \array_column($list['body']['keys'], '$id')); + + $updated = $this->client->call(Client::METHOD_PUT, '/project/keys/' . $keyId, $projectHeaders, [ + 'name' => 'Legacy Key Updated', + 'scopes' => ['users.read', 'users.write'], + ]); + + $this->assertSame(200, $updated['headers']['status-code']); + $this->assertSame(['users.read', 'users.write'], $updated['body']['scopes']); + + $ephemeral = $this->client->call(Client::METHOD_POST, '/project/keys/ephemeral', $projectHeaders, [ + 'scopes' => ['users.read'], + 'duration' => 900, + ]); + + $this->assertSame(201, $ephemeral['headers']['status-code']); + $this->assertStringStartsWith(API_KEY_EPHEMERAL . '_', $ephemeral['body']['secret']); + + $delete = $this->client->call(Client::METHOD_DELETE, '/project/keys/' . $keyId, $projectHeaders); + + $this->assertSame(204, $delete['headers']['status-code']); + + /** + * Test for FAILURE + */ + $get = $this->client->call(Client::METHOD_GET, '/project/keys/' . $keyId, $projectHeaders); + + $this->assertSame(404, $get['headers']['status-code']); + $this->assertSame('key_not_found', $get['body']['type']); + } +} diff --git a/tests/e2e/Services/Project/KeysConsoleClientTest.php b/tests/e2e/Services/Project/KeysConsoleClientTest.php new file mode 100644 index 0000000000..43ce02fc72 --- /dev/null +++ b/tests/e2e/Services/Project/KeysConsoleClientTest.php @@ -0,0 +1,16 @@ +assertTrue($listPlatforms['emitDefault']); } - public function testClosureDefaultIsNotEmitted(): void - { - $projectId = $this->format->requestParameterConfig(true, false, fn () => 'resolved', 'organization.getProjectKey', 'projectId'); - - $this->assertFalse($projectId['required']); - $this->assertFalse($projectId['emitDefault']); - } - public function testProjectPlatformResponseTypeUsesSharedEnumMetadata(): void { $models = [ From ae6aa8c59db2ffd0c53660d433f7b83e8933f3fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 11 Sep 2026 11:23:20 +0200 Subject: [PATCH 3/7] test(organization): assert ephemeral keys by using them, not by decoding them Co-Authored-By: Claude Fable 5.1 --- tests/e2e/Services/Organization/KeysBase.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/e2e/Services/Organization/KeysBase.php b/tests/e2e/Services/Organization/KeysBase.php index ba4b996aaa..250723c975 100644 --- a/tests/e2e/Services/Organization/KeysBase.php +++ b/tests/e2e/Services/Organization/KeysBase.php @@ -304,13 +304,14 @@ trait KeysBase $this->assertSame(true, $dateValidator->isValid($key['body']['$updatedAt'])); $this->assertSame(true, $dateValidator->isValid($key['body']['expire'])); - // Verify JWT payload - $jwt = substr($key['body']['secret'], strlen(API_KEY_EPHEMERAL . '_')); - $parts = explode('.', $jwt); - $this->assertCount(3, $parts); - $payload = json_decode(base64_decode(str_replace(['-', '_'], ['+', '/'], $parts[1])), true); - $this->assertNotEmpty($payload['projectId']); - $this->assertSame(['users.read', 'users.write'], $payload['scopes']); + // The key authenticates requests against the project it was issued for + $users = $this->client->call(Client::METHOD_GET, '/users', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $key['body']['secret'], + ]); + + $this->assertSame(200, $users['headers']['status-code']); $expireDt = new \DateTime($key['body']['expire']); $now = new \DateTime(); From 7f443ef6fe0bd202e857d91bfa1e01e75c1fb961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 11 Sep 2026 11:25:30 +0200 Subject: [PATCH 4/7] fix(organization): attribute key events and audits to the resolved project Organization requests run through the console project, so the event queue and audit context start out pointing at console. Re-point both at the project named in the route before recording key changes. Co-Authored-By: Claude Fable 5.1 --- .../Modules/Organization/Http/Projects/Keys/Create.php | 6 ++++++ .../Modules/Organization/Http/Projects/Keys/Delete.php | 6 ++++++ .../Organization/Http/Projects/Keys/Ephemeral/Create.php | 6 ++++++ .../Modules/Organization/Http/Projects/Keys/Update.php | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Create.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Create.php index 74e2401167..5e546a9e12 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Create.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Create.php @@ -3,6 +3,7 @@ namespace Appwrite\Platform\Modules\Organization\Http\Projects\Keys; use Appwrite\Auth\Key; +use Appwrite\Event\Context\Audit as AuditContext; use Appwrite\Event\Event as QueueEvent; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; @@ -73,6 +74,7 @@ class Create extends Action ->inject('team') ->inject('authorization') ->inject('apiKey') + ->inject('auditContext') ->callback($this->action(...)); } @@ -88,6 +90,7 @@ class Create extends Action Document $team, Authorization $authorization, ?Key $apiKey, + AuditContext $auditContext, ) { // Dynamic supported for backwards compatibility if ($apiKey !== null && \in_array($apiKey->getType(), [API_KEY_STANDARD, API_KEY_EPHEMERAL, 'dynamic'], true)) { @@ -96,6 +99,9 @@ class Create extends Action $project = $this->getProject($projectId, $team, $dbForPlatform, $apiKey); + // The request may run through the console project; events and audits belong to the resolved project + $queueForEvents->setProject($project); + $auditContext->project = $project; $keyId = ($keyId == 'unique()') ? ID::unique() : $keyId; $key = new Document([ diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Delete.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Delete.php index f53b40b614..8c73554d0d 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Delete.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Delete.php @@ -3,6 +3,7 @@ namespace Appwrite\Platform\Modules\Organization\Http\Projects\Keys; use Appwrite\Auth\Key; +use Appwrite\Event\Context\Audit as AuditContext; use Appwrite\Event\Event; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; @@ -60,6 +61,7 @@ class Delete extends Action ->inject('team') ->inject('authorization') ->inject('apiKey') + ->inject('auditContext') ->callback($this->action(...)); } @@ -72,9 +74,13 @@ class Delete extends Action Document $team, Authorization $authorization, ?Key $apiKey, + AuditContext $auditContext, ) { $project = $this->getProject($projectId, $team, $dbForPlatform, $apiKey); + // The request may run through the console project; events and audits belong to the resolved project + $queueForEvents->setProject($project); + $auditContext->project = $project; $key = $authorization->skip(fn () => $dbForPlatform->getDocument('keys', $keyId)); if ($key->isEmpty() || $key->getAttribute('resourceType', '') !== 'projects' || $key->getAttribute('resourceInternalId', '') !== $project->getSequence()) { diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Ephemeral/Create.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Ephemeral/Create.php index a043dbeef0..b2b3e53e70 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Ephemeral/Create.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Ephemeral/Create.php @@ -4,6 +4,7 @@ namespace Appwrite\Platform\Modules\Organization\Http\Projects\Keys\Ephemeral; use Ahc\Jwt\JWT; use Appwrite\Auth\Key; +use Appwrite\Event\Context\Audit as AuditContext; use Appwrite\Event\Event as QueueEvent; use Appwrite\Platform\Modules\Organization\Http\Projects\Keys\Action; use Appwrite\SDK\AuthType; @@ -68,6 +69,7 @@ class Create extends Action ->inject('dbForPlatform') ->inject('team') ->inject('apiKey') + ->inject('auditContext') ->callback($this->action(...)); } @@ -80,9 +82,13 @@ class Create extends Action Database $dbForPlatform, Document $team, ?Key $apiKey, + AuditContext $auditContext, ) { $project = $this->getProject($projectId, $team, $dbForPlatform, $apiKey); + // The request may run through the console project; events and audits belong to the resolved project + $queueForEvents->setProject($project); + $auditContext->project = $project; $keyId = ID::unique(); $jwt = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', $duration, 0); diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Update.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Update.php index 143d590580..4fb8e1e830 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Update.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Update.php @@ -3,6 +3,7 @@ namespace Appwrite\Platform\Modules\Organization\Http\Projects\Keys; use Appwrite\Auth\Key; +use Appwrite\Event\Context\Audit as AuditContext; use Appwrite\Event\Event as QueueEvent; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; @@ -69,6 +70,7 @@ class Update extends Action ->inject('team') ->inject('authorization') ->inject('apiKey') + ->inject('auditContext') ->callback($this->action(...)); } @@ -84,9 +86,13 @@ class Update extends Action Document $team, Authorization $authorization, ?Key $apiKey, + AuditContext $auditContext, ) { $project = $this->getProject($projectId, $team, $dbForPlatform, $apiKey); + // The request may run through the console project; events and audits belong to the resolved project + $queueForEvents->setProject($project); + $auditContext->project = $project; $key = $authorization->skip(fn () => $dbForPlatform->getDocument('keys', $keyId)); if ($key->isEmpty() || $key->getAttribute('resourceType', '') !== 'projects' || $key->getAttribute('resourceInternalId', '') !== $project->getSequence()) { From 1851993aa92196c614e13ff71b29a889ab0c311e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 11 Sep 2026 11:32:53 +0200 Subject: [PATCH 5/7] chore(scopes): mark project key scopes for removal after the Organization API migration Co-Authored-By: Claude Fable 5.1 --- app/config/scopes/project.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/config/scopes/project.php b/app/config/scopes/project.php index 941e236660..4739f91ed6 100644 --- a/app/config/scopes/project.php +++ b/app/config/scopes/project.php @@ -17,6 +17,8 @@ return [ 'description' => 'Access to read project usage metrics', 'category' => 'Project', ], + // TODO: Remove keys.read and keys.write from project key scopes once the Console, CLI and SDKs + // manage project keys through the Organization API (organization.projects.keys.*) "keys.read" => [ "description" => "Access to read project\'s keys", From 66b15c19ce64ac83b8db3c3931be86ffe64dd963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 11 Sep 2026 11:32:45 +0200 Subject: [PATCH 6/7] feat(organization): add detailed scopes for project key management Organization key routes now accept organization.projects.keys.read and organization.projects.keys.write alongside the legacy keys.read and keys.write scopes. The new scopes are listed for organization API keys and granted to console admin roles. Co-Authored-By: Claude Fable 5.1 --- app/config/roles.php | 2 ++ app/config/scopes/organization.php | 9 +++++++++ .../Modules/Organization/Http/Projects/Keys/Create.php | 2 +- .../Modules/Organization/Http/Projects/Keys/Delete.php | 2 +- .../Organization/Http/Projects/Keys/Ephemeral/Create.php | 2 +- .../Modules/Organization/Http/Projects/Keys/Get.php | 2 +- .../Modules/Organization/Http/Projects/Keys/Update.php | 2 +- .../Modules/Organization/Http/Projects/Keys/XList.php | 2 +- tests/e2e/Services/Console/ConsoleConsoleClientTest.php | 2 ++ tests/e2e/Services/Console/ConsoleCustomServerTest.php | 2 ++ 10 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/config/roles.php b/app/config/roles.php index fe952b59bd..d3394b05cf 100644 --- a/app/config/roles.php +++ b/app/config/roles.php @@ -92,6 +92,8 @@ $admins = [ 'projects.write', 'keys.read', 'keys.write', + 'organization.projects.keys.read', + 'organization.projects.keys.write', 'devKeys.read', 'devKeys.write', 'webhooks.read', diff --git a/app/config/scopes/organization.php b/app/config/scopes/organization.php index d74452f259..0a85dee1b0 100644 --- a/app/config/scopes/organization.php +++ b/app/config/scopes/organization.php @@ -12,6 +12,15 @@ return [ "Access to create, update, and delete organization projects", "category" => "Projects", ], + "organization.projects.keys.read" => [ + "description" => 'Access to read organization projects\' API keys', + "category" => "Projects", + ], + "organization.projects.keys.write" => [ + "description" => + "Access to create, update, and delete organization projects' API keys", + "category" => "Projects", + ], "devKeys.read" => [ "description" => 'Access to read project\'s development keys', "category" => "Other", diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Create.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Create.php index 5e546a9e12..dbef9c87cc 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Create.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Create.php @@ -42,7 +42,7 @@ class Create extends Action ->setHttpPath('/v1/organization/projects/:projectId/keys') ->desc('Create project key') ->groups(['api', 'organization']) - ->label('scope', 'keys.write') + ->label('scope', ['organization.projects.keys.write', 'keys.write']) ->label('event', 'keys.[keyId].create') ->label('audits.event', 'project.key.create') ->label('audits.resource', 'project.key/{response.$id}') diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Delete.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Delete.php index 8c73554d0d..122e09b7f7 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Delete.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Delete.php @@ -33,7 +33,7 @@ class Delete extends Action ->setHttpPath('/v1/organization/projects/:projectId/keys/:keyId') ->desc('Delete project key') ->groups(['api', 'organization']) - ->label('scope', 'keys.write') + ->label('scope', ['organization.projects.keys.write', 'keys.write']) ->label('event', 'keys.[keyId].delete') ->label('audits.event', 'project.key.delete') ->label('audits.resource', 'project.key/{request.keyId}') diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Ephemeral/Create.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Ephemeral/Create.php index b2b3e53e70..c88ac87aa3 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Ephemeral/Create.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Ephemeral/Create.php @@ -40,7 +40,7 @@ class Create extends Action ->setHttpPath('/v1/organization/projects/:projectId/keys/ephemeral') ->desc('Create ephemeral project key') ->groups(['api', 'organization']) - ->label('scope', 'keys.write') + ->label('scope', ['organization.projects.keys.write', 'keys.write']) ->label('event', 'keys.[keyId].create') ->label('audits.event', 'project.key.create') ->label('audits.resource', 'project.key/{response.$id}') diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Get.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Get.php index 70caad8587..015bd72687 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Get.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Get.php @@ -30,7 +30,7 @@ class Get extends Action ->setHttpPath('/v1/organization/projects/:projectId/keys/:keyId') ->desc('Get project key') ->groups(['api', 'organization']) - ->label('scope', 'keys.read') + ->label('scope', ['organization.projects.keys.read', 'keys.read']) ->label('sdk', new Method( namespace: 'organization', group: 'keys', diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Update.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Update.php index 4fb8e1e830..00b9abb46f 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Update.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Update.php @@ -40,7 +40,7 @@ class Update extends Action ->setHttpPath('/v1/organization/projects/:projectId/keys/:keyId') ->desc('Update project key') ->groups(['api', 'organization']) - ->label('scope', 'keys.write') + ->label('scope', ['organization.projects.keys.write', 'keys.write']) ->label('event', 'keys.[keyId].update') ->label('audits.event', 'project.key.update') ->label('audits.resource', 'project.key/{response.$id}') diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/XList.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/XList.php index 2ec6b484a3..71e3a213dd 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/XList.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/XList.php @@ -36,7 +36,7 @@ class XList extends Action ->setHttpPath('/v1/organization/projects/:projectId/keys') ->desc('List project keys') ->groups(['api', 'organization']) - ->label('scope', 'keys.read') + ->label('scope', ['organization.projects.keys.read', 'keys.read']) ->label('sdk', new Method( namespace: 'organization', group: 'keys', diff --git a/tests/e2e/Services/Console/ConsoleConsoleClientTest.php b/tests/e2e/Services/Console/ConsoleConsoleClientTest.php index 802cb4bea7..597256be7c 100644 --- a/tests/e2e/Services/Console/ConsoleConsoleClientTest.php +++ b/tests/e2e/Services/Console/ConsoleConsoleClientTest.php @@ -196,6 +196,8 @@ final class ConsoleConsoleClientTest extends Scope // Well-known scopes must be present $this->assertContains('projects.read', $scopeIds); $this->assertContains('projects.write', $scopeIds); + $this->assertContains('organization.projects.keys.read', $scopeIds); + $this->assertContains('organization.projects.keys.write', $scopeIds); // Every scope has the expected shape foreach ($response['body']['scopes'] as $scope) { diff --git a/tests/e2e/Services/Console/ConsoleCustomServerTest.php b/tests/e2e/Services/Console/ConsoleCustomServerTest.php index b3adc2b940..98550ccc3a 100644 --- a/tests/e2e/Services/Console/ConsoleCustomServerTest.php +++ b/tests/e2e/Services/Console/ConsoleCustomServerTest.php @@ -93,6 +93,8 @@ final class ConsoleCustomServerTest extends Scope $scopeIds = \array_column($response['body']['scopes'], '$id'); $this->assertContains('projects.read', $scopeIds); + $this->assertContains('organization.projects.keys.read', $scopeIds); + $this->assertContains('organization.projects.keys.write', $scopeIds); $projectsRead = null; foreach ($response['body']['scopes'] as $scope) { From 55909b2be4951d30ca05ca7c687ef88ea09d36d9 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 11 Sep 2026 19:11:30 +0100 Subject: [PATCH 7/7] chore: bump utopia-php/queue to 2.2.4 Picks up the Swoole adapter fix where each handler process still received one more message after SIGTERM. The stop flag is now re-checked once the concurrency slot is held, so a rolling restart drains only the jobs that were in flight when the signal arrived. Co-Authored-By: Claude Fable 5.1 --- composer.json | 2 +- composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 8cd6a8178c..cc5bd749a5 100644 --- a/composer.json +++ b/composer.json @@ -96,7 +96,7 @@ "utopia-php/platform": "1.0.0-rc20", "utopia-php/pools": "2.*", "utopia-php/span": "^4.2", - "utopia-php/queue": "^2.2.3", + "utopia-php/queue": "^2.2.4", "utopia-php/servers": "0.4.*", "utopia-php/registry": "0.5.*", "utopia-php/storage": "^4.0", diff --git a/composer.lock b/composer.lock index bc78c7ddae..4029210f89 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "179b6295c070315f1d35007e2da5867d", + "content-hash": "c3061710f7b567210d14fb97e6744ef9", "packages": [ { "name": "adhocore/jwt", @@ -4484,16 +4484,16 @@ }, { "name": "utopia-php/queue", - "version": "2.2.3", + "version": "2.2.4", "source": { "type": "git", "url": "https://github.com/utopia-php/queue.git", - "reference": "9474bc419fef9680a60ebd7d6773b730402d7446" + "reference": "c6994fe68c58d48f303693dad2762d1f80d5bf97" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/queue/zipball/9474bc419fef9680a60ebd7d6773b730402d7446", - "reference": "9474bc419fef9680a60ebd7d6773b730402d7446", + "url": "https://api.github.com/repos/utopia-php/queue/zipball/c6994fe68c58d48f303693dad2762d1f80d5bf97", + "reference": "c6994fe68c58d48f303693dad2762d1f80d5bf97", "shasum": "" }, "require": { @@ -4544,9 +4544,9 @@ ], "support": { "issues": "https://github.com/utopia-php/queue/issues", - "source": "https://github.com/utopia-php/queue/tree/2.2.3" + "source": "https://github.com/utopia-php/queue/tree/2.2.4" }, - "time": "2026-09-11T10:05:23+00:00" + "time": "2026-09-11T17:50:20+00:00" }, { "name": "utopia-php/registry",