diff --git a/.agents/skills/self-hosted-release/SKILL.md b/.agents/skills/self-hosted-release/SKILL.md index 989b8f4c1a..b4d955c104 100644 --- a/.agents/skills/self-hosted-release/SKILL.md +++ b/.agents/skills/self-hosted-release/SKILL.md @@ -41,7 +41,7 @@ Build and run the target release with the local Docker Compose stack, then test docker compose down -v docker compose up -d --force-recreate --build --wait docker compose exec -T appwrite vars -curl -fsS http://localhost/v1/health/version +curl -fsS http://localhost:9520/v1/health/version ``` 2. Inspect runtime health before running tests: diff --git a/.env b/.env index 900c0e78c5..dc2bc60763 100644 --- a/.env +++ b/.env @@ -107,6 +107,7 @@ _APP_COMPUTE_MEMORY=8192 _APP_COMPUTE_INACTIVE_THRESHOLD=600 _APP_COMPUTE_MAINTENANCE_INTERVAL=600 _APP_COMPUTE_RUNTIMES_NETWORK=runtimes +_APP_OPEN_RUNTIMES_NFT=enabled _APP_FUNCTIONS_RUNTIMES=node-22 _APP_FUNCTIONS_TIMEOUT=900 _APP_FUNCTIONS_CREATION_ABUSE_LIMIT=5000 diff --git a/.github/workflows/benchmark-comment.js b/.github/workflows/benchmark-comment.js index f25116c4f2..bdb0055c60 100644 --- a/.github/workflows/benchmark-comment.js +++ b/.github/workflows/benchmark-comment.js @@ -51,42 +51,37 @@ function buildComment(core) { const baseRef = markdownText(process.env.BENCHMARK_BASE_REF || 'base'); const headRef = markdownText(process.env.BENCHMARK_HEAD_REF || 'head'); const rows = benchmarkRows(before, after, beforeSamples, afterSamples); - const topWaits = topSamples(afterSamples, 'appwrite_api_waiting', 3); + const total = rows[0]; + const topWaits = topSamples(afterSamples, 'appwrite_api_waiting', 5); const lines = [ marker, '## :sparkles: Benchmark results', '', - `Comparing ${baseRef} (before) to ${headRef} (after).`, + `Comparing \`${baseRef}\` (before) → \`${headRef}\` (after).`, '', ]; if (before === null) { - lines.push('> Before benchmark did not complete; showing current branch metrics only.', ''); + lines.push('> :warning: Before benchmark did not complete — change column unavailable.', ''); } if (after === null) { - lines.push('> Current branch benchmark did not complete; showing available metrics only.', ''); + lines.push('> :warning: Current branch benchmark did not complete — showing available metrics only.', ''); } lines.push( - '**Before**', - '', - metricTable(rows, 'before'), - '', - '**After**', - '', - metricTable(rows, 'after'), - '', - '**Delta**', - '', - '| Scenario | P95 delta (ms) |', - '| --- | ---: |', - ...rows.map(deltaRow), + ...headlineTable(total), '', '
', - 'Top API waits', + 'Per-scenario breakdown & investigation details', '', '
', '', + '_Metrics below reflect the current branch (after). Δ P95 compares against the base._', + '', + detailTable(rows), + '', + '**Top API waits (after)**', + '', '| API request | Max wait (ms) |', '| --- | ---: |', ...topWaitRows(topWaits), @@ -97,6 +92,46 @@ function buildComment(core) { return `${lines.join('\n')}\n`; } +function headlineTable(total) { + const { before, after } = total; + return [ + '| Metric | Before | After | Change |', + '| --- | ---: | ---: | :--- |', + `| :rocket: Requests/sec | ${formatRate(before?.rps)} | ${formatRate(after?.rps)} | ${changeCell(before?.rps, after?.rps, false)} |`, + `| :stopwatch: Latency P50 | ${formatMsUnit(before?.p50)} | ${formatMsUnit(after?.p50)} | ${changeCell(before?.p50, after?.p50, true)} |`, + `| :stopwatch: Latency P95 | ${formatMsUnit(before?.p95)} | ${formatMsUnit(after?.p95)} | ${changeCell(before?.p95, after?.p95, true)} |`, + ]; +} + +function changeCell(before, after, lowerIsBetter) { + if (before === null || before === undefined || after === null || after === undefined || Number.isNaN(before) || Number.isNaN(after) || before === 0) { + return 'n/a'; + } + + const percent = Number((((after - before) / before) * 100).toFixed(1)); + const label = code(`${percent > 0 ? '+' : ''}${trimNumber(percent)}%`); + + if (Math.abs(percent) <= 5) { + return `:white_circle: ${label}`; + } + + const improved = lowerIsBetter ? percent < 0 : percent > 0; + return `${improved ? ':green_circle:' : ':red_circle:'} ${label}`; +} + +function detailTable(rows) { + return [ + '| Scenario | P50 (ms) | P95 (ms) | Requests | RPS | Δ P95 (ms) |', + '| --- | ---: | ---: | ---: | ---: | ---: |', + ...rows.map(detailRow), + ].join('\n'); +} + +function detailRow(row) { + const values = row.after; + return `| ${row.label} | ${formatMs(values?.p50)} | ${formatMs(values?.p95)} | ${formatCount(values?.iterations)} | ${formatRate(values?.rps)} | ${formatDelta(row.before?.p95, row.after?.p95)} |`; +} + function readSummary(path, core) { if (!fs.existsSync(path)) { return null; @@ -256,23 +291,6 @@ function metricValue(data, metric, stat) { return metricValues(data, metric)?.[stat] ?? null; } -function metricTable(rows, side) { - return [ - '| Scenario | P50 (ms) | P95 (ms) | Requests | RPS |', - '| --- | ---: | ---: | ---: | ---: |', - ...rows.map((row) => metricRow(row, side)), - ].join('\n'); -} - -function metricRow(row, side) { - const values = row[side]; - return `| ${row.label} | ${formatMs(values?.p50)} | ${formatMs(values?.p95)} | ${formatCount(values?.iterations)} | ${formatRate(values?.rps)} |`; -} - -function deltaRow(row) { - return `| ${row.label} | ${formatDelta(row.before?.p95, row.after?.p95)} |`; -} - function topSamples(samples, metric, limit) { const byName = samples.reduce((result, sample) => { if (sample.metric !== metric || typeof sample.data?.value !== 'number') { @@ -310,11 +328,16 @@ function markdownText(value) { } function formatMs(value) { - return formatNumber(value, 2); + return code(formatNumber(value, 2)); +} + +function formatMsUnit(value) { + const formatted = formatNumber(value, 2); + return formatted === 'n/a' ? formatted : code(`${formatted} ms`); } function formatRate(value) { - return formatNumber(value, 2); + return code(formatNumber(value, 2)); } function formatCount(value) { @@ -322,7 +345,7 @@ function formatCount(value) { return 'n/a'; } - return `${Math.round(value)}`; + return code(Math.round(value).toLocaleString('en-US')); } function formatDelta(before, after) { @@ -331,7 +354,8 @@ function formatDelta(before, after) { } const difference = Number((after - before).toFixed(2)); - return `${difference > 0 ? '+' : ''}${trimNumber(difference)}`; + const sign = difference > 0 ? '+' : difference < 0 ? '-' : ''; + return code(`${sign}${formatNumber(Math.abs(difference), 2)}`); } function formatNumber(value, decimals) { @@ -339,7 +363,14 @@ function formatNumber(value, decimals) { return 'n/a'; } - return trimNumber(Number(value).toFixed(decimals)); + return trimNumber(Number(value).toLocaleString('en-US', { + minimumFractionDigits: decimals, + maximumFractionDigits: decimals, + })); +} + +function code(text) { + return text === 'n/a' ? text : `\`${text}\``; } function trimNumber(value) { diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c734df8e9..e3883e1838 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' }} env: - COMPOSE_FILE: docker-compose.yml + COMPOSE_FILE: docker-compose.yml:docker-compose.override.yml IMAGE: appwrite-dev K6_VERSION: '0.53.0' @@ -13,6 +13,7 @@ on: pull_request: push: branches: + - main - 1.9.x workflow_dispatch: inputs: @@ -106,6 +107,11 @@ jobs: tools: composer:v2 coverage: none + - name: Setup Node + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + with: + node-version: '24' + - name: Validate composer.json run: composer validate @@ -113,6 +119,10 @@ jobs: id: install run: composer install --prefer-dist --no-progress --ignore-platform-reqs + - name: Install Node dependencies + if: ${{ !cancelled() && steps.install.outcome == 'success' }} + run: npm ci + - name: Cache PHPStan result cache if: ${{ !cancelled() && steps.install.outcome == 'success' }} uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 @@ -132,6 +142,10 @@ jobs: if: ${{ !cancelled() && steps.install.outcome == 'success' }} run: composer lint + - name: Check Docker Compose formatting + if: ${{ !cancelled() && steps.install.outcome == 'success' }} + run: npm run lint:compose + - name: Run Rector if: ${{ !cancelled() && steps.install.outcome == 'success' }} run: composer refactor:check @@ -667,7 +681,7 @@ jobs: docker tag ${{ env.IMAGE }}:before ${{ env.IMAGE }} docker compose up -d --wait --no-build for attempt in $(seq 1 10); do - if curl -fsS http://localhost/v1/health/version; then + if curl -fsS http://localhost:9520/v1/health/version; then break fi if [ "$attempt" -eq 10 ]; then @@ -684,9 +698,9 @@ jobs: continue-on-error: true uses: grafana/run-k6-action@de51a7390bdf0ac85a3bef493691bd71d4c7c158 # v1.4.0 env: - APPWRITE_ENDPOINT: 'http://localhost/v1' - APPWRITE_BENCHMARK_ITERATIONS: '5' - APPWRITE_BENCHMARK_VUS: '1' + APPWRITE_ENDPOINT: 'http://localhost:9520/v1' + APPWRITE_BENCHMARK_DURATION: '1m' + APPWRITE_BENCHMARK_VUS: '20' APPWRITE_WORKER_TIMEOUT_MS: '120000' APPWRITE_BENCHMARK_SUMMARY_PATH: 'benchmark-before-summary.json' with: @@ -706,7 +720,7 @@ jobs: - name: Wait for benchmark ports if: always() run: | - for port in 80 443 8080 9503; do + for port in 9520 9521 9522 9503; do for attempt in $(seq 1 30); do if ! ss -ltn | awk '{print $4}' | grep -Eq "[:.]${port}$"; then break @@ -731,7 +745,7 @@ jobs: docker tag ${{ env.IMAGE }}:after ${{ env.IMAGE }} docker compose up -d --wait --no-build for attempt in $(seq 1 10); do - if curl -fsS http://localhost/v1/health/version; then + if curl -fsS http://localhost:9520/v1/health/version; then break fi if [ "$attempt" -eq 10 ]; then @@ -745,9 +759,9 @@ jobs: continue-on-error: true uses: grafana/run-k6-action@de51a7390bdf0ac85a3bef493691bd71d4c7c158 # v1.4.0 env: - APPWRITE_ENDPOINT: 'http://localhost/v1' - APPWRITE_BENCHMARK_ITERATIONS: '5' - APPWRITE_BENCHMARK_VUS: '1' + APPWRITE_ENDPOINT: 'http://localhost:9520/v1' + APPWRITE_BENCHMARK_DURATION: '1m' + APPWRITE_BENCHMARK_VUS: '20' APPWRITE_WORKER_TIMEOUT_MS: '120000' APPWRITE_BENCHMARK_PREVIOUS_SUMMARY_PATH: '../../benchmark-before-summary.json' APPWRITE_BENCHMARK_SUMMARY_PATH: 'benchmark-after-summary.json' diff --git a/.github/workflows/sdk-preview.yml b/.github/workflows/sdk-preview.yml index dacc37a64a..535b3712f6 100644 --- a/.github/workflows/sdk-preview.yml +++ b/.github/workflows/sdk-preview.yml @@ -1,7 +1,7 @@ name: "SDK Preview" env: - COMPOSE_FILE: docker-compose.yml + COMPOSE_FILE: docker-compose.yml:docker-compose.override.yml on: workflow_dispatch: diff --git a/.github/workflows/specs.yml b/.github/workflows/specs.yml index 85c76bacd3..50a70bd4bb 100644 --- a/.github/workflows/specs.yml +++ b/.github/workflows/specs.yml @@ -1,7 +1,7 @@ name: "Generate Specs" env: - COMPOSE_FILE: docker-compose.yml + COMPOSE_FILE: docker-compose.yml:docker-compose.override.yml on: workflow_dispatch: diff --git a/.gitpod.yml b/.gitpod.yml index 78375bb1f0..82130fa32d 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -17,7 +17,7 @@ tasks: --prefer-dist ports: - - port: 8080 + - port: 9520 visibility: public vscode: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5d7ab96a4f..9dd25edc27 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -281,11 +281,34 @@ Although the Appwrite API is a monolithic app, it has a very clear separation of Each container in Appwrite is a microservice on its own. Each service is an independent process that can scale without regard to any of the other services. -Currently, all the Appwrite microservices are intended to communicate using the TCP protocol over a private network. With the exception of the public-facing port 80 and 443, which by default are used to expose the Appwrite HTTP API, you should **avoid exposing any other services' ports**. +Currently, all the Appwrite microservices are intended to communicate using the TCP protocol over a private network. You should **avoid exposing services' ports** beyond what is needed for local development and debugging. ## Ports -Appwrite dev version uses ports 80 and 443 as an entry point to the Appwrite API and console. We also expose multiple ports in the range of 9500-9504 for debugging some of the Appwrite containers on dev mode. If you have any conflicts with the ports running on your system, you can easily replace them by editing Appwrite's docker-compose.yml file and executing `docker compose up -d` command. +Appwrite server dev publishes all host ports in the **9500–9522** range so the stack can run alongside other local services (including Appwrite Cloud on **9600–9699**). Access the API and console at `http://localhost:9520` (or `https://localhost:9521`). + +| Host port | Service | +|-----------|---------| +| 9520 | Traefik HTTP (API, console, dev hostnames) | +| 9521 | Traefik HTTPS | +| 9522 | Traefik HTTP (alt) | +| 9500 | Traefik dashboard | +| 9501 | Appwrite API only (direct; no console) | +| 9502 | Realtime only (direct; no console) | +| 9503 | Mail catcher | +| 9504 | Request catcher (webhook) | +| 9505 | Embedding | +| 9506 | Adminer | +| 9507 | Request catcher (SMS) | +| 9508 | Mongo Express | +| 9509 | GraphQL explorer | +| 9510 | MariaDB | +| 9511 | MongoDB | +| 9512 | PostgreSQL | +| 9513 | Redis | +| 9514 | Redis Insight | + +Containers still talk to each other on the internal Docker network using standard service ports (for example, `mariadb:3306`). The table above is only for connections from your host machine. If you still have a conflict, change the host side in `docker-compose.yml` or `docker-compose.override.yml` and run `docker compose up -d`. ## Technology Stack diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php index 7496b7a9a7..f93d82456e 100644 --- a/app/config/collections/platform.php +++ b/app/config/collections/platform.php @@ -342,6 +342,17 @@ $platformCollections = [ 'array' => true, 'filters' => [], ], + [ + '$id' => ID::custom('onboarding'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 65536, + 'signed' => true, + 'required' => false, + 'default' => [], + 'array' => false, + 'filters' => ['json'], + ], [ '$id' => 'status', 'type' => Database::VAR_STRING, diff --git a/app/config/onboarding.php b/app/config/onboarding.php new file mode 100644 index 0000000000..014301a72e --- /dev/null +++ b/app/config/onboarding.php @@ -0,0 +1,76 @@ + true, + 'project.createAndroidPlatform' => true, + 'project.createApplePlatform' => true, + 'project.createWindowsPlatform' => true, + 'project.createLinuxPlatform' => true, + // Connect — API key + 'project.createKey' => true, + + // Auth + 'users.create' => true, + 'account.create' => true, + 'account.createAnonymousSession' => true, + 'teams.create' => true, + + // Databases — tablesDB + 'tablesDB.create' => true, + 'tablesDB.createTable' => true, + 'tablesDB.createRow' => true, + // Databases — documentsDB + 'documentsDB.create' => true, + 'documentsDB.createCollection' => true, + 'documentsDB.createDocument' => true, + // Databases — legacy + 'databases.create' => true, + 'databases.createCollection' => true, + 'databases.createDocument' => true, + + // Storage + 'storage.createBucket' => true, + 'storage.createFile' => true, + + // Functions + 'functions.create' => true, + // Deployment-creation SDK methods; OR them in the UI for a single + // "created a deployment" milestone. + 'functions.createDeployment' => true, + 'functions.createTemplateDeployment' => true, + 'functions.createVcsDeployment' => true, + 'functions.updateFunctionDeployment' => true, + + // Messaging + 'messaging.createTopic' => true, + 'messaging.createMailgunProvider' => true, + 'messaging.createSendgridProvider' => true, + 'messaging.createSesProvider' => true, + 'messaging.createResendProvider' => true, + 'messaging.createSmtpProvider' => true, + 'messaging.createSMTPProvider' => true, + 'messaging.createMsg91Provider' => true, + 'messaging.createTelesignProvider' => true, + 'messaging.createTextmagicProvider' => true, + 'messaging.createTwilioProvider' => true, + 'messaging.createVonageProvider' => true, + 'messaging.createFcmProvider' => true, + 'messaging.createFCMProvider' => true, + 'messaging.createApnsProvider' => true, + 'messaging.createAPNSProvider' => true, + + // Sites + 'sites.create' => true, + // Deployment-creation SDK methods; OR them in the UI for a single + // "created a deployment" milestone. + 'sites.createDeployment' => true, + 'sites.createTemplateDeployment' => true, + 'sites.createVcsDeployment' => true, + 'sites.updateSiteDeployment' => true, +]; diff --git a/app/config/roles.php b/app/config/roles.php index d5ae7c1331..04718f65d2 100644 --- a/app/config/roles.php +++ b/app/config/roles.php @@ -107,6 +107,8 @@ $admins = [ 'tokens.write', 'schedules.read', 'schedules.write', + 'stages.read', + 'stages.write', 'insights.read', 'insights.write', 'reports.read', diff --git a/app/config/scopes/project.php b/app/config/scopes/project.php index cd50abd57b..bfafebb5fb 100644 --- a/app/config/scopes/project.php +++ b/app/config/scopes/project.php @@ -75,6 +75,16 @@ return [ "Access to create, update, and delete project\'s templates", "category" => "Project", ], + "stages.read" => [ + "description" => + "Access to read project\'s stages", + "category" => "Project", + ], + "stages.write" => [ + "description" => + "Access to update project\'s stages", + "category" => "Project", + ], "oauth2.read" => [ "description" => "Access to read project\'s OAuth2 configuration", diff --git a/app/config/sdks.php b/app/config/sdks.php index f3d89db3c2..8d128cfe0c 100644 --- a/app/config/sdks.php +++ b/app/config/sdks.php @@ -95,24 +95,6 @@ return [ 'gitBranch' => 'dev', 'changelog' => \realpath(__DIR__ . '/../../docs/sdks/apple/CHANGELOG.md'), ], - [ - 'key' => 'objective-c', - 'name' => 'Objective C', - 'url' => '', - 'package' => '', - 'enabled' => false, - 'beta' => false, - 'dev' => false, - 'hidden' => false, - 'family' => APP_SDK_PLATFORM_CLIENT, - 'prism' => '', - 'source' => false, - 'gitUrl' => 'git@github.com:appwrite/sdk-for-objective-c.git', - 'gitRepoName' => 'sdk-for-objective-c', - 'gitUserName' => 'appwrite', - 'gitBranch' => 'dev', - 'changelog' => \realpath(__DIR__ . '/../../docs/sdks/objective-c/CHANGELOG.md'), - ], [ 'key' => 'android', 'name' => 'Android', diff --git a/app/config/variables.php b/app/config/variables.php index 90df9b4518..b77d841aaf 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -1070,6 +1070,15 @@ return [ 'question' => '', 'filter' => '' ], + [ + 'name' => '_APP_OPEN_RUNTIMES_NFT', + 'description' => 'Enables dependency tracing for Open Runtimes build artifacts. When enabled, supported SSR site builds prune unused node_modules files before packaging the build output.', + 'introduction' => '1.9.0', + 'default' => 'enabled', + 'required' => false, + 'question' => '', + 'filter' => '' + ], [ 'name' => '_APP_DOCKER_HUB_USERNAME', 'description' => 'The username for hub.docker.com. This variable is used to pull images from hub.docker.com.', diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index a39ce3c4bd..a9eec75f8b 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -64,6 +64,8 @@ Http::patch('/v1/projects/:projectId/oauth2') ])); }); + $dbForPlatform->purgeCachedDocument('projects', $project->getId()); + $response->dynamic($project, Response::MODEL_PROJECT); }); diff --git a/app/controllers/general.php b/app/controllers/general.php index 9ff704ca20..1a7cfa70ae 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -988,7 +988,7 @@ Http::init() * @see https://www.owasp.org/index.php/List_of_useful_HTTP_headers */ Http::init() - ->groups(['api', 'web']) + ->groups(['api', 'web', 'graphql']) ->inject('request') ->inject('response') ->inject('cors') diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 9387eaed17..5ef8eb5021 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -18,11 +18,13 @@ use Appwrite\Extend\Exception as AppwriteException; use Appwrite\Functions\EventProcessor; use Appwrite\Platform\Modules\Storage\Config\CacheControl; use Appwrite\Platform\Modules\Storage\Config\StorageCacheControl; +use Appwrite\Reference\Renderer; use Appwrite\SDK\Method; use Appwrite\Usage\Context; use Appwrite\Utopia\Database\Documents\User; use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; +use Throwable; use Utopia\Abuse\Abuse; use Utopia\Bus\Bus; use Utopia\Cache\Adapter\Filesystem; @@ -43,47 +45,6 @@ use Utopia\System\System; use Utopia\Telemetry\Adapter as Telemetry; use Utopia\Validator\WhiteList; -$parseLabel = function (string $label, array $responsePayload, array $requestParams, User $user, Document $project) { - preg_match_all('/{(.*?)}/', $label, $matches); - foreach ($matches[1] as $pos => $match) { - $find = $matches[0][$pos]; - $parts = explode('.', $match); - - if (count($parts) !== 2) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "The server encountered an error while parsing the label: $label. Please create an issue on GitHub to allow us to investigate further https://github.com/appwrite/appwrite/issues/new/choose"); - } - - $namespace = $parts[0]; - $replace = $parts[1]; - - $params = match ($namespace) { - 'user' => (array) $user, - 'project' => $project->getArrayCopy(), - 'request' => $requestParams, - default => $responsePayload, - }; - - if (array_key_exists($replace, $params)) { - $replacement = $params[$replace]; - // Convert to string if it's not already a string - if (! is_string($replacement)) { - if (is_array($replacement)) { - $replacement = json_encode($replacement); - } elseif (is_object($replacement) && method_exists($replacement, '__toString')) { - $replacement = (string) $replacement; - } elseif (is_scalar($replacement)) { - $replacement = (string) $replacement; - } else { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "The server encountered an error while parsing the label: $label. Please create an issue on GitHub to allow us to investigate further https://github.com/appwrite/appwrite/issues/new/choose"); - } - } - $label = \str_replace($find, $replacement, $label); - } - } - - return $label; -}; - Http::init() ->groups(['api']) ->inject('route') @@ -264,6 +225,13 @@ Http::init() API_KEY_ACCOUNT => ACTOR_TYPE_KEY_ACCOUNT, default => ACTOR_TYPE_KEY_ORGANIZATION, }); + + if ($apiKey->getType() === API_KEY_STANDARD || $apiKey->getType() === API_KEY_ORGANIZATION) { + $userClone + ->setAttribute('$id', $dbKey->getId()) + ->setAttribute('$sequence', $dbKey->getSequence()); + } + $auditContext->user = $userClone; } @@ -934,12 +902,18 @@ Http::shutdown() ->inject('auditContext') ->inject('publisherForAudits') ->inject('mode') - ->action(function (Route $route, array $params, Request $request, Response $response, Document $project, User $user, User $targetUser, AuditContext $auditContext, Audit $publisherForAudits, string $mode) use ($parseLabel) { + ->action(function (Route $route, array $params, Request $request, Response $response, Document $project, User $user, User $targetUser, AuditContext $auditContext, Audit $publisherForAudits, string $mode) { $responsePayload = $response->getPayload(); $pattern = $route->getLabel('audits.resource', null); if (! empty($pattern)) { - $resource = $parseLabel($pattern, $responsePayload, $params, $targetUser, $project); + $renderer = new Renderer(new Document([ + 'user' => (array) $targetUser, + 'project' => $project, + 'request' => $params, + 'response' => $responsePayload, + ])); + $resource = $renderer->render($pattern); if (! empty($resource) && $resource !== $pattern) { $auditContext->resource = $resource; } @@ -998,7 +972,7 @@ Http::shutdown() ->inject('user') ->inject('dbForProject') ->inject('authorization') - ->action(function (Route $route, array $params, Request $request, Response $response, Document $project, User $user, Database $dbForProject, Authorization $authorization) use ($parseLabel) { + ->action(function (Route $route, array $params, Request $request, Response $response, Document $project, User $user, Database $dbForProject, Authorization $authorization) { if (! $route->getLabel('cache', false)) { return; } @@ -1028,11 +1002,18 @@ Http::shutdown() $resourcePattern = $route->getLabel('cache.resource', null); $resourceTypePattern = $route->getLabel('cache.resourceType', null); + $renderer = new Renderer(new Document([ + 'user' => (array) $user, + 'project' => $project, + 'request' => $requestParams, + 'response' => $data, + ])); + try { $authorization->skip(fn () => $dbForProject->createDocument('cache', new Document([ '$id' => $key, - 'resource' => empty($resourcePattern) ? null : $parseLabel($resourcePattern, $data, $requestParams, $user, $project), - 'resourceType' => empty($resourceTypePattern) ? null : $parseLabel($resourceTypePattern, $data, $requestParams, $user, $project), + 'resource' => empty($resourcePattern) ? null : $renderer->render($resourcePattern), + 'resourceType' => empty($resourceTypePattern) ? null : $renderer->render($resourceTypePattern), 'mimeType' => $response->getContentType(), 'accessedAt' => $now, 'signature' => $signature, @@ -1112,6 +1093,95 @@ Http::shutdown() } }); +Http::shutdown() + ->groups(['api']) + ->inject('route') + ->inject('response') + ->inject('project') + ->inject('user') + ->inject('dbForPlatform') + ->inject('authorization') + ->inject('apiKey') + ->inject('mode') + ->action(function (Route $route, Response $response, Document $project, User $user, Database $dbForPlatform, Authorization $authorization, ?Key $apiKey, string $mode) { + /** + * Persist completed onboarding stage after usage shutdown so a schema/write failure here + * cannot suppress RequestCompleted or usage metrics on the same request. + */ + $statusCode = $response->getStatusCode(); + if ($statusCode < 200 || $statusCode >= 300 || $project->getId() === 'console') { + return; + } + + $sdkLabel = $route->getLabel('sdk', false); + if ($sdkLabel === false || $sdkLabel === null) { + return; + } + + /** @var array $onboarding */ + $onboarding = Config::getParam('onboarding', []); + if ($onboarding === []) { + return; + } + + $method = null; + if ($sdkLabel instanceof Method) { + $key = $sdkLabel->getNamespace() . '.' . $sdkLabel->getMethodName(); + if (isset($onboarding[$key])) { + $method = $key; + } + } elseif (\is_array($sdkLabel)) { + foreach ($sdkLabel as $sdkMethod) { + if (! $sdkMethod instanceof Method) { + continue; + } + $key = $sdkMethod->getNamespace() . '.' . $sdkMethod->getMethodName(); + if (isset($onboarding[$key])) { + $method = $key; + break; + } + } + } + + if ($method === null) { + return; + } + + $byMethod = $project->getAttribute('onboarding', []); + $status = \is_array($byMethod) ? ($byMethod[$method]['status'] ?? null) : null; + if ($status === ONBOARDING_STATUS_COMPLETED || $status === ONBOARDING_STATUS_SKIPPED) { + return; + } + + if (! \is_array($byMethod)) { + $byMethod = []; + } + + $actorType = ($apiKey !== null && $apiKey->getRole() === User::ROLE_KEYS) + ? match ($apiKey->getType()) { + API_KEY_ACCOUNT => ACTOR_TYPE_KEY_ACCOUNT, + API_KEY_ORGANIZATION => ACTOR_TYPE_KEY_ORGANIZATION, + API_KEY_STANDARD, API_KEY_EPHEMERAL => ACTOR_TYPE_KEY_PROJECT, + default => ACTOR_TYPE_KEY_PROJECT, + } + : (! $user->isEmpty() + ? ($mode === APP_MODE_ADMIN ? ACTOR_TYPE_ADMIN : ACTOR_TYPE_USER) + : ACTOR_TYPE_GUEST); + $byMethod[$method] = [ + 'status' => ONBOARDING_STATUS_COMPLETED, + 'at' => DateTime::now(), + 'actorType' => $actorType, + ]; + + try { + $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ + 'onboarding' => $byMethod, + ]))); + } catch (Throwable) { + // Missing `onboarding` attribute on upgraded installs must not break the request lifecycle. + } + }); + Http::init() ->groups(['usage']) ->action(function () { diff --git a/app/init/configs.php b/app/init/configs.php index 360a7abc34..f45ee1a7fe 100644 --- a/app/init/configs.php +++ b/app/init/configs.php @@ -26,6 +26,7 @@ Config::load('projectScopes', __DIR__ . '/../config/scopes/project.php', $config Config::load('organizationScopes', __DIR__ . '/../config/scopes/organization.php', $configAdapter); Config::load('accountScopes', __DIR__ . '/../config/scopes/account.php', $configAdapter); Config::load('services', __DIR__ . '/../config/services.php', $configAdapter); // List of services +Config::load('onboarding', __DIR__ . '/../config/onboarding.php', $configAdapter); // Project onboarding stages → routes Config::load('variables', __DIR__ . '/../config/variables.php', $configAdapter); // List of env variables Config::load('regions', __DIR__ . '/../config/regions.php', $configAdapter); // List of available regions Config::load('avatar-browsers', __DIR__ . '/../config/avatars/browsers.php', $configAdapter); diff --git a/app/init/constants.php b/app/init/constants.php index 8859937685..9efb6e3222 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -172,6 +172,12 @@ const ACTOR_TYPE_KEY_PROJECT = 'keyProject'; const ACTOR_TYPE_KEY_ACCOUNT = 'keyAccount'; const ACTOR_TYPE_KEY_ORGANIZATION = 'keyOrganization'; +/** + * Project onboarding stage status (stored per SDK method key under project.onboarding JSON). + */ +const ONBOARDING_STATUS_COMPLETED = 'completed'; +const ONBOARDING_STATUS_SKIPPED = 'skipped'; + /** * MFA */ diff --git a/app/init/models.php b/app/init/models.php index d0f665bb4e..efd2c13215 100644 --- a/app/init/models.php +++ b/app/init/models.php @@ -195,6 +195,7 @@ use Appwrite\Utopia\Response\Model\Schedule; use Appwrite\Utopia\Response\Model\Session; use Appwrite\Utopia\Response\Model\Site; use Appwrite\Utopia\Response\Model\Specification; +use Appwrite\Utopia\Response\Model\Stage; use Appwrite\Utopia\Response\Model\Subscriber; use Appwrite\Utopia\Response\Model\Table; use Appwrite\Utopia\Response\Model\Target; @@ -285,6 +286,7 @@ Response::setModel(new BaseList('Email Templates List', Response::MODEL_EMAIL_TE Response::setModel(new BaseList('Status List', Response::MODEL_HEALTH_STATUS_LIST, 'statuses', Response::MODEL_HEALTH_STATUS)); Response::setModel(new BaseList('Rule List', Response::MODEL_PROXY_RULE_LIST, 'rules', Response::MODEL_PROXY_RULE)); Response::setModel(new BaseList('Schedules List', Response::MODEL_SCHEDULE_LIST, 'schedules', Response::MODEL_SCHEDULE)); +Response::setModel(new BaseList('Stages List', Response::MODEL_STAGE_LIST, 'stages', Response::MODEL_STAGE, false, false)); Response::setModel(new BaseList('Locale codes list', Response::MODEL_LOCALE_CODE_LIST, 'localeCodes', Response::MODEL_LOCALE_CODE)); Response::setModel(new BaseList('Provider list', Response::MODEL_PROVIDER_LIST, 'providers', Response::MODEL_PROVIDER)); Response::setModel(new BaseList('Message list', Response::MODEL_MESSAGE_LIST, 'messages', Response::MODEL_MESSAGE)); @@ -507,6 +509,7 @@ Response::setModel(new Headers()); Response::setModel(new Specification()); Response::setModel(new Rule()); Response::setModel(new Schedule()); +Response::setModel(new Stage()); Response::setModel(new TemplateEmail()); Response::setModel(new ConsoleVariables()); Response::setModel(new ConsoleOAuth2ProviderParameter()); diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml deleted file mode 100644 index 7170439c1e..0000000000 --- a/app/views/install/compose.phtml +++ /dev/null @@ -1,1215 +0,0 @@ -x-logging: &x-logging - logging: - driver: 'json-file' - options: - max-file: '5' - max-size: '10m' -getParam('httpPort', ''); -$httpsPort = $this->getParam('httpsPort', ''); -$version = $this->getParam('version', ''); -$organization = $this->getParam('organization', ''); -$image = $this->getParam('image', ''); -$enableAssistant = $this->getParam('enableAssistant', false); -$executorImages = $this->getParam('executorImages', ''); -$dbService = $this->getParam('database', 'mongodb'); -$allowedDbServices = ['mariadb', 'mongodb', 'postgresql']; -if (!\in_array($dbService, $allowedDbServices, true)) { - $dbService = 'mongodb'; -} -$hostPath = rtrim($this->getParam('hostPath', ''), '/'); -?>services: - traefik: - image: traefik:3.6 - container_name: appwrite-traefik - <<: *x-logging - command: - - --providers.file.directory=/storage/config - - --providers.file.watch=true - - --providers.docker=true - - --providers.docker.exposedByDefault=false - - --providers.docker.constraints=Label(`traefik.constraint-label-stack`,`appwrite`) - - --entrypoints.appwrite_web.address=:80 - - --entrypoints.appwrite_websecure.address=:443 - restart: unless-stopped - ports: - - :80 - - :443 - volumes: - - /var/run/docker.sock:/var/run/docker.sock - - appwrite-config:/storage/config:ro - - appwrite-certificates:/storage/certificates:ro - depends_on: - - appwrite - networks: - - gateway - - appwrite - - appwrite: - image: /: - container_name: appwrite - <<: *x-logging - restart: unless-stopped - networks: - - appwrite - labels: - - traefik.enable=true - - traefik.constraint-label-stack=appwrite - - traefik.docker.network=appwrite - - traefik.http.services.appwrite_api.loadbalancer.server.port=80 - #http - - traefik.http.routers.appwrite_api_http.entrypoints=appwrite_web - - traefik.http.routers.appwrite_api_http.rule=PathPrefix(`/`) - - traefik.http.routers.appwrite_api_http.service=appwrite_api - # https - - traefik.http.routers.appwrite_api_https.entrypoints=appwrite_websecure - - traefik.http.routers.appwrite_api_https.rule=PathPrefix(`/`) - - traefik.http.routers.appwrite_api_https.service=appwrite_api - - traefik.http.routers.appwrite_api_https.tls=true - volumes: - - - ":/usr/src/code:rw" - - - appwrite-uploads:/storage/uploads:rw - - appwrite-imports:/storage/imports:rw - - appwrite-cache:/storage/cache:rw - - appwrite-config:/storage/config:rw - - appwrite-certificates:/storage/certificates:rw - - appwrite-functions:/storage/functions:rw - - appwrite-sites:/storage/sites:rw - - appwrite-builds:/storage/builds:rw - depends_on: - redis: - condition: service_healthy - : - condition: service_healthy -# - clamav - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_LOCALE - - _APP_COMPRESSION_MIN_SIZE_BYTES - - _APP_CONSOLE_WHITELIST_ROOT - - _APP_CONSOLE_WHITELIST_EMAILS - - _APP_CONSOLE_SESSION_ALERTS - - _APP_CONSOLE_WHITELIST_IPS - - _APP_CONSOLE_HOSTNAMES - - _APP_SYSTEM_EMAIL_NAME - - _APP_SYSTEM_EMAIL_ADDRESS - - _APP_EMAIL_SECURITY - - _APP_SYSTEM_RESPONSE_FORMAT - - _APP_OPTIONS_ABUSE - - _APP_OPTIONS_ROUTER_PROTECTION - - _APP_OPTIONS_FORCE_HTTPS - - _APP_OPTIONS_ROUTER_FORCE_HTTPS - - _APP_OPENSSL_KEY_V1 - - _APP_DOMAIN - - _APP_DOMAIN_TARGET_CNAME - - _APP_DOMAIN_TARGET_AAAA - - _APP_DOMAIN_TARGET_A - - _APP_DOMAIN_TARGET_CAA - - _APP_DNS - - _APP_DOMAIN_FUNCTIONS - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_SMTP_HOST - - _APP_SMTP_PORT - - _APP_SMTP_SECURE - - _APP_SMTP_USERNAME - - _APP_SMTP_PASSWORD - - _APP_USAGE_STATS - - _APP_STORAGE_LIMIT - - _APP_STORAGE_PREVIEW_LIMIT - - _APP_STORAGE_ANTIVIRUS - - _APP_STORAGE_ANTIVIRUS_HOST - - _APP_STORAGE_ANTIVIRUS_PORT - - _APP_STORAGE_DEVICE - - _APP_STORAGE_S3_ACCESS_KEY - - _APP_STORAGE_S3_SECRET - - _APP_STORAGE_S3_REGION - - _APP_STORAGE_S3_BUCKET - - _APP_STORAGE_S3_ENDPOINT - - _APP_STORAGE_DO_SPACES_ACCESS_KEY - - _APP_STORAGE_DO_SPACES_SECRET - - _APP_STORAGE_DO_SPACES_REGION - - _APP_STORAGE_DO_SPACES_BUCKET - - _APP_STORAGE_BACKBLAZE_ACCESS_KEY - - _APP_STORAGE_BACKBLAZE_SECRET - - _APP_STORAGE_BACKBLAZE_REGION - - _APP_STORAGE_BACKBLAZE_BUCKET - - _APP_STORAGE_LINODE_ACCESS_KEY - - _APP_STORAGE_LINODE_SECRET - - _APP_STORAGE_LINODE_REGION - - _APP_STORAGE_LINODE_BUCKET - - _APP_STORAGE_WASABI_ACCESS_KEY - - _APP_STORAGE_WASABI_SECRET - - _APP_STORAGE_WASABI_REGION - - _APP_STORAGE_WASABI_BUCKET - - _APP_COMPUTE_SIZE_LIMIT - - _APP_FUNCTIONS_TIMEOUT - - _APP_SITES_TIMEOUT - - _APP_COMPUTE_BUILD_TIMEOUT - - _APP_COMPUTE_CPUS - - _APP_COMPUTE_MEMORY - - _APP_FUNCTIONS_RUNTIMES - - _APP_SITES_RUNTIMES - - _APP_DOMAIN_SITES - - _APP_EXECUTOR_SECRET - - _APP_EXECUTOR_HOST - - _APP_LOGGING_CONFIG - - _APP_MAINTENANCE_INTERVAL - - _APP_MAINTENANCE_DELAY - - _APP_MAINTENANCE_START_TIME - - _APP_MAINTENANCE_RETENTION_EXECUTION - - _APP_MAINTENANCE_RETENTION_CACHE - - _APP_MAINTENANCE_RETENTION_ABUSE - - _APP_MAINTENANCE_RETENTION_AUDIT - - _APP_MAINTENANCE_RETENTION_AUDIT_CONSOLE - - _APP_MAINTENANCE_RETENTION_USAGE_HOURLY - - _APP_MAINTENANCE_RETENTION_SCHEDULES - - _APP_SMS_PROVIDER - - _APP_SMS_FROM - - _APP_GRAPHQL_INTROSPECTION - - _APP_GRAPHQL_MAX_BATCH_SIZE - - _APP_GRAPHQL_MAX_COMPLEXITY - - _APP_GRAPHQL_MAX_DEPTH - - _APP_VCS_GITHUB_APP_NAME - - _APP_VCS_GITHUB_PRIVATE_KEY - - _APP_VCS_GITHUB_APP_ID - - _APP_VCS_GITHUB_WEBHOOK_SECRET - - _APP_VCS_GITHUB_CLIENT_SECRET - - _APP_VCS_GITHUB_CLIENT_ID - - _APP_MIGRATIONS_FIREBASE_CLIENT_ID - - _APP_MIGRATIONS_FIREBASE_CLIENT_SECRET - - _APP_ASSISTANT_OPENAI_API_KEY - appwrite-console: - <<: *x-logging - container_name: appwrite-console - image: /console:8.7.5 - restart: unless-stopped - networks: - - appwrite - labels: - - "traefik.enable=true" - - "traefik.constraint-label-stack=appwrite" - - "traefik.docker.network=appwrite" - - "traefik.http.services.appwrite_console.loadbalancer.server.port=80" - #ws - - traefik.http.routers.appwrite_console_http.entrypoints=appwrite_web - - traefik.http.routers.appwrite_console_http.rule=PathPrefix(`/console`) - - traefik.http.routers.appwrite_console_http.service=appwrite_console - # wss - - traefik.http.routers.appwrite_console_https.entrypoints=appwrite_websecure - - traefik.http.routers.appwrite_console_https.rule=PathPrefix(`/console`) - - traefik.http.routers.appwrite_console_https.service=appwrite_console - - traefik.http.routers.appwrite_console_https.tls=true - - appwrite-realtime: - image: /: - entrypoint: realtime - container_name: appwrite-realtime - <<: *x-logging - restart: unless-stopped - labels: - - "traefik.enable=true" - - "traefik.constraint-label-stack=appwrite" - - "traefik.docker.network=appwrite" - - "traefik.http.services.appwrite_realtime.loadbalancer.server.port=80" - #ws - - traefik.http.routers.appwrite_realtime_ws.entrypoints=appwrite_web - - traefik.http.routers.appwrite_realtime_ws.rule=PathPrefix(`/v1/realtime`) - - traefik.http.routers.appwrite_realtime_ws.service=appwrite_realtime - # wss - - traefik.http.routers.appwrite_realtime_wss.entrypoints=appwrite_websecure - - traefik.http.routers.appwrite_realtime_wss.rule=PathPrefix(`/v1/realtime`) - - traefik.http.routers.appwrite_realtime_wss.service=appwrite_realtime - - traefik.http.routers.appwrite_realtime_wss.tls=true - networks: - - appwrite - depends_on: - redis: - condition: service_healthy - : - condition: service_healthy - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_OPTIONS_ABUSE - - _APP_OPTIONS_ROUTER_PROTECTION - - _APP_OPENSSL_KEY_V1 - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_USAGE_STATS - - _APP_LOGGING_CONFIG - - appwrite-worker-audits: - image: /: - entrypoint: worker-audits - <<: *x-logging - container_name: appwrite-worker-audits - restart: unless-stopped - networks: - - appwrite - depends_on: - redis: - condition: service_healthy - : - condition: service_healthy - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_OPENSSL_KEY_V1 - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_LOGGING_CONFIG - - appwrite-worker-webhooks: - image: /: - entrypoint: worker-webhooks - <<: *x-logging - container_name: appwrite-worker-webhooks - restart: unless-stopped - networks: - - appwrite - depends_on: - redis: - condition: service_healthy - : - condition: service_healthy - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_OPENSSL_KEY_V1 - - _APP_EMAIL_SECURITY - - _APP_SYSTEM_SECURITY_EMAIL_ADDRESS - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_LOGGING_CONFIG - - appwrite-worker-deletes: - image: /: - entrypoint: worker-deletes - <<: *x-logging - container_name: appwrite-worker-deletes - restart: unless-stopped - networks: - - appwrite - depends_on: - redis: - condition: service_healthy - : - condition: service_healthy - volumes: - - appwrite-uploads:/storage/uploads:rw - - appwrite-cache:/storage/cache:rw - - appwrite-functions:/storage/functions:rw - - appwrite-sites:/storage/sites:rw - - appwrite-builds:/storage/builds:rw - - appwrite-certificates:/storage/certificates:rw - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_OPENSSL_KEY_V1 - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_STORAGE_DEVICE - - _APP_STORAGE_S3_ACCESS_KEY - - _APP_STORAGE_S3_SECRET - - _APP_STORAGE_S3_REGION - - _APP_STORAGE_S3_BUCKET - - _APP_STORAGE_S3_ENDPOINT - - _APP_STORAGE_DO_SPACES_ACCESS_KEY - - _APP_STORAGE_DO_SPACES_SECRET - - _APP_STORAGE_DO_SPACES_REGION - - _APP_STORAGE_DO_SPACES_BUCKET - - _APP_STORAGE_BACKBLAZE_ACCESS_KEY - - _APP_STORAGE_BACKBLAZE_SECRET - - _APP_STORAGE_BACKBLAZE_REGION - - _APP_STORAGE_BACKBLAZE_BUCKET - - _APP_STORAGE_LINODE_ACCESS_KEY - - _APP_STORAGE_LINODE_SECRET - - _APP_STORAGE_LINODE_REGION - - _APP_STORAGE_LINODE_BUCKET - - _APP_STORAGE_WASABI_ACCESS_KEY - - _APP_STORAGE_WASABI_SECRET - - _APP_STORAGE_WASABI_REGION - - _APP_STORAGE_WASABI_BUCKET - - _APP_LOGGING_CONFIG - - _APP_EXECUTOR_SECRET - - _APP_EXECUTOR_HOST - - _APP_MAINTENANCE_RETENTION_ABUSE - - _APP_MAINTENANCE_RETENTION_AUDIT - - _APP_MAINTENANCE_RETENTION_AUDIT_CONSOLE - - _APP_MAINTENANCE_RETENTION_EXECUTION - - _APP_SYSTEM_SECURITY_EMAIL_ADDRESS - - _APP_EMAIL_CERTIFICATES - - appwrite-worker-databases: - image: /: - entrypoint: worker-databases - <<: *x-logging - container_name: appwrite-worker-databases - restart: unless-stopped - networks: - - appwrite - depends_on: - redis: - condition: service_healthy - : - condition: service_healthy - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_OPENSSL_KEY_V1 - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_LOGGING_CONFIG - - appwrite-worker-builds: - image: /: - entrypoint: worker-builds - <<: *x-logging - container_name: appwrite-worker-builds - restart: unless-stopped - networks: - - appwrite - depends_on: - redis: - condition: service_healthy - : - condition: service_healthy - volumes: - - appwrite-functions:/storage/functions:rw - - appwrite-sites:/storage/sites:rw - - appwrite-builds:/storage/builds:rw - - appwrite-uploads:/storage/uploads:rw - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_OPENSSL_KEY_V1 - - _APP_EXECUTOR_SECRET - - _APP_EXECUTOR_HOST - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_LOGGING_CONFIG - - _APP_VCS_GITHUB_APP_NAME - - _APP_VCS_GITHUB_PRIVATE_KEY - - _APP_VCS_GITHUB_APP_ID - - _APP_FUNCTIONS_TIMEOUT - - _APP_SITES_TIMEOUT - - _APP_COMPUTE_BUILD_TIMEOUT - - _APP_COMPUTE_CPUS - - _APP_COMPUTE_MEMORY - - _APP_COMPUTE_SIZE_LIMIT - - _APP_OPTIONS_FORCE_HTTPS - - _APP_OPTIONS_ROUTER_FORCE_HTTPS - - _APP_DOMAIN - - _APP_STORAGE_DEVICE - - _APP_STORAGE_S3_ACCESS_KEY - - _APP_STORAGE_S3_SECRET - - _APP_STORAGE_S3_REGION - - _APP_STORAGE_S3_BUCKET - - _APP_STORAGE_S3_ENDPOINT - - _APP_STORAGE_DO_SPACES_ACCESS_KEY - - _APP_STORAGE_DO_SPACES_SECRET - - _APP_STORAGE_DO_SPACES_REGION - - _APP_STORAGE_DO_SPACES_BUCKET - - _APP_STORAGE_BACKBLAZE_ACCESS_KEY - - _APP_STORAGE_BACKBLAZE_SECRET - - _APP_STORAGE_BACKBLAZE_REGION - - _APP_STORAGE_BACKBLAZE_BUCKET - - _APP_STORAGE_LINODE_ACCESS_KEY - - _APP_STORAGE_LINODE_SECRET - - _APP_STORAGE_LINODE_REGION - - _APP_STORAGE_LINODE_BUCKET - - _APP_STORAGE_WASABI_ACCESS_KEY - - _APP_STORAGE_WASABI_SECRET - - _APP_STORAGE_WASABI_REGION - - _APP_STORAGE_WASABI_BUCKET - - _APP_DOMAIN_SITES - - appwrite-worker-certificates: - image: /: - entrypoint: worker-certificates - <<: *x-logging - container_name: appwrite-worker-certificates - restart: unless-stopped - networks: - - appwrite - depends_on: - redis: - condition: service_healthy - : - condition: service_healthy - volumes: - - appwrite-config:/storage/config:rw - - appwrite-certificates:/storage/certificates:rw - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_OPENSSL_KEY_V1 - - _APP_DOMAIN - - _APP_DOMAIN_TARGET_CNAME - - _APP_DOMAIN_TARGET_AAAA - - _APP_DOMAIN_TARGET_A - - _APP_DOMAIN_TARGET_CAA - - _APP_DNS - - _APP_DOMAIN_FUNCTIONS - - _APP_EMAIL_CERTIFICATES - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_LOGGING_CONFIG - - appwrite-worker-executions: - image: /: - entrypoint: worker-executions - <<: *x-logging - container_name: appwrite-worker-executions - restart: unless-stopped - networks: - - appwrite - depends_on: - redis: - condition: service_healthy - : - condition: service_healthy - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_ENV - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_LOGGING_CONFIG - - appwrite-worker-functions: - image: /: - entrypoint: worker-functions - <<: *x-logging - container_name: appwrite-worker-functions - restart: unless-stopped - networks: - - appwrite - depends_on: - redis: - condition: service_healthy - : - condition: service_healthy - openruntimes-executor: - condition: service_started - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_OPENSSL_KEY_V1 - - _APP_DOMAIN - - _APP_OPTIONS_FORCE_HTTPS - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_FUNCTIONS_TIMEOUT - - _APP_SITES_TIMEOUT - - _APP_COMPUTE_BUILD_TIMEOUT - - _APP_COMPUTE_CPUS - - _APP_COMPUTE_MEMORY - - _APP_EXECUTOR_SECRET - - _APP_EXECUTOR_HOST - - _APP_USAGE_STATS - - _APP_DOCKER_HUB_USERNAME - - _APP_DOCKER_HUB_PASSWORD - - _APP_LOGGING_CONFIG - - appwrite-worker-mails: - image: /: - entrypoint: worker-mails - <<: *x-logging - container_name: appwrite-worker-mails - restart: unless-stopped - networks: - - appwrite - depends_on: - redis: - condition: service_healthy - : - condition: service_healthy - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_OPENSSL_KEY_V1 - - _APP_SYSTEM_EMAIL_NAME - - _APP_SYSTEM_EMAIL_ADDRESS - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_SMTP_HOST - - _APP_SMTP_PORT - - _APP_SMTP_SECURE - - _APP_SMTP_USERNAME - - _APP_SMTP_PASSWORD - - _APP_LOGGING_CONFIG - - _APP_DOMAIN - - _APP_OPTIONS_FORCE_HTTPS - - appwrite-worker-messaging: - image: /: - entrypoint: worker-messaging - <<: *x-logging - container_name: appwrite-worker-messaging - restart: unless-stopped - networks: - - appwrite - volumes: - - appwrite-uploads:/storage/uploads:rw - depends_on: - redis: - condition: service_healthy - : - condition: service_healthy - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_OPENSSL_KEY_V1 - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_LOGGING_CONFIG - - _APP_SMS_FROM - - _APP_SMS_PROVIDER - - _APP_STORAGE_DEVICE - - _APP_STORAGE_S3_ACCESS_KEY - - _APP_STORAGE_S3_SECRET - - _APP_STORAGE_S3_REGION - - _APP_STORAGE_S3_BUCKET - - _APP_STORAGE_S3_ENDPOINT - - _APP_STORAGE_DO_SPACES_ACCESS_KEY - - _APP_STORAGE_DO_SPACES_SECRET - - _APP_STORAGE_DO_SPACES_REGION - - _APP_STORAGE_DO_SPACES_BUCKET - - _APP_STORAGE_BACKBLAZE_ACCESS_KEY - - _APP_STORAGE_BACKBLAZE_SECRET - - _APP_STORAGE_BACKBLAZE_REGION - - _APP_STORAGE_BACKBLAZE_BUCKET - - _APP_STORAGE_LINODE_ACCESS_KEY - - _APP_STORAGE_LINODE_SECRET - - _APP_STORAGE_LINODE_REGION - - _APP_STORAGE_LINODE_BUCKET - - _APP_STORAGE_WASABI_ACCESS_KEY - - _APP_STORAGE_WASABI_SECRET - - _APP_STORAGE_WASABI_REGION - - _APP_STORAGE_WASABI_BUCKET - - appwrite-worker-migrations: - image: /: - entrypoint: worker-migrations - <<: *x-logging - container_name: appwrite-worker-migrations - restart: unless-stopped - networks: - - appwrite - volumes: - - appwrite-imports:/storage/imports:rw - depends_on: - : - condition: service_healthy - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_OPENSSL_KEY_V1 - - _APP_DOMAIN - - _APP_DOMAIN_TARGET_CNAME - - _APP_DOMAIN_TARGET_AAAA - - _APP_DOMAIN_TARGET_A - - _APP_DOMAIN_TARGET_CAA - - _APP_DNS - - _APP_EMAIL_SECURITY - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_LOGGING_CONFIG - - _APP_MIGRATIONS_FIREBASE_CLIENT_ID - - _APP_MIGRATIONS_FIREBASE_CLIENT_SECRET - - appwrite-task-maintenance: - image: /: - entrypoint: maintenance - <<: *x-logging - container_name: appwrite-task-maintenance - restart: unless-stopped - networks: - - appwrite - depends_on: - redis: - condition: service_healthy - : - condition: service_healthy - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_DOMAIN - - _APP_DOMAIN_TARGET_CNAME - - _APP_DOMAIN_TARGET_AAAA - - _APP_DOMAIN_TARGET_A - - _APP_DOMAIN_TARGET_CAA - - _APP_DNS - - _APP_DOMAIN_FUNCTIONS - - _APP_OPENSSL_KEY_V1 - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_MAINTENANCE_INTERVAL - - _APP_MAINTENANCE_RETENTION_EXECUTION - - _APP_MAINTENANCE_RETENTION_CACHE - - _APP_MAINTENANCE_RETENTION_ABUSE - - _APP_MAINTENANCE_RETENTION_AUDIT - - _APP_MAINTENANCE_RETENTION_AUDIT_CONSOLE - - _APP_MAINTENANCE_RETENTION_USAGE_HOURLY - - _APP_MAINTENANCE_RETENTION_SCHEDULES - - appwrite-task-stats-resources: - image: /: - container_name: appwrite-task-stats-resources - entrypoint: stats-resources - <<: *x-logging - restart: unless-stopped - networks: - - appwrite - depends_on: - redis: - condition: service_healthy - : - condition: service_healthy - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_OPENSSL_KEY_V1 - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_USAGE_STATS - - _APP_LOGGING_CONFIG - - _APP_DATABASE_SHARED_TABLES - - _APP_STATS_RESOURCES_INTERVAL - - appwrite-worker-stats-resources: - image: /: - entrypoint: worker-stats-resources - container_name: appwrite-worker-stats-resources - <<: *x-logging - restart: unless-stopped - networks: - - appwrite - depends_on: - redis: - condition: service_healthy - : - condition: service_healthy - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_OPENSSL_KEY_V1 - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_USAGE_STATS - - _APP_LOGGING_CONFIG - - _APP_STATS_RESOURCES_INTERVAL - - appwrite-worker-stats-usage: - image: /: - entrypoint: worker-stats-usage - container_name: appwrite-worker-stats-usage - <<: *x-logging - restart: unless-stopped - networks: - - appwrite - depends_on: - redis: - condition: service_healthy - : - condition: service_healthy - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_OPENSSL_KEY_V1 - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_USAGE_STATS - - _APP_LOGGING_CONFIG - - _APP_USAGE_AGGREGATION_INTERVAL - - appwrite-task-scheduler-functions: - image: /: - entrypoint: schedule-functions - container_name: appwrite-task-scheduler-functions - <<: *x-logging - restart: unless-stopped - networks: - - appwrite - depends_on: - : - condition: service_healthy - redis: - condition: service_healthy - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_OPENSSL_KEY_V1 - - _APP_OPTIONS_FORCE_HTTPS - - _APP_DOMAIN - - _APP_CONSOLE_DOMAIN - - _APP_DOMAIN_FUNCTIONS - - _APP_DOMAIN_SITES - - _APP_MIGRATION_HOST - - _APP_CONSOLE_SCHEMA - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - appwrite-task-scheduler-executions: - image: /: - entrypoint: schedule-executions - container_name: appwrite-task-scheduler-executions - <<: *x-logging - restart: unless-stopped - networks: - - appwrite - depends_on: - : - condition: service_healthy - redis: - condition: service_healthy - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_OPENSSL_KEY_V1 - - _APP_OPTIONS_FORCE_HTTPS - - _APP_DOMAIN - - _APP_CONSOLE_DOMAIN - - _APP_DOMAIN_FUNCTIONS - - _APP_DOMAIN_SITES - - _APP_MIGRATION_HOST - - _APP_CONSOLE_SCHEMA - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - appwrite-task-scheduler-messages: - image: /: - entrypoint: schedule-messages - container_name: appwrite-task-scheduler-messages - <<: *x-logging - restart: unless-stopped - networks: - - appwrite - depends_on: - : - condition: service_healthy - redis: - condition: service_healthy - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_OPENSSL_KEY_V1 - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - - appwrite-assistant: - image: appwrite/assistant:0.8.4 - container_name: appwrite-assistant - <<: *x-logging - restart: unless-stopped - networks: - - appwrite - environment: - - _APP_ASSISTANT_OPENAI_API_KEY - - - appwrite-browser: - image: appwrite/browser:0.3.2 - container_name: appwrite-browser - <<: *x-logging - restart: unless-stopped - networks: - - appwrite - - openruntimes-executor: - container_name: exc1 - hostname: exc1 - <<: *x-logging - restart: unless-stopped - stop_signal: SIGINT - image: openruntimes/executor:0.25.1 - networks: - - appwrite - volumes: - - /var/run/docker.sock:/var/run/docker.sock - - appwrite-builds:/storage/builds:rw - - appwrite-functions:/storage/functions:rw - - appwrite-sites:/storage/sites:rw - # Host mount nessessary to share files between executor and runtimes. - # It's not possible to share mount file between 2 containers without host mount (copying is too slow) - - /tmp:/tmp:rw - environment: - - OPR_EXECUTOR_CONNECTION_STORAGE=local://localhost - - OPR_EXECUTOR_CONNECTION_BUILD_CACHE_STORAGE= - - OPR_EXECUTOR_IMAGES= - - OPR_EXECUTOR_INACTIVE_TRESHOLD=$_APP_COMPUTE_INACTIVE_THRESHOLD - - OPR_EXECUTOR_MAINTENANCE_INTERVAL=$_APP_COMPUTE_MAINTENANCE_INTERVAL - - OPR_EXECUTOR_NETWORK=$_APP_COMPUTE_RUNTIMES_NETWORK - - OPR_EXECUTOR_DOCKER_HUB_USERNAME=$_APP_DOCKER_HUB_USERNAME - - OPR_EXECUTOR_DOCKER_HUB_PASSWORD=$_APP_DOCKER_HUB_PASSWORD - - OPR_EXECUTOR_ENV=$_APP_ENV - - OPR_EXECUTOR_RUNTIMES=$_APP_FUNCTIONS_RUNTIMES,$_APP_SITES_RUNTIMES - - OPR_EXECUTOR_SECRET=$_APP_EXECUTOR_SECRET - - OPR_EXECUTOR_RUNTIME_VERSIONS=v5 - - OPR_EXECUTOR_LOGGING_CONFIG=$_APP_LOGGING_CONFIG - - OPR_EXECUTOR_STORAGE_DEVICE=$_APP_STORAGE_DEVICE - - OPR_EXECUTOR_STORAGE_S3_ACCESS_KEY=$_APP_STORAGE_S3_ACCESS_KEY - - OPR_EXECUTOR_STORAGE_S3_SECRET=$_APP_STORAGE_S3_SECRET - - OPR_EXECUTOR_STORAGE_S3_REGION=$_APP_STORAGE_S3_REGION - - OPR_EXECUTOR_STORAGE_S3_BUCKET=$_APP_STORAGE_S3_BUCKET - - OPR_EXECUTOR_STORAGE_S3_ENDPOINT=$_APP_STORAGE_S3_ENDPOINT - - OPR_EXECUTOR_STORAGE_DO_SPACES_ACCESS_KEY=$_APP_STORAGE_DO_SPACES_ACCESS_KEY - - OPR_EXECUTOR_STORAGE_DO_SPACES_SECRET=$_APP_STORAGE_DO_SPACES_SECRET - - OPR_EXECUTOR_STORAGE_DO_SPACES_REGION=$_APP_STORAGE_DO_SPACES_REGION - - OPR_EXECUTOR_STORAGE_DO_SPACES_BUCKET=$_APP_STORAGE_DO_SPACES_BUCKET - - OPR_EXECUTOR_STORAGE_BACKBLAZE_ACCESS_KEY=$_APP_STORAGE_BACKBLAZE_ACCESS_KEY - - OPR_EXECUTOR_STORAGE_BACKBLAZE_SECRET=$_APP_STORAGE_BACKBLAZE_SECRET - - OPR_EXECUTOR_STORAGE_BACKBLAZE_REGION=$_APP_STORAGE_BACKBLAZE_REGION - - OPR_EXECUTOR_STORAGE_BACKBLAZE_BUCKET=$_APP_STORAGE_BACKBLAZE_BUCKET - - OPR_EXECUTOR_STORAGE_LINODE_ACCESS_KEY=$_APP_STORAGE_LINODE_ACCESS_KEY - - OPR_EXECUTOR_STORAGE_LINODE_SECRET=$_APP_STORAGE_LINODE_SECRET - - OPR_EXECUTOR_STORAGE_LINODE_REGION=$_APP_STORAGE_LINODE_REGION - - OPR_EXECUTOR_STORAGE_LINODE_BUCKET=$_APP_STORAGE_LINODE_BUCKET - - OPR_EXECUTOR_STORAGE_WASABI_ACCESS_KEY=$_APP_STORAGE_WASABI_ACCESS_KEY - - OPR_EXECUTOR_STORAGE_WASABI_SECRET=$_APP_STORAGE_WASABI_SECRET - - OPR_EXECUTOR_STORAGE_WASABI_REGION=$_APP_STORAGE_WASABI_REGION - - OPR_EXECUTOR_STORAGE_WASABI_BUCKET=$_APP_STORAGE_WASABI_BUCKET - - - mariadb: - image: mariadb:10.11 - container_name: appwrite-mariadb - restart: unless-stopped - networks: - - appwrite - volumes: - - appwrite-mariadb:/var/lib/mysql:rw - environment: - - MYSQL_ROOT_PASSWORD=${_APP_DB_ROOT_PASS} - - MYSQL_DATABASE=${_APP_DB_SCHEMA} - - MYSQL_USER=${_APP_DB_USER} - - MYSQL_PASSWORD=${_APP_DB_PASS} - - MARIADB_AUTO_UPGRADE=1 - command: 'mysqld --innodb-flush-method=fsync' - healthcheck: - test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"] - interval: 10s - timeout: 10s - retries: 10 - start_period: 30s - - - - mongodb: - image: mongo:8.2.5 - container_name: appwrite-mongodb - <<: *x-logging - restart: unless-stopped - networks: - - appwrite - volumes: - - appwrite-mongodb:/data/db - - appwrite-mongodb-keyfile:/data/keyfile - environment: - - MONGO_INITDB_ROOT_USERNAME=root - - MONGO_INITDB_ROOT_PASSWORD=${_APP_DB_ROOT_PASS} - - MONGO_INITDB_DATABASE=${_APP_DB_SCHEMA} - - MONGO_INITDB_USERNAME=${_APP_DB_USER} - - MONGO_INITDB_PASSWORD=${_APP_DB_PASS} - entrypoint: - - /bin/bash - - -c - - | - set -e - KEYFILE_PATH="/data/keyfile/mongo-keyfile" - INIT_FLAG="/data/db/.mongodb_initialized" - - # Generate keyfile if it doesn't exist - if [ ! -f "$$KEYFILE_PATH" ]; then - echo "Generating random MongoDB keyfile..." - mkdir -p /data/keyfile - openssl rand -base64 756 > "$$KEYFILE_PATH" - fi - chmod 400 "$$KEYFILE_PATH" - chown mongodb:mongodb "$$KEYFILE_PATH" 2>/dev/null || chown 999:999 "$$KEYFILE_PATH" - - # If not initialized, start without auth first to set up replica set and users - if [ ! -f "$$INIT_FLAG" ]; then - echo "First-time initialization: starting MongoDB without auth..." - mongod --replSet rs0 --bind_ip_all --fork --logpath /var/log/mongodb/mongod.log --dbpath /data/db - - echo "Waiting for MongoDB to start..." - sleep 5 - - echo "Initializing replica set..." - mongosh --eval "rs.initiate({_id: 'rs0', members: [{_id: 0, host: 'mongodb:27017'}]})" - - echo "Waiting for replica set to initialize..." - sleep 5 - - echo "Creating root user..." - mongosh admin --eval "db.createUser({user: '$$MONGO_INITDB_ROOT_USERNAME', pwd: '$$MONGO_INITDB_ROOT_PASSWORD', roles: ['root']})" - - echo "Creating application user..." - mongosh admin --eval "db.createUser({user: '$$MONGO_INITDB_USERNAME', pwd: '$$MONGO_INITDB_PASSWORD', roles: [{role: 'readWrite', db: '$$MONGO_INITDB_DATABASE'}]})" - - echo "Shutting down MongoDB..." - mongod --dbpath /data/db --shutdown - - touch "$$INIT_FLAG" - echo "Initialization complete." - fi - - echo "Starting MongoDB with authentication..." - exec mongod --replSet rs0 --bind_ip_all --auth --keyFile "$$KEYFILE_PATH" - healthcheck: - test: | - mongosh -u root -p "$$MONGO_INITDB_ROOT_PASSWORD" --authenticationDatabase admin --quiet --eval "const hello = db.adminCommand({hello: 1}); if (!hello.isWritablePrimary) { quit(1); }" - interval: 10s - timeout: 10s - retries: 10 - start_period: 60s - - - - postgresql: - image: appwrite/postgres:0.1.0 - container_name: appwrite-postgresql - restart: unless-stopped - networks: - - appwrite - volumes: - - appwrite-postgresql:/var/lib/postgresql:rw - environment: - - POSTGRES_DB=${_APP_DB_SCHEMA} - - POSTGRES_USER=${_APP_DB_USER} - - POSTGRES_PASSWORD=${_APP_DB_PASS} - command: "postgres" - healthcheck: - test: ["CMD-SHELL", "pg_isready -U ${_APP_DB_USER} -d ${_APP_DB_SCHEMA}"] - interval: 10s - timeout: 10s - retries: 10 - start_period: 30s - - - - redis: - image: redis:7.4.7-alpine - container_name: appwrite-redis - <<: *x-logging - restart: unless-stopped - command: > - redis-server - --maxmemory 512mb - --maxmemory-policy allkeys-lru - --maxmemory-samples 5 - networks: - - appwrite - volumes: - - appwrite-redis:/data:rw - healthcheck: - test: ["CMD", "redis-cli", "ping"] - interval: 10s - timeout: 5s - retries: 5 - start_period: 10s - - # clamav: - # image: appwrite/clamav:1.2.0 - # container_name: appwrite-clamav - # restart: unless-stopped - # networks: - # - appwrite - # volumes: - # - appwrite-uploads:/storage/uploads - -networks: - gateway: - name: gateway - appwrite: - name: appwrite - runtimes: - name: runtimes - -volumes: - - appwrite-mariadb: - - appwrite-postgresql: - - appwrite-mongodb: - appwrite-mongodb-keyfile: - - appwrite-redis: - appwrite-cache: - appwrite-uploads: - appwrite-imports: - appwrite-certificates: - appwrite-functions: - appwrite-sites: - appwrite-builds: - appwrite-config: - openruntimes-node-modules-cache: diff --git a/composer.lock b/composer.lock index b1fa6bf2d1..f719710677 100644 --- a/composer.lock +++ b/composer.lock @@ -5124,16 +5124,16 @@ }, { "name": "utopia-php/vcs", - "version": "4.2.3", + "version": "4.2.4", "source": { "type": "git", "url": "https://github.com/utopia-php/vcs.git", - "reference": "598cbd2793a5a6394493f1046743e75ec6544a57" + "reference": "f19c61daa1e9594734d85ae25b3e90ba2b350d33" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/vcs/zipball/598cbd2793a5a6394493f1046743e75ec6544a57", - "reference": "598cbd2793a5a6394493f1046743e75ec6544a57", + "url": "https://api.github.com/repos/utopia-php/vcs/zipball/f19c61daa1e9594734d85ae25b3e90ba2b350d33", + "reference": "f19c61daa1e9594734d85ae25b3e90ba2b350d33", "shasum": "" }, "require": { @@ -5167,9 +5167,9 @@ ], "support": { "issues": "https://github.com/utopia-php/vcs/issues", - "source": "https://github.com/utopia-php/vcs/tree/4.2.3" + "source": "https://github.com/utopia-php/vcs/tree/4.2.4" }, - "time": "2026-06-16T12:14:08+00:00" + "time": "2026-06-25T13:27:19+00:00" }, { "name": "utopia-php/websocket", diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 05e31ece94..ced607d9ca 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -1,24 +1,400 @@ -# Dev tools for local development only. -# This file is automatically loaded by `docker compose` alongside docker-compose.yml. -# CI sets COMPOSE_FILE=docker-compose.yml explicitly, so these services are excluded from test runs. - services: + appwrite: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - ./docker-compose.yml:/usr/src/code/docker-compose.yml + - ./.env:/usr/src/code/.env + - ./phpunit.xml:/usr/src/code/phpunit.xml + - ./tests:/usr/src/code/tests + - ./app:/usr/src/code/app + - ./docs:/usr/src/code/docs + - ./public:/usr/src/code/public + - ./src:/usr/src/code/src + - ./dev:/usr/src/code/dev + depends_on: + - coredns + ports: + - 9501:80 + dns: + - 127.0.0.11 + - 172.16.238.100 + entrypoint: + - php + - -e + - app/http.php + environment: + - _APP_MESSAGE_SMS_TEST_DSN + - _APP_MESSAGE_EMAIL_TEST_DSN + - _APP_MESSAGE_PUSH_TEST_DSN + - _TESTS_OAUTH2_GITHUB_CLIENT_ID + - _TESTS_OAUTH2_GITHUB_CLIENT_SECRET + appwrite-realtime: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + ports: + - 9502:80 + appwrite-worker-audits: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + appwrite-worker-webhooks: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + depends_on: + - request-catcher-sms + - request-catcher-webhook + appwrite-worker-deletes: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + appwrite-worker-databases: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + appwrite-worker-builds: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + appwrite-worker-screenshots: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + appwrite-worker-certificates: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + appwrite-worker-executions: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + appwrite-worker-functions: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + appwrite-worker-mails: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + depends_on: + - maildev + appwrite-worker-notifications: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + depends_on: + - maildev + appwrite-worker-messaging: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + appwrite-worker-migrations: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + - ./tests:/usr/src/code/tests + appwrite-task-maintenance: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + appwrite-task-interval: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + appwrite-task-stats-resources: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + appwrite-worker-stats-resources: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + appwrite-worker-stats-usage: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + appwrite-task-scheduler-functions: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + appwrite-task-scheduler-executions: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + appwrite-task-scheduler-messages: + build: + context: . + target: development + args: + DEBUG: false + TESTING: true + VERSION: dev + image: appwrite-dev + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + coredns: + image: coredns/coredns:1.12.4 + container_name: appwrite-coredns + restart: unless-stopped + logging: + driver: json-file + options: + max-file: "5" + max-size: 10m + command: + - -conf + - /mnt/resources/Corefile + networks: + appwrite: + ipv4_address: 172.16.238.100 + volumes: + - ./tests/resources/coredns:/mnt/resources:ro + maildev: + image: appwrite/mailcatcher:1.1.1 + container_name: appwrite-mailcatcher + logging: + driver: json-file + options: + max-file: "5" + max-size: 10m + ports: + - 9503:1080 + networks: + - appwrite + - gateway + labels: + - traefik.enable=true + - traefik.constraint-label-stack=appwrite + - traefik.docker.network=gateway + - traefik.http.services.appwrite_maildev.loadbalancer.server.port=1080 + - traefik.http.routers.appwrite_maildev_http.entrypoints=appwrite_web + - traefik.http.routers.appwrite_maildev_http.rule=Host(`mail.localhost`) + - traefik.http.routers.appwrite_maildev_http.service=appwrite_maildev + - traefik.http.routers.appwrite_maildev_https.entrypoints=appwrite_websecure + - traefik.http.routers.appwrite_maildev_https.rule=Host(`mail.localhost`) + - traefik.http.routers.appwrite_maildev_https.service=appwrite_maildev + - traefik.http.routers.appwrite_maildev_https.tls=true + environment: + - MAILDEV_INCOMING_USER=${_APP_SMTP_USERNAME} + - MAILDEV_INCOMING_PASS=${_APP_SMTP_PASSWORD} + request-catcher-webhook: + image: appwrite/requestcatcher:1.1.0 + container_name: appwrite-requestcatcher-webhook + logging: + driver: json-file + options: + max-file: "5" + max-size: 10m + ports: + - 9504:5000 + networks: + - appwrite + request-catcher-sms: + image: appwrite/requestcatcher:1.1.0 + container_name: appwrite-requestcatcher-sms + logging: + driver: json-file + options: + max-file: "5" + max-size: 10m + ports: + - 9507:5000 + networks: + - appwrite appwrite-mongo-express: - profiles: ["mongodb"] + profiles: + - mongodb image: mongo-express container_name: appwrite-mongo-express networks: - appwrite ports: - - "8082:8081" + - "9508:8081" environment: - ME_CONFIG_MONGODB_URL: "mongodb://root:${_APP_DB_ROOT_PASS}@appwrite-mongodb:27017/?replicaSet=rs0&directConnection=true" + ME_CONFIG_MONGODB_URL: mongodb://root:${_APP_DB_ROOT_PASS}@appwrite-mongodb:27017/?replicaSet=rs0&directConnection=true ME_CONFIG_BASICAUTH_USERNAME: ${_APP_DB_USER} ME_CONFIG_BASICAUTH_PASSWORD: ${_APP_DB_PASS} depends_on: mongodb: condition: service_healthy - adminer: image: adminer container_name: appwrite-adminer @@ -37,20 +413,19 @@ services: configs: - source: adminer-index.php target: /var/www/html/index.php - mode: 0755 + mode: 493 labels: - - "traefik.enable=true" - - "traefik.constraint-label-stack=appwrite" - - "traefik.docker.network=gateway" - - "traefik.http.services.appwrite_adminer.loadbalancer.server.port=8080" - - "traefik.http.routers.appwrite_adminer_http.entrypoints=appwrite_web" - - "traefik.http.routers.appwrite_adminer_http.rule=Host(`mysql.localhost`)" - - "traefik.http.routers.appwrite_adminer_http.service=appwrite_adminer" - - "traefik.http.routers.appwrite_adminer_https.entrypoints=appwrite_websecure" - - "traefik.http.routers.appwrite_adminer_https.rule=Host(`mysql.localhost`)" - - "traefik.http.routers.appwrite_adminer_https.service=appwrite_adminer" - - "traefik.http.routers.appwrite_adminer_https.tls=true" - + - traefik.enable=true + - traefik.constraint-label-stack=appwrite + - traefik.docker.network=gateway + - traefik.http.services.appwrite_adminer.loadbalancer.server.port=8080 + - traefik.http.routers.appwrite_adminer_http.entrypoints=appwrite_web + - traefik.http.routers.appwrite_adminer_http.rule=Host(`mysql.localhost`) + - traefik.http.routers.appwrite_adminer_http.service=appwrite_adminer + - traefik.http.routers.appwrite_adminer_https.entrypoints=appwrite_websecure + - traefik.http.routers.appwrite_adminer_https.rule=Host(`mysql.localhost`) + - traefik.http.routers.appwrite_adminer_https.service=appwrite_adminer + - traefik.http.routers.appwrite_adminer_https.tls=true redis-insight: image: redis/redisinsight:latest restart: unless-stopped @@ -62,22 +437,21 @@ services: configs: - source: redisinsight-connections.json target: /mnt/connections.json - mode: 0755 + mode: 493 labels: - - "traefik.enable=true" - - "traefik.constraint-label-stack=appwrite" - - "traefik.docker.network=gateway" - - "traefik.http.services.appwrite_redisinsight.loadbalancer.server.port=5540" - - "traefik.http.routers.appwrite_redisinsight_http.entrypoints=appwrite_web" - - "traefik.http.routers.appwrite_redisinsight_http.rule=Host(`redis.localhost`)" - - "traefik.http.routers.appwrite_redisinsight_http.service=appwrite_redisinsight" - - "traefik.http.routers.appwrite_redisinsight_https.entrypoints=appwrite_websecure" - - "traefik.http.routers.appwrite_redisinsight_https.rule=Host(`redis.localhost`)" - - "traefik.http.routers.appwrite_redisinsight_https.service=appwrite_redisinsight" - - "traefik.http.routers.appwrite_redisinsight_https.tls=true" + - traefik.enable=true + - traefik.constraint-label-stack=appwrite + - traefik.docker.network=gateway + - traefik.http.services.appwrite_redisinsight.loadbalancer.server.port=5540 + - traefik.http.routers.appwrite_redisinsight_http.entrypoints=appwrite_web + - traefik.http.routers.appwrite_redisinsight_http.rule=Host(`redis.localhost`) + - traefik.http.routers.appwrite_redisinsight_http.service=appwrite_redisinsight + - traefik.http.routers.appwrite_redisinsight_https.entrypoints=appwrite_websecure + - traefik.http.routers.appwrite_redisinsight_https.rule=Host(`redis.localhost`) + - traefik.http.routers.appwrite_redisinsight_https.service=appwrite_redisinsight + - traefik.http.routers.appwrite_redisinsight_https.tls=true ports: - - "8081:5540" - + - "9514:5540" graphql-explorer: container_name: appwrite-graphql-explorer image: appwrite/altair:0.3.0 @@ -85,10 +459,51 @@ services: networks: - appwrite ports: - - "9509:3000" + - 9509:3000 environment: - - SERVER_URL=http://localhost/v1/graphql - + - SERVER_URL=http://localhost:9520/v1/graphql + traefik: + command: + - --providers.file.directory=/storage/config + - --providers.file.watch=true + - --providers.docker=true + - --providers.docker.exposedByDefault=false + - --providers.docker.constraints=Label(`traefik.constraint-label-stack`,`appwrite`) + - --entrypoints.appwrite_web.address=:80 + - --entrypoints.appwrite_websecure.address=:443 + - --log.level=DEBUG + - --api.insecure=true + - --accesslog=true + ports: + - 9520:80 + - 9522:80 + - 9521:443 + - 9500:8080 + networks: + appwrite: + aliases: + - appwrite.test + gateway: + aliases: + - appwrite.test + runtimes: + aliases: + - appwrite.test + mariadb: + ports: + - "9510:3306" + mongodb: + ports: + - "9511:27017" + postgresql: + ports: + - "9512:5432" + redis: + ports: + - "9513:6379" + appwrite-embedding: + ports: + - "9505:3000" configs: redisinsight-connections.json: content: | @@ -129,7 +544,6 @@ configs: "tags": [] } ] - adminer-index.php: content: | /dev/null"] + test: + - CMD-SHELL + - 'curl -fsS -H "Authorization: Bearer $$OPR_EXECUTOR_SECRET" http://localhost/v1/health + >/dev/null' interval: 5s timeout: 3s retries: 20 start_period: 5s - mariadb: - image: mariadb:10.11 # fix issues when upgrading using: mysql_upgrade -u root -p + image: mariadb:10.11 container_name: appwrite-mariadb - <<: *x-logging + logging: + driver: json-file + options: + max-file: "5" + max-size: 10m networks: - appwrite volumes: - appwrite-mariadb:/var/lib/mysql:rw - ports: - - "3306:3306" environment: - MYSQL_ROOT_PASSWORD=${_APP_DB_ROOT_PASS} - MYSQL_DATABASE=${_APP_DB_SCHEMA} - MYSQL_USER=${_APP_DB_USER} - MYSQL_PASSWORD=${_APP_DB_PASS} - MARIADB_AUTO_UPGRADE=1 - command: "mysqld --innodb-flush-method=fsync" + command: + - mysqld + - --innodb-flush-method=fsync healthcheck: - test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"] + test: + - CMD + - healthcheck.sh + - --connect + - --innodb_initialized interval: 5s timeout: 5s retries: 12 - mongodb: image: mongo:8.2.5 container_name: appwrite-mongodb - <<: *x-logging + logging: + driver: json-file + options: + max-file: "5" + max-size: 10m restart: on-failure:3 networks: - appwrite @@ -1340,15 +1296,15 @@ services: - appwrite-mongodb-keyfile:/data/keyfile - ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro - ./mongo-entrypoint.sh:/mongo-entrypoint.sh:ro - ports: - - "27017:27017" environment: - MONGO_INITDB_ROOT_USERNAME=root - MONGO_INITDB_ROOT_PASSWORD=${_APP_DB_ROOT_PASS} - MONGO_INITDB_DATABASE=${_APP_DB_SCHEMA} - MONGO_INITDB_USERNAME=${_APP_DB_USER} - MONGO_INITDB_PASSWORD=${_APP_DB_PASS} - entrypoint: ["/bin/bash", "/mongo-entrypoint.sh"] + entrypoint: + - /bin/bash + - /mongo-entrypoint.sh healthcheck: test: | bash -c " @@ -1371,167 +1327,96 @@ services: timeout: 10s retries: 10 start_period: 30s - postgresql: image: appwrite/postgres:0.1.0 container_name: appwrite-postgresql - <<: *x-logging + logging: + driver: json-file + options: + max-file: "5" + max-size: 10m networks: - appwrite volumes: - appwrite-postgresql:/var/lib/postgresql/18/data:rw - ports: - - "5432:5432" environment: - POSTGRES_DB=${_APP_DB_SCHEMA} - POSTGRES_USER=${_APP_DB_USER} - POSTGRES_PASSWORD=${_APP_DB_PASS} healthcheck: - test: ["CMD-SHELL", "pg_isready -U ${_APP_DB_USER} -d ${_APP_DB_SCHEMA}"] + test: + - CMD-SHELL + - pg_isready -U ${_APP_DB_USER} -d ${_APP_DB_SCHEMA} interval: 5s timeout: 5s retries: 10 start_period: 10s - command: > - postgres - -c fsync=off - -c synchronous_commit=off - -c full_page_writes=off - + command: + - postgres + - -c + - fsync=off + - -c + - synchronous_commit=off + - -c + - full_page_writes=off appwrite-embedding: image: appwrite/embedding:0.1.0 environment: EMBEDDING_MODELS: ${_APP_EMBEDDING_MODELS:-nomic-embed-text} container_name: appwrite-embedding - ports: - - "3000:3000" restart: unless-stopped - # persistent for caching models across restarts and preloading volumes: - appwrite-models:/home/embedder/models networks: - appwrite - redis: image: redis:7.4.7-alpine - <<: *x-logging + logging: + driver: json-file + options: + max-file: "5" + max-size: 10m container_name: appwrite-redis - command: > - redis-server - --maxmemory 512mb - --maxmemory-policy allkeys-lru - --maxmemory-samples 5 - ports: - - "6379:6379" + command: + - redis-server + - --maxmemory + - 512mb + - --maxmemory-policy + - allkeys-lru + - --maxmemory-samples + - "5" networks: - appwrite volumes: - appwrite-redis:/data:rw healthcheck: - test: ["CMD", "redis-cli", "ping"] + test: + - CMD + - redis-cli + - ping interval: 5s timeout: 5s retries: 12 - - coredns: # DNS server for testing purposes (Proxy APIs) - image: coredns/coredns:1.12.4 - container_name: appwrite-coredns - restart: unless-stopped - <<: *x-logging - command: ["-conf", "/mnt/resources/Corefile"] - # If you need to debug CoreDNS, do it from "appwrite container", or port forward: - # ports: - # - "53:53" - networks: - appwrite: - ipv4_address: 172.16.238.100 - volumes: - - ./tests/resources/coredns:/mnt/resources:ro - - # Dev Tools Start ------------------------------------------------------------------------------------------ - # - # The Appwrite Team uses the following tools to help debug, monitor and diagnose the Appwrite stack - # - # Here is a description of the different tools and why are we using them: - # - # MailCatcher - An SMTP server. Catches all system emails and displays them in a nice UI. - # RequestCatcher - An HTTP server. Catches all system https calls and displays them using a simple HTTP API. Used to debug & tests webhooks and HTTP tasks - # Redis Insight - A nice UI for exploring Redis data - # Adminer - A nice UI for exploring MariaDB data - # GraphQl Explorer - A nice UI for exploring GraphQL API - - maildev: # used mainly for dev tests - image: appwrite/mailcatcher:1.1.1 - container_name: appwrite-mailcatcher - <<: *x-logging - ports: - - "9503:1080" - networks: - - appwrite - - gateway - labels: - - "traefik.enable=true" - - "traefik.constraint-label-stack=appwrite" - - "traefik.docker.network=gateway" - - "traefik.http.services.appwrite_maildev.loadbalancer.server.port=1080" - - "traefik.http.routers.appwrite_maildev_http.entrypoints=appwrite_web" - - "traefik.http.routers.appwrite_maildev_http.rule=Host(`mail.localhost`)" - - "traefik.http.routers.appwrite_maildev_http.service=appwrite_maildev" - - "traefik.http.routers.appwrite_maildev_https.entrypoints=appwrite_websecure" - - "traefik.http.routers.appwrite_maildev_https.rule=Host(`mail.localhost`)" - - "traefik.http.routers.appwrite_maildev_https.service=appwrite_maildev" - - "traefik.http.routers.appwrite_maildev_https.tls=true" - environment: - - MAILDEV_INCOMING_USER=${_APP_SMTP_USERNAME} - - MAILDEV_INCOMING_PASS=${_APP_SMTP_PASSWORD} - - request-catcher-webhook: # used mainly for dev tests (mock HTTP webhook) - image: appwrite/requestcatcher:1.1.0 - container_name: appwrite-requestcatcher-webhook - <<: *x-logging - ports: - - "9504:5000" - networks: - - appwrite - - request-catcher-sms: # used mainly for dev tests (mock SMS auth secret) - image: appwrite/requestcatcher:1.1.0 - container_name: appwrite-requestcatcher-sms - <<: *x-logging - ports: - - "9507:5000" - networks: - - appwrite - - # Dev tools (adminer, redis-insight, mongo-express, graphql-explorer) - # are defined in docker-compose.override.yml - networks: gateway: name: gateway appwrite: name: appwrite - ipam: - config: - - subnet: 172.16.238.0/24 runtimes: name: runtimes - - - volumes: - appwrite-mariadb: - appwrite-mongodb: - appwrite-mongodb-keyfile: - appwrite-postgresql: - appwrite-redis: - appwrite-cache: - appwrite-uploads: - appwrite-imports: - appwrite-certificates: - appwrite-functions: - appwrite-sites: - appwrite-builds: - appwrite-config: - appwrite-models: - openruntimes-node-modules-cache: + appwrite-mariadb: null + appwrite-mongodb: null + appwrite-mongodb-keyfile: null + appwrite-postgresql: null + appwrite-redis: null + appwrite-cache: null + appwrite-uploads: null + appwrite-imports: null + appwrite-certificates: null + appwrite-functions: null + appwrite-sites: null + appwrite-builds: null + appwrite-config: null + appwrite-models: null + openruntimes-node-modules-cache: null diff --git a/docs/references/projects/list-stages.md b/docs/references/projects/list-stages.md new file mode 100644 index 0000000000..3a2f6cc401 --- /dev/null +++ b/docs/references/projects/list-stages.md @@ -0,0 +1 @@ +Get the onboarding stages for the current project, including each stage’s SDK method key and status (for example pending, completed, or skipped). diff --git a/docs/references/projects/update-stage.md b/docs/references/projects/update-stage.md new file mode 100644 index 0000000000..9e6f43919e --- /dev/null +++ b/docs/references/projects/update-stage.md @@ -0,0 +1 @@ +Update an onboarding stage for the current project. Use this endpoint to skip a stage or leave it unchanged without performing the related API action. diff --git a/docs/sdks/cli/GETTING_STARTED.md b/docs/sdks/cli/GETTING_STARTED.md index 1cadb1bbda..8b907d298a 100644 --- a/docs/sdks/cli/GETTING_STARTED.md +++ b/docs/sdks/cli/GETTING_STARTED.md @@ -9,7 +9,7 @@ $ appwrite login ? Enter your password ******** ✓ Success ``` -This will also prompt you to enter your Appwrite endpoint ( default: http://localhost/v1 ) +This will also prompt you to enter your Appwrite endpoint ( default: http://localhost:9520/v1 ) * ### Initialising your project Once logged in, the CLI needs to be initialised before you can use it with your Appwrite project. You can do this with the `appwrite init project` command. @@ -139,5 +139,5 @@ $ appwrite client --reset The Appwrite CLI can also work in a CI environment. The initialisation of the CLI works a bit differently in CI. In CI, you set your `endpoint`, `projectId` and `API Key` using ```sh -appwrite client --endpoint http://localhost/v1 --projectId --key +appwrite client --endpoint http://localhost:9520/v1 --projectId --key ``` diff --git a/docs/sdks/deno/CHANGELOG.md b/docs/sdks/deno/CHANGELOG.md deleted file mode 100644 index 4319fb6d59..0000000000 --- a/docs/sdks/deno/CHANGELOG.md +++ /dev/null @@ -1,29 +0,0 @@ -# Change Log - -## 16.0.0 - -* Add array-based enum parameters (e.g., `permissions: BrowserPermission[]`). -* Breaking change: `Output` enum has been removed; use `ImageFormat` instead. -* Add `getQueueAudits` support to `Health` service. -* Add longtext/mediumtext/text/varchar attribute and column helpers to `Databases` and `TablesDB` services. - -## 15.1.0 - -* Add `incrementDocumentAttribute` and `decrementDocumentAttribute` support to `Databases` service -* Add `gif` support to `ImageFormat` enum -* Add `dart38` and `flutter332` support to runtime models -* Add `encrypt` support to `StringAttribute` model -* Add `sequence` support to `Document` model -* Add `upsertDocument` support to `Databases` service - -## 15.0.0 - -* Add `` to doc examples due to the new multi region endpoints -* Add doc examples and methods for bulk api transactions: `createDocuments`, `deleteDocuments` etc. -* Add doc examples, class and methods for new `Sites` service -* Add doc examples, class and methods for new `Tokens` service -* Add enums for `BuildRuntime `, `Adapter`, `Framework`, `DeploymentDownloadType` and `VCSDeploymentType` -* Updates enum for `runtimes` with Pythonml312, Dart219, Flutter327 and Flutter329 -* Add `token` param to `getFilePreview` and `getFileView` for File tokens usage -* Add `queries` and `search` params to `listMemberships` method -* Removes `search` param from `listExecutions` method \ No newline at end of file diff --git a/docs/sdks/deno/GETTING_STARTED.md b/docs/sdks/deno/GETTING_STARTED.md deleted file mode 100644 index 5046d61c74..0000000000 --- a/docs/sdks/deno/GETTING_STARTED.md +++ /dev/null @@ -1,68 +0,0 @@ -## Getting Started - -### Init your SDK - -Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page and your new API secret Key from project's API keys section. - -```typescript -let client = new sdk.Client(); - -client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key - .setSelfSigned() // Use only on dev mode with a self-signed SSL cert -; -``` - -### Make your first request - -Once your SDK object is set, create any of the Appwrite service objects and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the [API References](https://appwrite.io/docs) section. - -```typescript -let users = new sdk.Users(client); - -let user = await users.create(ID.unique(), "email@example.com", "+123456789", "password", "Walter O'Brien"); -console.log(user); -``` - -### Full Example - -```typescript -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; - -let client = new sdk.Client(); -let users = new sdk.Users(client); - -client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key - .setSelfSigned() // Use only on dev mode with a self-signed SSL cert -; - -let user = await users.create(ID.unique(), "email@example.com", "+123456789", "password", "Walter O'Brien"); -console.log(user); -``` - -### Error Handling - -The Appwrite Deno SDK raises `AppwriteException` object with `message`, `code` and `response` properties. You can handle any errors by catching `AppwriteException` and present the `message` to the user or handle it yourself based on the provided error information. Below is an example. - -```typescript -let users = new sdk.Users(client); - -try { - let user = await users.create(ID.unique(), "email@example.com", "+123456789", "password", "Walter O'Brien"); -} catch(e) { - console.log(e.message); -} -``` - -### Learn more - -You can use the following resources to learn more and get help -- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/getting-started-for-server) -- 📜 [Appwrite Docs](https://appwrite.io/docs) -- 💬 [Discord Community](https://appwrite.io/discord) -- 🚂 [Appwrite Deno Playground](https://github.com/appwrite/playground-for-deno) diff --git a/docs/sdks/flutter-dev/CHANGELOG.md b/docs/sdks/flutter-dev/CHANGELOG.md deleted file mode 100644 index 9b6bb58c41..0000000000 --- a/docs/sdks/flutter-dev/CHANGELOG.md +++ /dev/null @@ -1,66 +0,0 @@ -## 0.3.2 - -- Fixed package namespaces -- Breaking change: `Output` enum has been removed; use `ImageFormat` instead. -- Add `Channel` helpers for Realtime. - -## 0.3.1 - -- Downgraded meta package version to 1.1.8 - -## 0.3.0 - -- Updated package dependencies (@lohanidamodar) -- Added Flutter for Web compatibility (@lohanidamodar) - -## 0.2.3 - -- Fixed OAuth2 cookie bug, where a new session cookie couldn't overwrite an old cookie - -## 0.2.2 - -- Fixed an error that happened when the OAuth session creation request was sent before any other API call -- Fixed a bug in the Avatars service where location URL generation had syntax error - -## 0.2.1 - -- Fixed callback scheme - -## 0.2.0 - -- Updated flutter_web_auth plugin to version 0.2.4 -- Added per project unique callback for OAuth2 redirects to avoid conflicts between multiple Appwrite projects - -## 0.1.1 - -- Updated flutter_web_auth version - -## 0.1.0 - -- Added examples file -- Some minor style fixes - -## 0.0.14 - -- Using MultipartFile for file uploads - -## 0.0.13 - -- Fix for file upload method - -## 0.0.12 - -- Added file upload support for storage service - -## 0.0.11 - -- Added integration with web auth plugin to support Appwrite OAuth API - -## 0.0.9 - -- Updated default params - -## 0.0.8 - -- Fixed compilation error in Client class -- Shorter description for package diff --git a/docs/sdks/flutter-dev/EXAMPLES.md b/docs/sdks/flutter-dev/EXAMPLES.md deleted file mode 100644 index d0cb0c2b2a..0000000000 --- a/docs/sdks/flutter-dev/EXAMPLES.md +++ /dev/null @@ -1,63 +0,0 @@ -# Examples - -Init your Appwrite client: - -```dart -Client client = Client(); - -client - .setEndpoint('https://localhost/v1') // Your Appwrite Endpoint - .setProject('5e8cf4f46b5e8') // Your project ID - .setSelfSigned() // Remove in production -; -``` - -Create a new user and session: - -```dart -Account account = Account(client); - -final user = await account.create(userId: ID.unique(), email: "email@example.com", password: "password", name: "Walter O'Brien"); - -final session = await account.createEmailSession(email: 'me@appwrite.io', password: 'password'); - -``` - -Fetch user profile: - -```dart -Account account = Account(client); - -final profile = await account.get(); -``` - -Upload File: - -```dart -Storage storage = Storage(client); - -late InputFile file; - -if(kIsWeb) { - file = InputFile(bytes: pickedFile.bytes, filename: 'image.jpg'); -} else { - file = InputFile(path: './path-to-file/image.jpg', filename: 'image.jpg'); -} - -storage.createFile( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', // use 'unique()' to automatically generate a unique ID - file: file, - permissions: [ - Permission.read(Role.any()), - ], -) -.then((response) { - print(response); // File uploaded! -}) -.catchError((error) { - print(error.response); -}); -``` - -All examples and API features are available at the [official Appwrite docs](https://appwrite.io/docs) diff --git a/docs/sdks/flutter/EXAMPLES.md b/docs/sdks/flutter/EXAMPLES.md index d0cb0c2b2a..36537cbf18 100644 --- a/docs/sdks/flutter/EXAMPLES.md +++ b/docs/sdks/flutter/EXAMPLES.md @@ -6,7 +6,7 @@ Init your Appwrite client: Client client = Client(); client - .setEndpoint('https://localhost/v1') // Your Appwrite Endpoint + .setEndpoint('https://localhost:9521/v1') // Your Appwrite Endpoint .setProject('5e8cf4f46b5e8') // Your project ID .setSelfSigned() // Remove in production ; diff --git a/docs/sdks/objective-c/CHANGELOG.md b/docs/sdks/objective-c/CHANGELOG.md deleted file mode 100644 index 420e6f23d0..0000000000 --- a/docs/sdks/objective-c/CHANGELOG.md +++ /dev/null @@ -1 +0,0 @@ -# Change Log diff --git a/docs/sdks/react-native/GETTING_STARTED.md b/docs/sdks/react-native/GETTING_STARTED.md index a5c6f57c46..08b5c2f266 100644 --- a/docs/sdks/react-native/GETTING_STARTED.md +++ b/docs/sdks/react-native/GETTING_STARTED.md @@ -34,7 +34,7 @@ import { Client } from 'react-native-appwrite'; const client = new Client(); client - .setEndpoint('http://localhost/v1') // Your Appwrite Endpoint + .setEndpoint('http://localhost:9520/v1') // Your Appwrite Endpoint .setProject('455x34dfkj') // Your project ID .setPlatform('com.example.myappwriteapp') // Your application ID or bundle ID. ; @@ -65,7 +65,7 @@ import { Client, Account } from 'react-native-appwrite'; const client = new Client(); client - .setEndpoint('http://localhost/v1') // Your Appwrite Endpoint + .setEndpoint('http://localhost:9520/v1') // Your Appwrite Endpoint .setProject('455x34dfkj') .setPlatform('com.example.myappwriteapp') // YOUR application ID ; diff --git a/docs/sdks/web/GETTING_STARTED.md b/docs/sdks/web/GETTING_STARTED.md index cc75a3d3e5..db02a8428d 100644 --- a/docs/sdks/web/GETTING_STARTED.md +++ b/docs/sdks/web/GETTING_STARTED.md @@ -15,7 +15,7 @@ Initialize your SDK with your Appwrite server API endpoint and project ID which const client = new Client(); client - .setEndpoint('http://localhost/v1') // Your Appwrite Endpoint + .setEndpoint('http://localhost:9520/v1') // Your Appwrite Endpoint .setProject('455x34dfkj') // Your project ID ; ``` @@ -44,7 +44,7 @@ account.create(ID.unique(), "email@example.com", "password", "Walter O'Brien") const client = new Client(); client - .setEndpoint('http://localhost/v1') // Your Appwrite Endpoint + .setEndpoint('http://localhost:9520/v1') // Your Appwrite Endpoint .setProject('455x34dfkj') ; diff --git a/docs/tutorials/add-environment-variable.md b/docs/tutorials/add-environment-variable.md index 5116908580..7fdd416642 100644 --- a/docs/tutorials/add-environment-variable.md +++ b/docs/tutorials/add-environment-variable.md @@ -24,11 +24,11 @@ This information is also used to generate the website documentation at https://a If the newly introduced environment variable has a default value, add it to the `.env` and `Dockerfile` along with other environment variables. `.env` file uses settings for Appwrite development environment. -### Add to Docker Compose file and template +### Add to Docker Compose file -Add the new environment variables to the `docker-compose.yml` and `app/views/install/compose.phtml` for each docker service that requires access to those environment variables. +Add the new environment variables to `docker-compose.yml` for each Docker service that requires access to those environment variables. -The `docker-compose.yml` file is used by the Appwrite maintainers during development, whereas the `app/views/install/compose.phtml` file is used by the Appwrite setup script. +The setup script generates the install compose file from `docker-compose.yml`, so changes should be made in the base compose file instead of a separate template. Run `npm run format:compose` after editing compose files. With these steps, your environment variable is properly added and can be accessed inside Appwrite code and any other containers where it is passed. You can access and use those variables to implement the features you are trying to achieve. diff --git a/docs/tutorials/add-translations.md b/docs/tutorials/add-translations.md index 68023fcf8b..ef56336799 100644 --- a/docs/tutorials/add-translations.md +++ b/docs/tutorials/add-translations.md @@ -149,13 +149,13 @@ First of all, we need to start a local instance of Appwrite. Thanks to Docker, t docker compose up -d ``` -If this is your first time running Appwrite, it may take up to a few minutes to download all images and start all containers. Once everything is started, you should see Appwrite running on `http://localhost:80`. When you visit this URL, it will ask you to sign up. After that, it will show you your empty dashboard where you need to create a new project - give it any name you want. Then you need to go to `Settings` of the project and copy `Project-ID`. +If this is your first time running Appwrite, it may take up to a few minutes to download all images and start all containers. Once everything is started, you should see Appwrite running on `http://localhost:9520`. When you visit this URL, it will ask you to sign up. After that, it will show you your empty dashboard where you need to create a new project - give it any name you want. Then you need to go to `Settings` of the project and copy `Project-ID`. If you are lost in the Appwrite dashboard, check out our [Article about Appwrite's dashboard](https://dev.to/appwrite/30daysofappwrite-appwrite-dashboard-15cc). Now, let's send the request. We will be editing headers of the request, so you will need a tool to do that, such as Postman or Insomnia. -First, let's see English translations. Let's set request type to `GET`, URL to `https://localhost/v1/locale/countries/eu` and add `X-Appwrite-Project` header. +First, let's see English translations. Let's set request type to `GET`, URL to `https://localhost:9521/v1/locale/countries/eu` and add `X-Appwrite-Project` header. ![English test](images/test-en.png) diff --git a/package-lock.json b/package-lock.json index 6ab33b14fe..138de0201d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,7 +4,26 @@ "requires": true, "packages": { "": { - "name": "@appwrite.io/repo" + "name": "@appwrite.io/repo", + "devDependencies": { + "prettier": "^3.9.0" + } + }, + "node_modules/prettier": { + "version": "3.9.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.9.0.tgz", + "integrity": "sha512-LjIqSIC5VYLzs9WedVmJ2ljNAGnU+DteIClbahu4L/DBeWjZ6iT/k1lAYyu9JUh+1xINxWadaPw/Pl63y/agAw==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } } } } diff --git a/package.json b/package.json index 1e2b1be430..9dfab20a21 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,15 @@ "type": "git", "url": "git+https://github.com/appwrite/appwrite.git" }, + "scripts": { + "format:compose": "prettier --write docker-compose.yml docker-compose.override.yml", + "lint:compose": "prettier --check docker-compose.yml docker-compose.override.yml" + }, "files": [ "docs/examples", "app/config/specs" - ] + ], + "devDependencies": { + "prettier": "^3.9.0" + } } diff --git a/src/Appwrite/Docker/Compose/Generator.php b/src/Appwrite/Docker/Compose/Generator.php new file mode 100644 index 0000000000..f982d80178 --- /dev/null +++ b/src/Appwrite/Docker/Compose/Generator.php @@ -0,0 +1,290 @@ + [ + 'default' => 'mongodb', + 'services' => [ + 'mariadb', + 'mongodb', + 'postgresql', + ], + ], + ]; + + private const array SELECTABLE_VOLUME_GROUPS = [ + 'database' => [ + 'mariadb' => ['appwrite-mariadb'], + 'mongodb' => ['appwrite-mongodb', 'appwrite-mongodb-keyfile'], + 'postgresql' => ['appwrite-postgresql'], + ], + ]; + + private const array OPTIONAL_SERVICES = [ + 'enableAssistant' => 'appwrite-assistant', + ]; + + private const array LOCAL_VOLUME_PREPENDS = [ + 'appwrite' => [ + 'param' => 'hostPath', + 'volume' => '{hostPath}:/usr/src/code:rw', + ], + ]; + + private const array PARAM_DEFAULTS = [ + 'version' => 'latest', + 'database' => 'mongodb', + 'hostPath' => '', + 'enableAssistant' => false, + ]; + + private const array DEPENDENCY_SELECTORS = [ + 'database' => [ + 'param' => 'database', + 'condition' => [ + 'condition' => 'service_healthy', + ], + 'placeholders' => [ + '${_APP_DB_HOST:-mongodb}', + '${_APP_DB_HOST:-mariadb}', + ], + ], + ]; + + private const array YAML_DOCUMENT_MARKER_PATTERNS = [ + '/^---\R/', + '/\R\\.\\.\\.\R?$/', + ]; + + /** + * @var array + */ + private array $compose; + + /** + * @var array + */ + private array $params = []; + + private array $selectableServices = [ + 'mariadb', + 'mongodb', + 'postgresql', + ]; + + public function __construct(string $compose) + { + $parsed = \yaml_parse($compose); + + if (!\is_array($parsed)) { + throw new Exception('Failed to parse Docker Compose file'); + } + + $this->compose = $parsed; + } + + /** + * @param array $params + */ + public function render(array $params): string + { + $compose = $this->compose; + $this->params = $this->normalizeParams($params); + $this->selectableServices = $this->getSelectableServices(); + + $compose['services'] = $this->filterServices($compose['services'] ?? []); + $compose['volumes'] = $this->filterVolumes($compose['volumes'] ?? []); + + foreach ($compose['services'] as $name => &$service) { + if (!\is_array($service)) { + continue; + } + + $this->rewriteDependencies($service); + $this->rewriteLocalVolumes($name, $service); + } + unset($service); + + return $this->emit($compose); + } + + /** + * @param array $params + * @return array + */ + private function normalizeParams(array $params): array + { + $params = \array_merge(self::PARAM_DEFAULTS, $params); + + foreach (self::SELECTABLE_SERVICE_GROUPS as $param => $config) { + if (!\in_array($params[$param], $config['services'], true)) { + $params[$param] = $config['default']; + } + } + + $params['hostPath'] = \rtrim((string)$params['hostPath'], '/'); + + return $params; + } + + /** + * @return string[] + */ + private function getSelectableServices(): array + { + $services = []; + + foreach (self::SELECTABLE_SERVICE_GROUPS as $config) { + $services = \array_merge($services, $config['services']); + } + + return \array_values(\array_unique($services)); + } + + /** + * @param array $services + * @return array + */ + private function filterServices(array $services): array + { + foreach (self::SELECTABLE_SERVICE_GROUPS as $param => $config) { + foreach ($config['services'] as $service) { + if ($service !== $this->params[$param]) { + unset($services[$service]); + } + } + } + + foreach (self::OPTIONAL_SERVICES as $param => $service) { + if (empty($this->params[$param])) { + unset($services[$service]); + } + } + + return $services; + } + + /** + * @param array $volumes + * @return array + */ + private function filterVolumes(array $volumes): array + { + foreach (self::SELECTABLE_VOLUME_GROUPS as $param => $groups) { + foreach ($groups as $service => $names) { + if ($service === $this->params[$param]) { + continue; + } + + foreach ($names as $name) { + unset($volumes[$name]); + } + } + } + + return $volumes; + } + + /** + * @param array $service + */ + private function rewriteDependencies(array &$service): void + { + if (!isset($service['depends_on'])) { + return; + } + + foreach (self::DEPENDENCY_SELECTORS as $selector) { + $selected = $this->params[$selector['param']]; + $removable = [ + ...$this->selectableServices, + ...$selector['placeholders'], + ]; + + if (\array_is_list($service['depends_on'])) { + $hasSelectedDependency = false; + $dependsOn = \array_values(\array_filter( + $service['depends_on'], + function (mixed $dependency) use ($removable, &$hasSelectedDependency): bool { + if (!\in_array($dependency, $removable, true)) { + return true; + } + + $hasSelectedDependency = true; + + return false; + } + )); + + if ($hasSelectedDependency && !\in_array($selected, $dependsOn, true)) { + $dependsOn[] = $selected; + } + + $service['depends_on'] = $dependsOn; + continue; + } + + $hasSelectedDependency = false; + foreach ($removable as $dependency) { + if (\array_key_exists($dependency, $service['depends_on'])) { + $hasSelectedDependency = true; + } + + unset($service['depends_on'][$dependency]); + } + + if ($hasSelectedDependency) { + $service['depends_on'][$selected] = $selector['condition']; + } + } + } + + /** + * @param array $service + */ + private function rewriteLocalVolumes(string $name, array &$service): void + { + if ($this->params['version'] !== 'local' || !isset(self::LOCAL_VOLUME_PREPENDS[$name])) { + return; + } + + $config = self::LOCAL_VOLUME_PREPENDS[$name]; + if (empty($this->params[$config['param']])) { + return; + } + + $service['volumes'] ??= []; + \array_unshift($service['volumes'], $this->replacePlaceholders($config['volume'])); + } + + /** + * @param array $compose + */ + private function emit(array $compose): string + { + $yaml = \yaml_emit($compose, YAML_UTF8_ENCODING, YAML_LN_BREAK); + + foreach (self::YAML_DOCUMENT_MARKER_PATTERNS as $pattern) { + $yaml = \preg_replace($pattern, '', $yaml) ?? $yaml; + } + + return $yaml; + } + + private function replacePlaceholders(string $value): string + { + foreach ($this->params as $param => $replacement) { + if (\is_scalar($replacement)) { + $value = \str_replace('{' . $param . '}', (string)$replacement, $value); + } + } + + return $value; + } + +} diff --git a/src/Appwrite/Functions/Validator/Headers.php b/src/Appwrite/Functions/Validator/Headers.php index 04003d535b..a18660fa2d 100644 --- a/src/Appwrite/Functions/Validator/Headers.php +++ b/src/Appwrite/Functions/Validator/Headers.php @@ -50,13 +50,17 @@ class Headers extends Validator $size = 0; foreach ($value as $key => $val) { - $length = \strlen($key); // Reject non-string keys - if (!\is_string($key) || $length === 0) { + if (!\is_string($key)) { return false; } - $size += $length + \strlen($val); + $length = \strlen($key); + if ($length === 0) { + return false; + } + + $size += $length + \strlen($val ?? ''); if ($size >= $this->maxSize) { return false; } diff --git a/src/Appwrite/Migration/Version/V24.php b/src/Appwrite/Migration/Version/V24.php index 65da1bd20d..82889f8d79 100644 --- a/src/Appwrite/Migration/Version/V24.php +++ b/src/Appwrite/Migration/Version/V24.php @@ -115,6 +115,12 @@ class V24 extends Migration } catch (Throwable $th) { Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$id}: {$th->getMessage()}"); } + + try { + $this->createIndexFromCollection($this->dbForProject, $id, '_key_teamInternalId'); + } catch (Throwable $th) { + Console::warning("Failed to create index \"_key_teamInternalId\" from {$id}: {$th->getMessage()}"); + } } $this->dbForProject->purgeCachedCollection($id); break; @@ -213,6 +219,15 @@ class V24 extends Migration $this->dbForProject->purgeCachedCollection($id); break; + case 'memberships': + try { + $this->createIndexFromCollection($this->dbForProject, $id, '_key_team_confirm'); + } catch (Throwable $th) { + Console::warning("Failed to create index \"_key_team_confirm\" from {$id}: {$th->getMessage()}"); + } + $this->dbForProject->purgeCachedCollection($id); + break; + case 'tokens': try { $this->createIndexFromCollection($this->dbForProject, $id, '_key_type_expire'); @@ -239,6 +254,8 @@ class V24 extends Migration 'startCommand', 'buildSpecification', 'runtimeSpecification', + 'providerBranches', + 'providerPaths', ]; try { $this->createAttributesFromCollection($this->dbForProject, $id, $attributes); @@ -254,6 +271,8 @@ class V24 extends Migration 'deploymentRetention', 'buildSpecification', 'runtimeSpecification', + 'providerBranches', + 'providerPaths', ]; try { $this->createAttributesFromCollection($this->dbForProject, $id, $attributes); @@ -295,6 +314,32 @@ class V24 extends Migration $this->dbForProject->purgeCachedCollection($id); break; + case 'platforms': + case 'webhooks': + if ($collectionType === 'console') { + try { + $this->createIndexFromCollection($this->dbForProject, $id, '_key_project_id'); + } catch (Throwable $th) { + Console::warning("Failed to create index \"_key_project_id\" from {$id}: {$th->getMessage()}"); + } + } + $this->dbForProject->purgeCachedCollection($id); + break; + + case 'reports': + case 'insights': + if ($collectionType === 'console') { + try { + $this->createCollection($id); + } catch (Throwable $th) { + Console::warning("Failed to create collection \"{$id}\": {$th->getMessage()}"); + + throw $th; + } + } + $this->dbForProject->purgeCachedCollection($id); + break; + case 'providers': try { $this->dbForProject->deleteIndex($id, '_key_name'); diff --git a/src/Appwrite/Platform/Installer/Server.php b/src/Appwrite/Platform/Installer/Server.php index b86db4d93d..06be8a6ad1 100644 --- a/src/Appwrite/Platform/Installer/Server.php +++ b/src/Appwrite/Platform/Installer/Server.php @@ -52,6 +52,10 @@ class Server private const string DEFAULT_IMAGE = 'appwrite-dev'; public const string DEFAULT_CONTAINER = 'appwrite-installer'; + private const string COMPOSE_FILE = 'docker-compose.yml'; + private const string ENV_FILE = '.env'; + private const string LOCAL_COMPOSE_FILE = 'docker-compose.web-installer.yml'; + private const string LOCAL_ENV_FILE = '.env.web-installer'; private State $state; private array $paths = []; @@ -208,8 +212,13 @@ class Server } $basePath = $config->isLocal() ? '/usr/src/code' : (getcwd() ?: '.'); - $composePath = $basePath . '/docker-compose.yml'; - $envPath = $basePath . '/.env'; + if ($config->isLocal()) { + $composePath = $basePath . '/' . self::LOCAL_COMPOSE_FILE; + $envPath = $basePath . '/' . self::LOCAL_ENV_FILE; + } else { + $composePath = $basePath . '/' . self::COMPOSE_FILE; + $envPath = $basePath . '/' . self::ENV_FILE; + } if (!file_exists($composePath) && !file_exists($envPath)) { return; diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Create.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Create.php index cdf8828ab3..6aa13e4cd0 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Create.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Create.php @@ -42,7 +42,6 @@ class Create extends Action ->label('scope', 'account') ->label('audits.event', 'user.update') ->label('audits.resource', 'user/{response.$id}') - ->label('usage.resource', 'user/{response.$id}') ->label('audits.userId', '{response.$id}') ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Delete.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Delete.php index 44bbdfd702..ce0e8d266e 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Delete.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Delete.php @@ -39,7 +39,6 @@ class Delete extends Action ->label('scope', 'account') ->label('audits.event', 'user.update') ->label('audits.resource', 'user/{user.$id}') - ->label('usage.resource', 'user/{user.$id}') ->label('audits.userId', '{user.$id}') ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Update.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Update.php index 0bcfcfb7ba..11f044b507 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Update.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Update.php @@ -41,7 +41,6 @@ class Update extends Action ->label('scope', 'account') ->label('audits.event', 'user.update') ->label('audits.resource', 'user/{response.$id}') - ->label('usage.resource', 'user/{response.$id}') ->label('audits.userId', '{response.$id}') ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php index aae9bcfcd0..da6055fffd 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php @@ -57,7 +57,6 @@ class Create extends Action ->label('event', 'users.[userId].challenges.[challengeId].create') ->label('audits.event', 'challenge.create') ->label('audits.resource', 'user/{response.userId}') - ->label('usage.resource', 'user/{response.userId}') ->label('audits.userId', '{response.userId}') ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Update.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Update.php index 3e16aab2ab..5f6b7a1186 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Update.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Update.php @@ -40,7 +40,6 @@ class Update extends Action ->label('event', 'users.[userId].sessions.[sessionId].create') ->label('audits.event', 'challenges.update') ->label('audits.resource', 'user/{response.userId}') - ->label('usage.resource', 'user/{response.userId}') ->label('audits.userId', '{response.userId}') ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Create.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Create.php index 7d7c1d8e75..0d1191aaea 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Create.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Create.php @@ -36,7 +36,6 @@ class Create extends Action ->label('scope', 'account') ->label('audits.event', 'user.update') ->label('audits.resource', 'user/{response.$id}') - ->label('usage.resource', 'user/{response.$id}') ->label('audits.userId', '{response.$id}') ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Update.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Update.php index 5d7570e61e..40051cfebc 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Update.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Update.php @@ -36,7 +36,6 @@ class Update extends Action ->label('scope', 'account') ->label('audits.event', 'user.update') ->label('audits.resource', 'user/{response.$id}') - ->label('usage.resource', 'user/{response.$id}') ->label('audits.userId', '{response.$id}') ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Update.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Update.php index 6842e99d4e..a578149654 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Update.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Update.php @@ -36,7 +36,6 @@ class Update extends Action ->label('scope', 'account') ->label('audits.event', 'user.update') ->label('audits.resource', 'user/{response.$id}') - ->label('usage.resource', 'user/{response.$id}') ->label('audits.userId', '{response.$id}') ->label('sdk', new Method( namespace: 'account', diff --git a/src/Appwrite/Platform/Modules/Advisor/Http/Reports/Delete.php b/src/Appwrite/Platform/Modules/Advisor/Http/Reports/Delete.php index baa53aa7ca..1efc029c17 100644 --- a/src/Appwrite/Platform/Modules/Advisor/Http/Reports/Delete.php +++ b/src/Appwrite/Platform/Modules/Advisor/Http/Reports/Delete.php @@ -38,7 +38,6 @@ class Delete extends Action ->label('resourceType', RESOURCE_TYPE_REPORTS) ->label('audits.event', 'report.delete') ->label('audits.resource', 'report/{request.reportId}') - ->label('usage.resource', 'report/{request.reportId}') ->label('abuse-key', 'projectId:{projectId},userId:{userId}') ->label('abuse-limit', APP_LIMIT_WRITE_RATE_DEFAULT) ->label('abuse-time', APP_LIMIT_WRITE_RATE_PERIOD_DEFAULT) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php index 4fc251fe51..61c7760eed 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php @@ -45,6 +45,7 @@ class Get extends Action ->desc('Get attribute') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php index 430117188f..6390797407 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php @@ -40,6 +40,7 @@ class XList extends Action ->desc('List attributes') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php index 43364413db..64667f52c0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php @@ -34,6 +34,7 @@ class Get extends Action ->desc('Get collection') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'databases', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php index 763fd86f7b..39e951e100 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php @@ -35,6 +35,7 @@ class Get extends Action ->desc('Get index') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php index c4d70c5fb6..506b45a890 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php @@ -41,6 +41,7 @@ class XList extends Action ->desc('List indexes') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php index 5d1ccbd45f..5731fd9aff 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php @@ -42,6 +42,7 @@ class XList extends Action ->desc('List collections') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'databases', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php index 5ee8e2f5e3..d5e2a3eabf 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php @@ -28,6 +28,7 @@ class Get extends Action ->desc('Get database') ->groups(['api', 'database']) ->label('scope', 'databases.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php index dc20349e7c..d31c2fb48b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php @@ -33,6 +33,7 @@ class Get extends Action ->desc('Get transaction') ->groups(['api', 'database', 'transactions']) ->label('scope', 'rows.read') + ->label('usage.resource', 'transaction/{request.transactionId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'databases', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Documents/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Documents/Get.php index 47d352bf98..ec02abe2aa 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Documents/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Documents/Get.php @@ -33,6 +33,7 @@ class Get extends DocumentGet ->desc('Get document') ->groups(['api', 'database']) ->label('scope', 'documents.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Documents/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Documents/XList.php index 51c0d67e8a..f2da8d262b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Documents/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Documents/XList.php @@ -35,6 +35,7 @@ class XList extends DocumentXList ->desc('List documents') ->groups(['api', 'database']) ->label('scope', 'documents.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Get.php index 53120dd636..d112f919e2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Get.php @@ -31,6 +31,7 @@ class Get extends CollectionGet ->desc('Get collection') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/Get.php index 7fa75b6ed9..567abaefed 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/Get.php @@ -32,6 +32,7 @@ class Get extends IndexGet ->desc('Get index') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/XList.php index 1e16155f76..93ffb8fb55 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/XList.php @@ -33,6 +33,7 @@ class XList extends IndexXList ->desc('List indexes') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/XList.php index 638244145b..2fde8aa50b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/XList.php @@ -34,6 +34,7 @@ class XList extends CollectionXList ->desc('List collections') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Get.php index 309a3b867e..d2a1f65779 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Get.php @@ -27,6 +27,7 @@ class Get extends DatabaseGet ->desc('Get database') ->groups(['api', 'database']) ->label('scope', 'databases.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Transactions/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Transactions/Get.php index 7def4f0b9a..c2f4b85881 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Transactions/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Transactions/Get.php @@ -31,6 +31,7 @@ class Get extends TransactionsGet ->desc('Get transaction') ->groups(['api', 'database', 'transactions']) ->label('scope', 'documents.read') + ->label('usage.resource', 'transaction/{request.transactionId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Get.php index 5fad045dda..a7171c9691 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Get.php @@ -27,6 +27,7 @@ class Get extends DatabaseGet ->desc('Get database') ->groups(['api', 'database']) ->label('scope', 'databases.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'tablesDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Get.php index b0ef9e8a85..9885f44ca4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Get.php @@ -43,6 +43,7 @@ class Get extends AttributesGet ->desc('Get column') ->groups(['api', 'database']) ->label('scope', ['tables.read', 'collections.read', 'columns.read', 'attributes.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/XList.php index 56c436a13e..643ff94db4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/XList.php @@ -34,6 +34,7 @@ class XList extends AttributesXList ->desc('List columns') ->groups(['api', 'database']) ->label('scope', ['tables.read', 'collections.read', 'columns.read', 'attributes.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Get.php index ca104f05c4..f7d61f0ebe 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Get.php @@ -32,6 +32,7 @@ class Get extends CollectionGet ->desc('Get table') ->groups(['api', 'database']) ->label('scope', ['tables.read', 'collections.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Get.php index 9918bcb2b8..96e185e01a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Get.php @@ -33,6 +33,7 @@ class Get extends IndexGet ->desc('Get index') ->groups(['api', 'database']) ->label('scope', ['tables.read', 'collections.read', 'indexes.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/XList.php index 5fe3be4c05..b67ea60f44 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/XList.php @@ -34,6 +34,7 @@ class XList extends IndexXList ->desc('List indexes') ->groups(['api', 'database']) ->label('scope', ['tables.read', 'collections.read', 'indexes.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Get.php index 65ae238a1a..4b5b427f88 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Get.php @@ -35,6 +35,7 @@ class Get extends DocumentGet ->desc('Get row') ->groups(['api', 'database']) ->label('scope', ['rows.read', 'documents.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/XList.php index 87e276719e..b951fec8f8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/XList.php @@ -37,6 +37,7 @@ class XList extends DocumentXList ->desc('List rows') ->groups(['api', 'database']) ->label('scope', ['rows.read', 'documents.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/XList.php index 30ebbab409..fd8e51b467 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/XList.php @@ -35,6 +35,7 @@ class XList extends CollectionXList ->desc('List tables') ->groups(['api', 'database']) ->label('scope', ['tables.read', 'collections.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Transactions/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Transactions/Get.php index d81d3e579d..cfb621d28d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Transactions/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Transactions/Get.php @@ -32,6 +32,7 @@ class Get extends TransactionsGet ->desc('Get transaction') ->groups(['api', 'database', 'transactions']) ->label('scope', ['documents.read', 'rows.read']) + ->label('usage.resource', 'transaction/{request.transactionId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'tablesDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Documents/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Documents/Get.php index 73f7a55026..35dc3f178a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Documents/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Documents/Get.php @@ -33,6 +33,7 @@ class Get extends DocumentGet ->desc('Get document') ->groups(['api', 'database']) ->label('scope', 'documents.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Documents/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Documents/XList.php index c9ed05ac02..1b11b282fd 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Documents/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Documents/XList.php @@ -35,6 +35,7 @@ class XList extends DocumentXList ->desc('List documents') ->groups(['api', 'database']) ->label('scope', 'documents.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Get.php index 9619bb5048..73c0a9d3dc 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Get.php @@ -31,6 +31,7 @@ class Get extends CollectionGet ->desc('Get collection') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/Get.php index 4cf646acba..3d1b492ff9 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/Get.php @@ -32,6 +32,7 @@ class Get extends IndexGet ->desc('Get index') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/XList.php index acc46fb570..8475349979 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/XList.php @@ -33,6 +33,7 @@ class XList extends IndexXList ->desc('List indexes') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/XList.php index 7ba26b8b6a..ac6a20c457 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/XList.php @@ -34,6 +34,7 @@ class XList extends CollectionXList ->desc('List collections') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Embeddings/Text/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Embeddings/Text/Create.php index 4ab3edeb70..a77cc51f1b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Embeddings/Text/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Embeddings/Text/Create.php @@ -50,7 +50,7 @@ class Create extends CreateDocumentAction ->label('resourceType', RESOURCE_TYPE_EMBEDDINGS_TEXT) ->label('audits.event', 'embedding.create') ->label('audits.resource', 'vectorsdb/embeddings/text') - ->label('usage.resource', 'vectorsdb/embeddings/text') + ->label('usage.resource', 'database/embeddings/text') ->label('abuse-key', 'ip:{ip},method:{method},url:{url},userId:{userId}') ->label('abuse-limit', APP_LIMIT_WRITE_RATE_DEFAULT * 2) ->label('abuse-time', APP_LIMIT_WRITE_RATE_PERIOD_DEFAULT) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Get.php index a79632b105..606fb7150a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Get.php @@ -26,6 +26,7 @@ class Get extends DatabaseGet ->desc('Get database') ->groups(['api', 'database']) ->label('scope', 'databases.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Transactions/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Transactions/Get.php index fa4cc86cdd..5b1a227844 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Transactions/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Transactions/Get.php @@ -31,6 +31,7 @@ class Get extends TransactionsGet ->desc('Get transaction') ->groups(['api', 'database', 'transactions']) ->label('scope', 'documents.read') + ->label('usage.resource', 'transaction/{request.transactionId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php index 2d57ec5525..70d20fc0d9 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php @@ -36,6 +36,7 @@ class Get extends Action ->groups(['api', 'functions']) ->desc('Get deployment download') ->label('scope', 'functions.read') + ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Get.php index 57c4421928..31a395341b 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Get.php @@ -29,6 +29,7 @@ class Get extends Action ->desc('Get deployment') ->groups(['api', 'functions']) ->label('scope', 'functions.read') + ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php index e8e9ea9a18..581dea3d12 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php @@ -40,6 +40,7 @@ class XList extends Base ->desc('List deployments') ->groups(['api', 'functions']) ->label('scope', 'functions.read') + ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php index 9908669f84..027ff51166 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php @@ -32,6 +32,7 @@ class Get extends Base ->desc('Get execution') ->groups(['api', 'functions']) ->label('scope', ['executions.read', 'execution.read']) + ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php index bf31fa0ced..29bed70cd0 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php @@ -40,6 +40,7 @@ class XList extends Base ->desc('List executions') ->groups(['api', 'functions']) ->label('scope', ['executions.read', 'execution.read']) + ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Get.php index 9fab8afef8..449413cb10 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Get.php @@ -30,6 +30,7 @@ class Get extends Base ->desc('Get function') ->groups(['api', 'functions']) ->label('scope', 'functions.read') + ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Get.php index 13ce73e751..41decb1a48 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Get.php @@ -30,6 +30,7 @@ class Get extends Base ->desc('Get variable') ->groups(['api', 'functions']) ->label('scope', 'functions.read') + ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label( 'sdk', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/XList.php index b330812b96..bf6ba67190 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/XList.php @@ -37,6 +37,7 @@ class XList extends Base ->desc('List variables') ->groups(['api', 'functions']) ->label('scope', 'functions.read') + ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label( 'sdk', diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index c2b8837c13..fb4e691926 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -295,7 +295,15 @@ class Builds extends Action $privateKey = System::getEnv('_APP_VCS_GITHUB_PRIVATE_KEY'); $githubAppId = System::getEnv('_APP_VCS_GITHUB_APP_ID'); - $github->initializeVariables($providerInstallationId, $privateKey, $githubAppId); + try { + $github->initializeVariables($providerInstallationId, $privateKey, $githubAppId); + } catch (\Exception $e) { + if ($e->getCode() === 404 + && $resource->getAttribute('installationId', '') === $installationId) { + $this->disconnectVcs($resource, $dbForProject, $dbForPlatform); + } + throw $e; + } } Span::add('timings.setup', \round(\microtime(true) - $phaseStart, 3)); @@ -669,6 +677,7 @@ class Builds extends Action 'APPWRITE_FUNCTION_RUNTIME_VERSION' => $runtime['version'] ?? '', 'APPWRITE_FUNCTION_CPUS' => $cpus, 'APPWRITE_FUNCTION_MEMORY' => $memory, + 'OPEN_RUNTIMES_NFT' => System::getEnv('_APP_OPEN_RUNTIMES_NFT', 'enabled'), ]; break; case 'sites': @@ -684,6 +693,7 @@ class Builds extends Action 'APPWRITE_SITE_RUNTIME_VERSION' => $runtime['version'] ?? '', 'APPWRITE_SITE_CPUS' => $cpus, 'APPWRITE_SITE_MEMORY' => $memory, + 'OPEN_RUNTIMES_NFT' => System::getEnv('_APP_OPEN_RUNTIMES_NFT', 'enabled'), ]; break; } @@ -1555,6 +1565,24 @@ class Builds extends Action } } + protected function disconnectVcs(Document $resource, Database $dbForProject, Database $dbForPlatform): void + { + $repositoryId = $resource->getAttribute('repositoryId', ''); + if (!empty($repositoryId)) { + $dbForPlatform->deleteDocument('repositories', $repositoryId); + } + $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document([ + 'installationId' => '', + 'installationInternalId' => '', + 'providerRepositoryId' => '', + 'providerBranch' => '', + 'providerSilentMode' => false, + 'providerRootDirectory' => '', + 'repositoryId' => '', + 'repositoryInternalId' => '', + ])); + } + private function updateLatestDeployment(Database $dbForProject, Document $resource): Document { $latestDeployment = $dbForProject->findOne('deployments', [ diff --git a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Delete.php b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Delete.php index daad2bf634..f9c989b5bf 100644 --- a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Delete.php +++ b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Delete.php @@ -34,7 +34,6 @@ class Delete extends Action ->label('event', 'migrations.[migrationId].delete') ->label('audits.event', 'migrationId.delete') ->label('audits.resource', 'migrations/{request.migrationId}') - ->label('usage.resource', 'migrations/{request.migrationId}') ->label('sdk', new Method( namespace: 'migrations', group: null, diff --git a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Update.php b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Update.php index b900b6586b..8ecc53c2a3 100644 --- a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Update.php +++ b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('event', 'migrations.[migrationId].retry') ->label('audits.event', 'migration.retry') ->label('audits.resource', 'migrations/{request.migrationId}') - ->label('usage.resource', 'migrations/{request.migrationId}') ->label('sdk', new Method( namespace: 'migrations', group: null, diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php index 191c09e455..90c3781701 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php @@ -46,7 +46,6 @@ class Create extends Action ->groups(['api', 'organization']) ->label('audits.event', 'projects.create') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('scope', 'projects.write') ->label('sdk', new Method( namespace: 'organization', diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Delete.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Delete.php index 56af8a6b8b..fc8d5cccfc 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Delete.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Delete.php @@ -35,7 +35,6 @@ class Delete extends Action ->label('scope', 'projects.write') ->label('audits.event', 'projects.delete') ->label('audits.resource', 'project/{request.projectId}') - ->label('usage.resource', 'project/{request.projectId}') ->label('sdk', new Method( namespace: 'organization', group: 'projects', diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Update.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Update.php index b178a0c549..c364a5d6df 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Update.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Update.php @@ -33,7 +33,6 @@ class Update extends Action ->label('scope', 'projects.write') ->label('audits.event', 'projects.update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'organization', group: 'projects', diff --git a/src/Appwrite/Platform/Modules/Presences/HTTP/Delete.php b/src/Appwrite/Platform/Modules/Presences/HTTP/Delete.php index 7431efd411..66ab00c3a7 100644 --- a/src/Appwrite/Platform/Modules/Presences/HTTP/Delete.php +++ b/src/Appwrite/Platform/Modules/Presences/HTTP/Delete.php @@ -36,7 +36,6 @@ class Delete extends PlatformAction ->label('event', 'presences.[presenceId].delete') ->label('audits.event', 'presence.delete') ->label('audits.resource', 'presence/{request.presenceId}') - ->label('usage.resource', 'presence/{request.presenceId}') ->label('sdk', new Method( namespace: 'presences', group: 'presences', diff --git a/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php b/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php index 2d37818830..cd2f0d5636 100644 --- a/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php +++ b/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php @@ -45,7 +45,6 @@ class Update extends PlatformAction ->label('event', 'presences.[presenceId].update') ->label('audits.event', 'presence.update') ->label('audits.resource', 'presence/{response.$id}') - ->label('usage.resource', 'presence/{response.$id}') ->label('sdk', [ // Client-side SDK: `userId` is not accepted (session callers can only update their own presence). new Method( diff --git a/src/Appwrite/Platform/Modules/Presences/HTTP/Upsert.php b/src/Appwrite/Platform/Modules/Presences/HTTP/Upsert.php index 16bf5458f5..9e691e4647 100644 --- a/src/Appwrite/Platform/Modules/Presences/HTTP/Upsert.php +++ b/src/Appwrite/Platform/Modules/Presences/HTTP/Upsert.php @@ -46,7 +46,6 @@ class Upsert extends PlatformAction ->label('event', 'presences.[presenceId].upsert') ->label('audits.event', 'presence.upsert') ->label('audits.resource', 'presence/{response.$id}') - ->label('usage.resource', 'presence/{response.$id}') ->label('sdk', [ // Client-side SDK: `userId` is not accepted (session callers should just upsert their own presence). new Method( diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/AuthMethods/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/AuthMethods/Update.php index c6bf5a3c7c..f5f0ae0a32 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/AuthMethods/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/AuthMethods/Update.php @@ -38,7 +38,6 @@ class Update extends Action ->label('event', 'authMethod.[methodId].update') ->label('audits.event', 'project.authMethods.[methodId].update') ->label('audits.resource', 'project.authMethods/{response.$id}') - ->label('usage.resource', 'project.authMethods/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: null, diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Delete.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Delete.php index d84af6b995..201061dd62 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Delete.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Delete.php @@ -36,7 +36,6 @@ class Delete extends Action ->label('scope', 'project.write') ->label('audits.event', 'project.delete') ->label('audits.resource', 'project/{project.$id}') - ->label('usage.resource', 'project/{project.$id}') ->label('sdk', new Method( namespace: 'project', group: null, diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php index 3b23bb9039..992b3532c4 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php @@ -46,7 +46,6 @@ class Create extends Base ->label('event', 'keys.[keyId].create') ->label('audits.event', 'project.key.create') ->label('audits.resource', 'project.key/{response.$id}') - ->label('usage.resource', 'project.key/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'keys', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Delete.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Delete.php index 2c5e3bc2ed..c5da673e22 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Delete.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Delete.php @@ -38,7 +38,6 @@ class Delete extends Base ->label('event', 'keys.[keyId].delete') ->label('audits.event', 'project.key.delete') ->label('audits.resource', 'project.key/{request.keyId}') - ->label('usage.resource', 'project.key/{request.keyId}') ->label('sdk', new Method( namespace: 'project', group: 'keys', 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 index 314188645c..aadf76d74f 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php @@ -42,7 +42,6 @@ class Create extends Base ->label('event', 'keys.[keyId].create') ->label('audits.event', 'project.key.create') ->label('audits.resource', 'project.key/{response.$id}') - ->label('usage.resource', 'project.key/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'keys', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Update.php index 09d3e639d5..0d96bcf315 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Update.php @@ -44,7 +44,6 @@ class Update extends Base ->label('event', 'keys.[keyId].update') ->label('audits.event', 'project.key.update') ->label('audits.resource', 'project.key/{response.$id}') - ->label('usage.resource', 'project.key/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'keys', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Labels/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Labels/Update.php index 1647f9febe..8a3506eb13 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Labels/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Labels/Update.php @@ -35,7 +35,6 @@ class Update extends Action // ->label('event', 'project.labels.update') ->label('audits.event', 'project.labels.update') ->label('audits.resource', 'project.labels/{response.$id}') - ->label('usage.resource', 'project.labels/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: null, diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Create.php index 4300795d01..f4002c60ef 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Create.php @@ -37,7 +37,6 @@ class Create extends Action ->label('event', 'mock-phones.[number].create') ->label('audits.event', 'project.mock-phone.create') ->label('audits.resource', 'project.mock-phone/{response.number}') - ->label('usage.resource', 'project.mock-phone/{response.number}') ->label('sdk', new Method( namespace: 'project', group: 'mocks', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Delete.php b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Delete.php index 14b5f662c1..0fb23e1764 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Delete.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Delete.php @@ -36,7 +36,6 @@ class Delete extends Action ->label('event', 'mock-phones.[number].delete') ->label('audits.event', 'project.mock-phone.delete') ->label('audits.resource', 'project.mock-phone/{request.number}') - ->label('usage.resource', 'project.mock-phone/{request.number}') ->label('sdk', new Method( namespace: 'project', group: 'mocks', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Update.php index 99f27a2fc1..48b90a1b97 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Update.php @@ -37,7 +37,6 @@ class Update extends Action ->label('event', 'mock-phones.[number].update') ->label('audits.event', 'project.mock-phone.update') ->label('audits.resource', 'project.mock-phone/{response.number}') - ->label('usage.resource', 'project.mock-phone/{response.number}') ->label('sdk', new Method( namespace: 'project', group: 'mocks', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Apple/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Apple/Update.php index 25144643b9..dc9eede2b4 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Apple/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Apple/Update.php @@ -116,7 +116,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Auth0/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Auth0/Update.php index 51cd34a27d..aa5f39b213 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Auth0/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Auth0/Update.php @@ -90,7 +90,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Authentik/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Authentik/Update.php index f02dd540e9..af6b12618a 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Authentik/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Authentik/Update.php @@ -90,7 +90,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php index 8cbb2549d3..b439e7fdf7 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php @@ -242,7 +242,6 @@ abstract class Base extends Action ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/FusionAuth/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/FusionAuth/Update.php index be2038d0c9..3cdf0eeb89 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/FusionAuth/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/FusionAuth/Update.php @@ -90,7 +90,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Gitlab/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Gitlab/Update.php index 3ef25071dd..804f6354ae 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Gitlab/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Gitlab/Update.php @@ -101,7 +101,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Google/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Google/Update.php index 9839350e54..5623f2bdf9 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Google/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Google/Update.php @@ -94,7 +94,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Keycloak/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Keycloak/Update.php index c7dd7ae572..aa41e8a5e9 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Keycloak/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Keycloak/Update.php @@ -96,7 +96,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Microsoft/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Microsoft/Update.php index 67be3a8be0..811819a05c 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Microsoft/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Microsoft/Update.php @@ -100,7 +100,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Oidc/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Oidc/Update.php index 6cc170c086..697b306be8 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Oidc/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Oidc/Update.php @@ -110,7 +110,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Okta/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Okta/Update.php index f51311ec23..0344b6a14a 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Okta/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Okta/Update.php @@ -98,7 +98,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Android/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Android/Create.php index 94078072e1..accc6d5b35 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Android/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Android/Create.php @@ -39,7 +39,6 @@ class Create extends Action ->label('event', 'platforms.[platformId].create') ->label('audits.event', 'project.platform.create') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Android/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Android/Update.php index 9b368fd849..3ff958e814 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Android/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Android/Update.php @@ -37,7 +37,6 @@ class Update extends Action ->label('event', 'platforms.[platformId].update') ->label('audits.event', 'project.platform.update') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Apple/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Apple/Create.php index b66687bf0c..0843bf9a0c 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Apple/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Apple/Create.php @@ -39,7 +39,6 @@ class Create extends Action ->label('event', 'platforms.[platformId].create') ->label('audits.event', 'project.platform.create') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Apple/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Apple/Update.php index 02c5c226f8..0295075f19 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Apple/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Apple/Update.php @@ -37,7 +37,6 @@ class Update extends Action ->label('event', 'platforms.[platformId].update') ->label('audits.event', 'project.platform.update') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Delete.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Delete.php index d580aa7c8e..24669b02b2 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Delete.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Delete.php @@ -37,7 +37,6 @@ class Delete extends Action ->label('event', 'platforms.[platformId].delete') ->label('audits.event', 'project.platform.delete') ->label('audits.resource', 'project.platform/{request.platformId}') - ->label('usage.resource', 'project.platform/{request.platformId}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Linux/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Linux/Create.php index b4edf8bcd7..472b41cace 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Linux/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Linux/Create.php @@ -39,7 +39,6 @@ class Create extends Action ->label('event', 'platforms.[platformId].create') ->label('audits.event', 'project.platform.create') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Linux/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Linux/Update.php index 47ff114562..9c1f715c33 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Linux/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Linux/Update.php @@ -37,7 +37,6 @@ class Update extends Action ->label('event', 'platforms.[platformId].update') ->label('audits.event', 'project.platform.update') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Create.php index ce9ff52443..6c07727150 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Create.php @@ -47,7 +47,6 @@ class Create extends Action ->label('event', 'platforms.[platformId].create') ->label('audits.event', 'project.platform.create') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Update.php index 79dc5e8184..62d209ea25 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Update.php @@ -39,7 +39,6 @@ class Update extends Action ->label('event', 'platforms.[platformId].update') ->label('audits.event', 'project.platform.update') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Windows/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Windows/Create.php index 3530c6ed17..58be45d03b 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Windows/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Windows/Create.php @@ -39,7 +39,6 @@ class Create extends Action ->label('event', 'platforms.[platformId].create') ->label('audits.event', 'project.platform.create') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Windows/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Windows/Update.php index 4d4a371f5e..5cfb6ee7ea 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Windows/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Windows/Update.php @@ -37,7 +37,6 @@ class Update extends Action ->label('event', 'platforms.[platformId].update') ->label('audits.event', 'project.platform.update') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php index 7ca0586e36..b167aba794 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordDictionary/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordDictionary/Update.php index bd21431793..d0f8882e99 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordDictionary/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordDictionary/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php index e1d040de3a..be611e299f 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php @@ -36,7 +36,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPersonalData/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPersonalData/Update.php index f522368882..ff7819f192 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPersonalData/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPersonalData/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php index f76da811ef..0f8c566511 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionAlert/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionAlert/Update.php index e79859e9f8..d930fd89e7 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionAlert/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionAlert/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php index f32aa82f3b..10eabb57cd 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionInvalidation/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionInvalidation/Update.php index 68ecb22057..d4d87edbba 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionInvalidation/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionInvalidation/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php index 541e18f636..93ae339b79 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php @@ -36,7 +36,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php index 726ca237d2..b3f430b779 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php @@ -36,7 +36,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Protocols/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Protocols/Update.php index cc7e9e5c7f..e0e4477a3c 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Protocols/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Protocols/Update.php @@ -39,7 +39,6 @@ class Update extends Action ->label('event', 'protocols.[protocolId].update') ->label('audits.event', 'project.protocols.[protocolId].update') ->label('audits.resource', 'project.protocols/{response.$id}') - ->label('usage.resource', 'project.protocols/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: null, diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php index 8879facae4..dd8a469d26 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php @@ -45,7 +45,6 @@ class Update extends Action // ->label('event', 'project.smtp.update') ->label('audits.event', 'project.smtp.update') ->label('audits.resource', 'project.smtp/{response.$id}') - ->label('usage.resource', 'project.smtp/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'smtp', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Services/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Services/Update.php index e1e6efd768..86ef67bb01 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Services/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Services/Update.php @@ -39,7 +39,6 @@ class Update extends Action ->label('event', 'services.[serviceId].update') ->label('audits.event', 'project.services.[serviceId].update') ->label('audits.resource', 'project.services/{response.$id}') - ->label('usage.resource', 'project.services/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: null, diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Templates/Email/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Templates/Email/Update.php index 8e86d7d1e6..22e3e931d6 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Templates/Email/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Templates/Email/Update.php @@ -42,7 +42,6 @@ class Update extends Action ->label('event', 'templates.[templateId].update') ->label('audits.event', 'project.template.update') ->label('audits.resource', 'project.template/{response.templateId}') - ->label('usage.resource', 'project.template/{response.templateId}') ->label('sdk', new Method( namespace: 'project', group: 'templates', @@ -91,45 +90,63 @@ class Update extends Action ) { $locale = $locale ?: System::getEnv('_APP_LOCALE', 'en'); - // Prevent template update if custom SMTP is not configured - $smtp = $project->getAttribute('smtp', []); - if (($smtp['enabled'] ?? false) !== true) { - throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'SMTP must be enabled on the project to configure custom email templates.'); - } + $templateKey = "email.{$templateId}-{$locale}"; + $changes = [ + 'senderName' => $senderName, + 'senderEmail' => $senderEmail, + 'replyToEmail' => $replyToEmail, + 'replyToName' => $replyToName, + 'message' => $message, + 'subject' => $subject, + ]; - // Fetch current configuration - $templates = $project->getAttribute('templates', []); - $template = $templates['email.' . $templateId . '-' . $locale] ?? []; + $project = $dbForPlatform->withTransaction(function () use ($dbForPlatform, $authorization, $project, $templateKey, $changes) { + $project = $authorization->skip(fn () => $dbForPlatform->getDocument('projects', $project->getId(), forUpdate: true)); - // Apply changes — null means "not provided, keep existing". - // Empty string explicitly clears a previously-set value. - $keys = ['senderName', 'senderEmail', 'replyToEmail', 'replyToName', 'message', 'subject']; - foreach ($keys as $key) { - if (!\is_null(${$key})) { - $template[$key] = ${$key}; + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); } - } - // Backwards compatibility - if (!\is_null($template['replyTo'] ?? null)) { - $template['replyToEmail'] = $template['replyToEmail'] ?? $template['replyTo'] ?? ''; - } - - // Ensure required fields are set - $requiredKeys = ['subject', 'message']; - foreach ($requiredKeys as $key) { - if (empty($template[$key])) { - throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Param "' . $key . '" is not optional.'); + // Prevent template update if custom SMTP is not configured + $smtp = $project->getAttribute('smtp', []); + if (($smtp['enabled'] ?? false) !== true) { + throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'SMTP must be enabled on the project to configure custom email templates.'); } - } - // Save configuration - $templates['email.' . $templateId . '-' . $locale] = $template; - $updates = new Document([ - 'templates' => $templates, - ]); + // Fetch current configuration from the locked row so concurrent updates + // to other locale/template entries are preserved. + $templates = $project->getAttribute('templates', []); + $template = $templates[$templateKey] ?? []; - $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates)); + // Apply changes: null means "not provided, keep existing". + // Empty string explicitly clears a previously-set value. + foreach ($changes as $key => $value) { + if ($value !== null) { + $template[$key] = $value; + } + } + + // Backwards compatibility + if (($template['replyTo'] ?? null) !== null) { + $template['replyToEmail'] ??= $template['replyTo'] ?? ''; + } + + // Ensure required fields are set + $requiredKeys = ['subject', 'message']; + foreach ($requiredKeys as $key) { + if (empty($template[$key])) { + throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Param "' . $key . '" is not optional.'); + } + } + + $templates[$templateKey] = $template; + + return $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ + 'templates' => $templates, + ]))); + }); + + $template = $project->getAttribute('templates', [])[$templateKey] ?? []; $queueForEvents->setParam('templateId', $templateId); diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php index 6a4bd033cf..8c76ed2a8e 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php @@ -38,7 +38,6 @@ class Create extends Action ->label('event', 'variables.[variableId].create') ->label('audits.event', 'project.variable.create') ->label('audits.resource', 'project.variable/{response.$id}') - ->label('usage.resource', 'project.variable/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'variables', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Delete.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Delete.php index 5183bdc68e..553fb09e54 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Delete.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Delete.php @@ -35,7 +35,6 @@ class Delete extends Action ->label('event', 'variables.[variableId].delete') ->label('audits.event', 'project.variable.delete') ->label('audits.resource', 'project.variable/{request.variableId}') - ->label('usage.resource', 'project.variable/{request.variableId}') ->label('sdk', new Method( namespace: 'project', group: 'variables', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Update.php index cad912d97c..6b05e19a78 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Update.php @@ -37,7 +37,6 @@ class Update extends Action ->label('event', 'variables.[variableId].update') ->label('audits.event', 'project.variable.update') ->label('audits.resource', 'project.variable/{response.$id}') - ->label('usage.resource', 'project.variable/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'variables', diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php index b45d0a0aae..28405fe1da 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php @@ -51,7 +51,6 @@ class Create extends Action ->groups(['api', 'projects']) ->label('audits.event', 'projects.create') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('scope', 'projects.write') ->param('projectId', '', new ProjectId(), 'Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, and hyphen. Can\'t start with a special char. Max length is 36 chars.') ->param('name', null, new Text(128), 'Project name. Max length: 128 chars.') diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Update.php b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Update.php index 0778c51661..f6df843d07 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Update.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Update.php @@ -36,7 +36,6 @@ class Update extends Action ->label('scope', 'projects.write') ->label('audits.event', 'projects.update') ->label('audits.resource', 'project/{request.projectId}') - ->label('usage.resource', 'project/{request.projectId}') ->param('projectId', '', new UID(), 'Project unique ID.') ->param('name', null, new Text(128), 'Project name. Max length: 128 chars.') ->param('description', '', new Text(256), 'Project description. Max length: 256 chars.', true) diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Schedules/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/Schedules/Create.php index 3ef3a6bd24..7cf13c5ca2 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/Schedules/Create.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/Schedules/Create.php @@ -72,7 +72,6 @@ class Create extends Action ->label('event', 'schedules.[scheduleId].create') ->label('audits.event', 'schedule.create') ->label('audits.resource', 'schedule/{response.$id}') - ->label('usage.resource', 'schedule/{response.$id}') ->label('sdk', new Method( namespace: 'projects', group: 'schedules', diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Stages/Update.php b/src/Appwrite/Platform/Modules/Projects/Http/Stages/Update.php new file mode 100644 index 0000000000..c345712bc8 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Projects/Http/Stages/Update.php @@ -0,0 +1,144 @@ +setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) + ->setHttpPath('/v1/projects/:projectId/stages/:stageId') + ->desc('Update stage') + ->groups(['api', 'projects']) + ->label('scope', 'stages.write') + ->label('audits.event', 'stages.update') + ->label('audits.resource', 'project/{request.projectId}') + ->label('sdk', new Method( + namespace: 'projects', + group: 'stages', + name: 'updateStage', + description: '/docs/references/projects/update-stage.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: Response::STATUS_CODE_OK, + model: Response::MODEL_STAGE, + ) + ], + )) + ->param('projectId', '', new UID(), 'Project unique ID.') + ->param('stageId', '', new Text(128), 'SDK method key (namespace.method).') + ->param('skip', true, new Boolean(), 'Mark the stage as skipped.', true) + ->inject('response') + ->inject('dbForPlatform') + ->inject('apiKey') + ->inject('user') + ->inject('mode') + ->callback($this->action(...)); + } + + public function action(string $projectId, string $stageId, bool $skip, Response $response, Database $dbForPlatform, ?Key $apiKey, User $user, string $mode): void + { + $project = $dbForPlatform->getDocument('projects', $projectId); + + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } + + $this->assertOnboardingMethod($stageId); + + $byMethod = $project->getAttribute('onboarding', []); + if (! \is_array($byMethod)) { + $byMethod = []; + } + + $row = \is_array($byMethod[$stageId] ?? null) ? $byMethod[$stageId] : null; + + if ($skip) { + $prev = \is_array($row) ? ($row['status'] ?? '') : ''; + if ($prev !== ONBOARDING_STATUS_COMPLETED) { + $byMethod[$stageId] = [ + 'status' => ONBOARDING_STATUS_SKIPPED, + 'at' => DateTime::now(), + 'actorType' => $this->resolveActorType($apiKey, $user, $mode), + ]; + $project = $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ + 'onboarding' => $byMethod, + ])); + $byMethod = $project->getAttribute('onboarding', []); + $row = \is_array($byMethod[$stageId] ?? null) ? $byMethod[$stageId] : null; + } + } + + $response->dynamic(new Document($this->formatStageRow($stageId, $row)), Response::MODEL_STAGE); + } + + private function assertOnboardingMethod(string $method): void + { + if (! \array_key_exists($method, Config::getParam('onboarding', []))) { + throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Unknown SDK method: ' . $method); + } + } + + /** + * @param array|null $row + * @return array + */ + private function formatStageRow(string $method, ?array $row): array + { + $status = \is_array($row) ? ($row['status'] ?? null) : null; + $at = \is_array($row) ? ($row['at'] ?? '') : ''; + $actorType = \is_array($row) ? ($row['actorType'] ?? '') : ''; + + return [ + 'id' => $method, + 'sdk' => $method, + 'status' => $status ?? 'pending', + 'at' => $at, + 'actorType' => $actorType, + ]; + } + + private function resolveActorType(?Key $apiKey, User $user, string $mode): string + { + if ($apiKey !== null && $apiKey->getRole() === User::ROLE_KEYS) { + return match ($apiKey->getType()) { + API_KEY_ACCOUNT => ACTOR_TYPE_KEY_ACCOUNT, + API_KEY_ORGANIZATION => ACTOR_TYPE_KEY_ORGANIZATION, + API_KEY_STANDARD, API_KEY_EPHEMERAL => ACTOR_TYPE_KEY_PROJECT, + default => ACTOR_TYPE_KEY_PROJECT, + }; + } + + if (! $user->isEmpty()) { + return $mode === APP_MODE_ADMIN ? ACTOR_TYPE_ADMIN : ACTOR_TYPE_USER; + } + + return ACTOR_TYPE_GUEST; + } +} diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Stages/XList.php b/src/Appwrite/Platform/Modules/Projects/Http/Stages/XList.php new file mode 100644 index 0000000000..7fa6537152 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Projects/Http/Stages/XList.php @@ -0,0 +1,96 @@ +setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) + ->setHttpPath('/v1/projects/:projectId/stages') + ->desc('List stages') + ->groups(['api', 'projects']) + ->label('scope', 'stages.read') + ->label('sdk', new Method( + namespace: 'projects', + group: 'stages', + name: 'listStages', + description: '/docs/references/projects/list-stages.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: Response::STATUS_CODE_OK, + model: Response::MODEL_STAGE_LIST, + ) + ], + )) + ->param('projectId', '', new UID(), 'Project unique ID.') + ->inject('response') + ->inject('dbForPlatform') + ->callback($this->action(...)); + } + + public function action(string $projectId, Response $response, Database $dbForPlatform): void + { + $project = $dbForPlatform->getDocument('projects', $projectId); + + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } + + $response->dynamic(new Document([ + 'stages' => $this->buildStagesList($project), + ]), Response::MODEL_STAGE_LIST); + } + + /** + * @return array> + */ + private function buildStagesList(Document $project): array + { + $methods = \array_keys(Config::getParam('onboarding', [])); + $byMethod = $project->getAttribute('onboarding', []); + if (! \is_array($byMethod)) { + $byMethod = []; + } + + $out = []; + foreach ($methods as $method) { + $row = $byMethod[$method] ?? null; + $status = \is_array($row) ? ($row['status'] ?? null) : null; + + $at = \is_array($row) ? ($row['at'] ?? '') : ''; + $actorType = \is_array($row) ? ($row['actorType'] ?? '') : ''; + + $out[] = [ + 'id' => $method, + 'sdk' => $method, + 'status' => $status ?? 'pending', + 'at' => $at, + 'actorType' => $actorType, + ]; + } + + return $out; + } +} diff --git a/src/Appwrite/Platform/Modules/Projects/Services/Http.php b/src/Appwrite/Platform/Modules/Projects/Services/Http.php index 8275e664d5..56e8c26d73 100644 --- a/src/Appwrite/Platform/Modules/Projects/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Projects/Services/Http.php @@ -14,6 +14,8 @@ use Appwrite\Platform\Modules\Projects\Http\Projects\XList as ListProjects; use Appwrite\Platform\Modules\Projects\Http\Schedules\Create as CreateSchedule; use Appwrite\Platform\Modules\Projects\Http\Schedules\Get as GetSchedule; use Appwrite\Platform\Modules\Projects\Http\Schedules\XList as ListSchedules; +use Appwrite\Platform\Modules\Projects\Http\Stages\Update as UpdateStages; +use Appwrite\Platform\Modules\Projects\Http\Stages\XList as ListStages; use Utopia\Platform\Service; class Http extends Service @@ -35,5 +37,8 @@ class Http extends Service $this->addAction(CreateSchedule::getName(), new CreateSchedule()); $this->addAction(GetSchedule::getName(), new GetSchedule()); $this->addAction(ListSchedules::getName(), new ListSchedules()); + + $this->addAction(ListStages::getName(), new ListStages()); + $this->addAction(UpdateStages::getName(), new UpdateStages()); } } diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php index 56e5ad4f7c..9431d24cde 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php @@ -41,7 +41,6 @@ class Create extends Action ->label('event', 'rules.[ruleId].create') ->label('audits.event', 'rule.create') ->label('audits.resource', 'rule/{response.$id}') - ->label('usage.resource', 'rule/{response.$id}') ->label('sdk', new Method( namespace: 'proxy', group: 'rules', diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Delete.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Delete.php index 3d7fd02fa8..991b8eb006 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Delete.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Delete.php @@ -38,7 +38,6 @@ class Delete extends Action ->label('event', 'rules.[ruleId].delete') ->label('audits.event', 'rules.delete') ->label('audits.resource', 'rule/{request.ruleId}') - ->label('usage.resource', 'rule/{request.ruleId}') ->label('sdk', new Method( namespace: 'proxy', group: 'rules', diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php index 24cf52bc0d..7cc8b5e59e 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php @@ -43,7 +43,6 @@ class Create extends Action ->label('event', 'rules.[ruleId].create') ->label('audits.event', 'rule.create') ->label('audits.resource', 'rule/{response.$id}') - ->label('usage.resource', 'rule/{response.$id}') ->label('sdk', new Method( namespace: 'proxy', group: 'rules', diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php index cfd165d5bd..c15bc3b1d9 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php @@ -45,7 +45,6 @@ class Create extends Action ->label('event', 'rules.[ruleId].create') ->label('audits.event', 'rule.create') ->label('audits.resource', 'rule/{response.$id}') - ->label('usage.resource', 'rule/{response.$id}') ->label('sdk', new Method( namespace: 'proxy', group: 'rules', diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php index 43de6b5699..ca45d73e13 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php @@ -43,7 +43,6 @@ class Create extends Action ->label('event', 'rules.[ruleId].create') ->label('audits.event', 'rule.create') ->label('audits.resource', 'rule/{response.$id}') - ->label('usage.resource', 'rule/{response.$id}') ->label('sdk', new Method( namespace: 'proxy', group: 'rules', diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Status/Update.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Status/Update.php index 711681fc67..1ad6f730b3 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Status/Update.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Status/Update.php @@ -41,7 +41,6 @@ class Update extends Action ->label('event', 'rules.[ruleId].update') ->label('audits.event', 'rule.update') ->label('audits.resource', 'rule/{response.$id}') - ->label('usage.resource', 'rule/{response.$id}') ->label('sdk', new Method( namespace: 'proxy', group: 'rules', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php index fa84b2f22f..79ef3d2b1d 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php @@ -35,6 +35,7 @@ class Get extends Action ->desc('Get deployment download') ->groups(['api', 'sites']) ->label('scope', 'sites.read') + ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Get.php index 56aaa3640b..6c6384e2a0 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Get.php @@ -29,6 +29,7 @@ class Get extends Action ->desc('Get deployment') ->groups(['api', 'sites']) ->label('scope', 'sites.read') + ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php index 3dccd687ea..8dd25fdd55 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php @@ -40,6 +40,7 @@ class XList extends Base ->desc('List deployments') ->groups(['api', 'sites']) ->label('scope', 'sites.read') + ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Get.php index d685f2082d..508bcf0120 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Get.php @@ -30,6 +30,7 @@ class Get extends Base ->desc('Get site') ->groups(['api', 'sites']) ->label('scope', 'sites.read') + ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Get.php index 2fcb051996..50e10fe4c9 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Get.php @@ -30,6 +30,7 @@ class Get extends Base ->desc('Get variable') ->groups(['api', 'sites']) ->label('scope', 'sites.read') + ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label( 'sdk', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/XList.php index 1270fe4925..9637c0e8e0 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/XList.php @@ -37,6 +37,7 @@ class XList extends Base ->desc('List variables') ->groups(['api', 'sites']) ->label('scope', 'sites.read') + ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label( 'sdk', diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php index 680bdcff63..cf934575c0 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php @@ -62,7 +62,7 @@ class Create extends Action ->label('audits.event', 'file.create') ->label('event', 'buckets.[bucketId].files.[fileId].create') ->label('audits.resource', 'file/{response.$id}') - ->label('usage.resource', 'file/{response.$id}') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{response.$id}') ->label('abuse-key', 'ip:{ip},method:{method},url:{url},userId:{userId},chunkId:{chunkId}') ->label('abuse-limit', APP_LIMIT_WRITE_RATE_DEFAULT) ->label('abuse-time', APP_LIMIT_WRITE_RATE_PERIOD_DEFAULT) diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php index e2d5122305..6b631230c7 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php @@ -42,7 +42,7 @@ class Delete extends Action ->label('event', 'buckets.[bucketId].files.[fileId].delete') ->label('audits.event', 'file.delete') ->label('audits.resource', 'file/{request.fileId}') - ->label('usage.resource', 'file/{request.fileId}') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{request.fileId}') ->label('abuse-key', 'ip:{ip},method:{method},url:{url},userId:{userId}') ->label('abuse-limit', APP_LIMIT_WRITE_RATE_DEFAULT) ->label('abuse-time', APP_LIMIT_WRITE_RATE_PERIOD_DEFAULT) diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php index ed02a295c8..e5d82c7aa1 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php @@ -43,6 +43,7 @@ class Get extends Action ->desc('Get file for download') ->groups(['api', 'storage']) ->label('scope', 'files.read') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{request.fileId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('sdk', new Method( namespace: 'storage', diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Get.php index d997fe3cc0..53ce6fad4f 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Get.php @@ -32,6 +32,7 @@ class Get extends Action ->desc('Get file') ->groups(['api', 'storage']) ->label('scope', 'files.read') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{request.fileId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('sdk', new Method( namespace: 'storage', diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php index 2a2686b544..d856c0456d 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php @@ -53,6 +53,7 @@ class Get extends Action ->desc('Get file preview') ->groups(['api', 'storage']) ->label('scope', 'files.read') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{request.fileId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('cache', true) ->label('cache.resourceType', 'bucket/{request.bucketId}') diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Push/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Push/Get.php index 2b2d23c1fa..637d1b22e6 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Push/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Push/Get.php @@ -40,6 +40,7 @@ class Get extends Action ->desc('Get file for push notification') ->groups(['api', 'storage']) ->label('scope', 'public') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{request.fileId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->param('bucketId', '', new UID(), 'Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).') ->param('fileId', '', new UID(), 'File ID.') diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Update.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Update.php index 7758493b7b..c917e21ce8 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Update.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Update.php @@ -43,7 +43,7 @@ class Update extends Action ->label('event', 'buckets.[bucketId].files.[fileId].update') ->label('audits.event', 'file.update') ->label('audits.resource', 'file/{response.$id}') - ->label('usage.resource', 'file/{response.$id}') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{response.$id}') ->label('sdk', new Method( namespace: 'storage', group: 'files', diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php index 01e8b56fbe..8214cdbfa1 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php @@ -44,6 +44,7 @@ class Get extends Action ->desc('Get file for view') ->groups(['api', 'storage']) ->label('scope', 'files.read') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{request.fileId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('sdk', new Method( namespace: 'storage', diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/XList.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/XList.php index 28dfa87c5d..de61ea5910 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/XList.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/XList.php @@ -41,6 +41,7 @@ class XList extends Action ->desc('List files') ->groups(['api', 'storage']) ->label('scope', 'files.read') + ->label('usage.resource', 'bucket/{request.bucketId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('sdk', new Method( namespace: 'storage', diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Get.php index 4e75de27c8..0418ef8b45 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Get.php @@ -32,6 +32,7 @@ class Get extends Action ->desc('Get bucket') ->groups(['api', 'storage']) ->label('scope', 'buckets.read') + ->label('usage.resource', 'bucket/{request.bucketId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('sdk', new Method( namespace: 'storage', diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php index 9412db8268..92db118c46 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php @@ -61,7 +61,6 @@ class Create extends Action ->label('auth.type', 'invites') ->label('audits.event', 'membership.create') ->label('audits.resource', 'team/{request.teamId}') - ->label('usage.resource', 'team/{request.teamId}') ->label('audits.userId', '{request.userId}') ->label('sdk', new Method( namespace: 'teams', diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Delete.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Delete.php index 94a7a5a047..d055ecb23f 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Delete.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Delete.php @@ -38,7 +38,6 @@ class Delete extends Action ->label('scope', 'teams.write') ->label('audits.event', 'membership.delete') ->label('audits.resource', 'team/{request.teamId}') - ->label('usage.resource', 'team/{request.teamId}') ->label('sdk', new Method( namespace: 'teams', group: 'memberships', diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Status/Update.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Status/Update.php index 45706ad2a1..35297710af 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Status/Update.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Status/Update.php @@ -46,7 +46,6 @@ class Update extends Action ->label('scope', 'public') ->label('audits.event', 'membership.update') ->label('audits.resource', 'team/{request.teamId}') - ->label('usage.resource', 'team/{request.teamId}') ->label('audits.userId', '{request.userId}') ->label('sdk', new Method( namespace: 'teams', diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Update.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Update.php index bb4b50c699..0d2f1e40b4 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Update.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Update.php @@ -40,7 +40,6 @@ class Update extends Action ->label('scope', 'teams.write') ->label('audits.event', 'membership.update') ->label('audits.resource', 'team/{request.teamId}') - ->label('usage.resource', 'team/{request.teamId}') ->label('sdk', new Method( namespace: 'teams', group: 'memberships', diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Preferences/Update.php b/src/Appwrite/Platform/Modules/Teams/Http/Preferences/Update.php index 22d9b7d8cf..2ec5dc9c74 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Preferences/Update.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Preferences/Update.php @@ -36,7 +36,6 @@ class Update extends Action ->label('scope', 'teams.write') ->label('audits.event', 'team.update') ->label('audits.resource', 'team/{response.$id}') - ->label('usage.resource', 'team/{response.$id}') ->label('audits.userId', '{response.$id}') ->label('sdk', new Method( namespace: 'teams', diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Teams/Create.php b/src/Appwrite/Platform/Modules/Teams/Http/Teams/Create.php index 7b335ac48f..222b0968be 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Teams/Create.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Teams/Create.php @@ -44,7 +44,6 @@ class Create extends Action ->label('scope', 'teams.write') ->label('audits.event', 'team.create') ->label('audits.resource', 'team/{response.$id}') - ->label('usage.resource', 'team/{response.$id}') ->label('sdk', new Method( namespace: 'teams', group: 'teams', diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Teams/Delete.php b/src/Appwrite/Platform/Modules/Teams/Http/Teams/Delete.php index c7c125393e..3bae031e06 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Teams/Delete.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Teams/Delete.php @@ -38,7 +38,6 @@ class Delete extends Action ->label('scope', 'teams.write') ->label('audits.event', 'team.delete') ->label('audits.resource', 'team/{request.teamId}') - ->label('usage.resource', 'team/{request.teamId}') ->label('sdk', new Method( namespace: 'teams', group: 'teams', diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Teams/Name/Update.php b/src/Appwrite/Platform/Modules/Teams/Http/Teams/Name/Update.php index cd43f87e4c..ebe751ee1c 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Teams/Name/Update.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Teams/Name/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('scope', 'teams.write') ->label('audits.event', 'team.update') ->label('audits.resource', 'team/{response.$id}') - ->label('usage.resource', 'team/{response.$id}') ->label('sdk', new Method( namespace: 'teams', group: 'teams', diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php index d0f2c7bcda..ceb73f0079 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php @@ -40,9 +40,9 @@ class Create extends Action ->label('event', 'tokens.[tokenId].create') ->label('audits.event', 'token.create') ->label('audits.resource', 'token/{response.$id}') - ->label('usage.resource', 'token/{response.$id}') ->label('usage.metric', 'tokens.{scope}.requests.create') ->label('usage.params', ['resourceId:{request.resourceId}', 'resourceType:{request.resourceType}']) + ->label('usage.resource', 'bucket/{request.bucketId}/file/{request.fileId}') ->label('abuse-key', 'ip:{ip},method:{method},url:{url},userId:{userId}') ->label('abuse-limit', APP_LIMIT_WRITE_RATE_DEFAULT) ->label('abuse-time', APP_LIMIT_WRITE_RATE_PERIOD_DEFAULT) diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/XList.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/XList.php index 5a93a06f26..65ab108e65 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/XList.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/XList.php @@ -37,6 +37,7 @@ class XList extends Action ->groups(['api', 'tokens']) ->label('scope', 'tokens.read') ->label('usage.metric', 'tokens.requests.read') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{request.fileId}') ->label('sdk', new Method( namespace: 'tokens', group: 'files', diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Delete.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Delete.php index 4188170367..4fca85e2a2 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Delete.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Delete.php @@ -8,6 +8,7 @@ use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Usage\Context; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Validator\UID; @@ -33,7 +34,6 @@ class Delete extends Action ->label('event', 'tokens.[tokenId].delete') ->label('audits.event', 'tokens.delete') ->label('audits.resource', 'token/{request.tokenId}') - ->label('usage.resource', 'token/{request.tokenId}') ->label('usage.metric', 'tokens.{scope}.requests.delete') ->label('usage.params', ['tokenId:{request.tokenId}']) ->label('abuse-key', 'ip:{ip},method:{method},url:{url},userId:{userId}') @@ -59,16 +59,25 @@ class Delete extends Action ->inject('response') ->inject('dbForProject') ->inject('queueForEvents') + ->inject('usage') ->callback($this->action(...)); } - public function action(string $tokenId, Response $response, Database $dbForProject, Event $queueForEvents) + public function action(string $tokenId, Response $response, Database $dbForProject, Event $queueForEvents, Context $usage) { $token = $dbForProject->getDocument('resourceTokens', $tokenId); if ($token->isEmpty()) { throw new Exception(Exception::TOKEN_NOT_FOUND); } + if ($token->getAttribute('resourceType') === TOKENS_RESOURCE_TYPE_FILES) { + $resourceId = (string) $token->getAttribute('resourceId', ''); + [$bucketId, $fileId] = explode(':', $resourceId, 2) + ['', '']; + if ($bucketId !== '' && $fileId !== '') { + $usage->setResourcePath('bucket/' . $bucketId . '/file/' . $fileId); + } + } + $dbForProject->deleteDocument('resourceTokens', $tokenId); $queueForEvents diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Get.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Get.php index 0a364683ca..a3a540552c 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Get.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Get.php @@ -7,6 +7,7 @@ use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Usage\Context; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Validator\UID; @@ -50,10 +51,11 @@ class Get extends Action ->param('tokenId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Token ID.', false, ['dbForProject']) ->inject('response') ->inject('dbForProject') + ->inject('usage') ->callback($this->action(...)); } - public function action(string $tokenId, Response $response, Database $dbForProject) + public function action(string $tokenId, Response $response, Database $dbForProject, Context $usage) { $token = $dbForProject->getDocument('resourceTokens', $tokenId); @@ -61,6 +63,14 @@ class Get extends Action throw new Exception(Exception::TOKEN_NOT_FOUND); } + if ($token->getAttribute('resourceType') === TOKENS_RESOURCE_TYPE_FILES) { + $resourceId = (string) $token->getAttribute('resourceId', ''); + [$bucketId, $fileId] = explode(':', $resourceId, 2) + ['', '']; + if ($bucketId !== '' && $fileId !== '') { + $usage->setResourcePath('bucket/' . $bucketId . '/file/' . $fileId); + } + } + $response->dynamic($token, Response::MODEL_RESOURCE_TOKEN); } } diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Update.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Update.php index 924d73dfe8..63b2fb098b 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Update.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Update.php @@ -8,6 +8,7 @@ use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Usage\Context; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Validator\Datetime as DatetimeValidator; @@ -35,7 +36,6 @@ class Update extends Action ->label('event', 'tokens.[tokenId].update') ->label('audits.event', 'tokens.update') ->label('audits.resource', 'tokens/{response.$id}') - ->label('usage.resource', 'tokens/{response.$id}') ->label('usage.metric', 'tokens.{scope}.requests.update') ->label('usage.params', ['tokenId:{request.tokenId}']) ->label('abuse-key', 'ip:{ip},method:{method},url:{url},userId:{userId}') @@ -62,10 +62,11 @@ class Update extends Action ->inject('response') ->inject('dbForProject') ->inject('queueForEvents') + ->inject('usage') ->callback($this->action(...)); } - public function action(string $tokenId, ?string $expire, Response $response, Database $dbForProject, Event $queueForEvents) + public function action(string $tokenId, ?string $expire, Response $response, Database $dbForProject, Event $queueForEvents, Context $usage) { $token = $dbForProject->getDocument('resourceTokens', $tokenId); @@ -73,6 +74,14 @@ class Update extends Action throw new Exception(Exception::TOKEN_NOT_FOUND); } + if ($token->getAttribute('resourceType') === TOKENS_RESOURCE_TYPE_FILES) { + $resourceId = (string) $token->getAttribute('resourceId', ''); + [$bucketId, $fileId] = explode(':', $resourceId, 2) + ['', '']; + if ($bucketId !== '' && $fileId !== '') { + $usage->setResourcePath('bucket/' . $bucketId . '/file/' . $fileId); + } + } + $token->setAttribute('expire', $expire); $token = $dbForProject->updateDocument('resourceTokens', $tokenId, $token); diff --git a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php index e40e447ed5..53f67f34b0 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php @@ -78,7 +78,7 @@ class Create extends Action $parsedPayload = $github->getEvent($event, $payload); match ($event) { - $github::EVENT_INSTALLATION => $this->handleInstallationEvent($parsedPayload, $dbForPlatform, $authorization), + $github::EVENT_INSTALLATION => $this->handleInstallationEvent($parsedPayload, $dbForPlatform, $authorization, $getProjectDB), $github::EVENT_PUSH => $this->handlePushEvent($parsedPayload, $githubAppId, $privateKey, $github, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform), $github::EVENT_PULL_REQUEST => $this->handlePullRequestEvent($parsedPayload, $privateKey, $githubAppId, $github, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform), default => null, @@ -92,35 +92,89 @@ class Create extends Action return; } - private function handleInstallationEvent( + protected function handleInstallationEvent( array $parsedPayload, Database $dbForPlatform, Authorization $authorization, + callable $getProjectDB, ) { if ($parsedPayload["action"] !== "deleted") { return; } - // TODO: Use worker for this job instead (update function/site as well) $providerInstallationId = $parsedPayload["installationId"]; - $installations = $dbForPlatform->find('installations', [ - Query::equal('providerInstallationId', [$providerInstallationId]), - Query::limit(1000) - ]); + $installationCursor = null; + do { + $installationQueries = [ + Query::equal('providerInstallationId', [$providerInstallationId]), + Query::limit(1000), + ]; + if ($installationCursor !== null) { + $installationQueries[] = Query::cursorAfter($installationCursor); + } + $installations = $authorization->skip(fn () => $dbForPlatform->find('installations', $installationQueries)); - foreach ($installations as $installation) { - $repositories = $authorization->skip(fn () => $dbForPlatform->find('repositories', [ - Query::equal('installationInternalId', [$installation->getSequence()]), - Query::limit(1000) - ])); + foreach ($installations as $installation) { + $projectId = $installation->getAttribute('projectId', ''); + $project = $authorization->skip(fn () => $dbForPlatform->getDocument('projects', $projectId)); - foreach ($repositories as $repository) { - $authorization->skip(fn () => $dbForPlatform->deleteDocument('repositories', $repository->getId())); + if (!$project->isEmpty()) { + $dbForProject = $getProjectDB($project); + + foreach (['functions', 'sites'] as $collection) { + $cursor = null; + do { + $queries = [ + Query::equal('installationInternalId', [$installation->getSequence()]), + Query::limit(1000), + ]; + if ($cursor !== null) { + $queries[] = Query::cursorAfter($cursor); + } + $resources = $authorization->skip(fn () => $dbForProject->find($collection, $queries)); + + foreach ($resources as $resource) { + $authorization->skip(fn () => $dbForProject->updateDocument($collection, $resource->getId(), new Document([ + 'installationId' => '', + 'installationInternalId' => '', + 'providerRepositoryId' => '', + 'providerBranch' => '', + 'providerSilentMode' => false, + 'providerRootDirectory' => '', + 'repositoryId' => '', + 'repositoryInternalId' => '', + ]))); + } + + $cursor = count($resources) === 1000 ? $resources[array_key_last($resources)] : null; + } while ($cursor !== null); + } + } + + $cursor = null; + do { + $queries = [ + Query::equal('installationInternalId', [$installation->getSequence()]), + Query::limit(1000), + ]; + if ($cursor !== null) { + $queries[] = Query::cursorAfter($cursor); + } + $repositories = $authorization->skip(fn () => $dbForPlatform->find('repositories', $queries)); + + foreach ($repositories as $repository) { + $authorization->skip(fn () => $dbForPlatform->deleteDocument('repositories', $repository->getId())); + } + + $cursor = count($repositories) === 1000 ? $repositories[array_key_last($repositories)] : null; + } while ($cursor !== null); + + $authorization->skip(fn () => $dbForPlatform->deleteDocument('installations', $installation->getId())); } - $authorization->skip(fn () => $dbForPlatform->deleteDocument('installations', $installation->getId())); - } + $installationCursor = count($installations) === 1000 ? $installations[array_key_last($installations)] : null; + } while ($installationCursor !== null); } private function handlePushEvent( diff --git a/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Create.php b/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Create.php index 5c9520442b..38196420be 100644 --- a/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Create.php +++ b/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Create.php @@ -47,7 +47,6 @@ class Create extends Action ->label('event', 'webhooks.[webhookId].create') ->label('audits.event', 'webhook.create') ->label('audits.resource', 'webhook/{response.$id}') - ->label('usage.resource', 'webhook/{response.$id}') ->label('sdk', new Method( namespace: 'webhooks', group: null, diff --git a/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Delete.php b/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Delete.php index 1d0ffe9303..cd05b6210c 100644 --- a/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Delete.php +++ b/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Delete.php @@ -38,7 +38,6 @@ class Delete extends Action ->label('event', 'webhooks.[webhookId].delete') ->label('audits.event', 'webhook.delete') ->label('audits.resource', 'webhook/{request.webhookId}') - ->label('usage.resource', 'webhook/{request.webhookId}') ->label('sdk', new Method( namespace: 'webhooks', group: null, diff --git a/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Secret/Update.php b/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Secret/Update.php index 396c147542..fbff94735e 100644 --- a/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Secret/Update.php +++ b/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Secret/Update.php @@ -38,7 +38,6 @@ class Update extends Action ->label('event', 'webhooks.[webhookId].update') ->label('audits.event', 'webhooks.update') ->label('audits.resource', 'webhook/{response.$id}') - ->label('usage.resource', 'webhook/{response.$id}') ->label('sdk', new Method( namespace: 'webhooks', group: null, diff --git a/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Update.php b/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Update.php index 0f89d90d4e..17b93812f3 100644 --- a/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Update.php +++ b/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Update.php @@ -44,7 +44,6 @@ class Update extends Action ->label('event', 'webhooks.[webhookId].update') ->label('audits.event', 'webhooks.update') ->label('audits.resource', 'webhook/{response.$id}') - ->label('usage.resource', 'webhook/{response.$id}') ->label('sdk', new Method( namespace: 'webhooks', group: null, diff --git a/src/Appwrite/Platform/Tasks/Install.php b/src/Appwrite/Platform/Tasks/Install.php index 8c9b86dedb..b2a8843049 100644 --- a/src/Appwrite/Platform/Tasks/Install.php +++ b/src/Appwrite/Platform/Tasks/Install.php @@ -3,6 +3,7 @@ namespace Appwrite\Platform\Tasks; use Appwrite\Docker\Compose; +use Appwrite\Docker\Compose\Generator; use Appwrite\Docker\Env; use Appwrite\Platform\Installer\Runtime\State; use Appwrite\Platform\Installer\Server as InstallerServer; @@ -532,7 +533,12 @@ class Install extends Action } $templateForEnv = new View($this->buildFromProjectPath('/app/views/install/env.phtml')); - $templateForCompose = new View($this->buildFromProjectPath('/app/views/install/compose.phtml')); + $composePath = $this->buildFromProjectPath('/docker-compose.yml'); + $composeYaml = \file_get_contents($composePath); + if ($composeYaml === false) { + throw new \RuntimeException('Failed to read docker-compose.yml from ' . $composePath); + } + $composeGenerator = new Generator($composeYaml); $database = $input['_APP_DB_ADAPTER'] ?? 'mongodb'; @@ -557,16 +563,18 @@ class Install extends Action } $executorImages = \implode(',', \array_unique($runtimeImages)); - $templateForCompose - ->setParam('httpPort', $httpPort) - ->setParam('httpsPort', $httpsPort) - ->setParam('version', $version) - ->setParam('organization', $organization) - ->setParam('image', $image) - ->setParam('database', $database) - ->setParam('hostPath', $this->hostPath) - ->setParam('enableAssistant', $enableAssistant) - ->setParam('executorImages', $executorImages); + $input['_APP_HTTP_PORT'] = $httpPort; + $input['_APP_HTTPS_PORT'] = $httpsPort; + $input['_APP_IMAGE'] = "{$organization}/{$image}"; + $input['_APP_VERSION'] = $version; + $input['_APP_EXECUTOR_IMAGES'] = $executorImages; + + $composeContent = $composeGenerator->render([ + 'version' => $version, + 'database' => $database, + 'hostPath' => $this->hostPath, + 'enableAssistant' => $enableAssistant, + ]); $templateForEnv->setParam('vars', $input); @@ -604,7 +612,7 @@ class Install extends Action $this->updateProgress($progress, InstallerServer::STEP_DOCKER_COMPOSE, InstallerServer::STATUS_IN_PROGRESS, $messages); if (!$useExistingConfig) { - $this->writeComposeFile($templateForCompose); + $this->writeComposeFile($composeContent); } $this->updateProgress($progress, InstallerServer::STEP_DOCKER_COMPOSE, InstallerServer::STATUS_COMPLETED, $messages); @@ -623,7 +631,7 @@ class Install extends Action } if ($database === 'mongodb' && !$useExistingConfig && $startIndex <= 1) { - $this->copyMongoEntrypointIfNeeded(); + $this->copyMongoFilesIfNeeded(); } if (!$noStart) { @@ -639,7 +647,7 @@ class Install extends Action } } - if (!$isLocalInstall || file_exists('/.dockerenv') || file_exists('/run/.containerenv')) { + if (!$isLocalInstall && (file_exists('/.dockerenv') || file_exists('/run/.containerenv'))) { $this->connectInstallerToAppwriteNetwork(); } @@ -919,10 +927,9 @@ class Install extends Action $healthPath = '/v1/health/version'; if ($isLocalInstall) { - $candidates = [ - self::APPWRITE_API_URL . $healthPath, - 'http://localhost:' . $httpPort . $healthPath, - ]; + $candidates = (file_exists('/.dockerenv') || file_exists('/run/.containerenv')) + ? ['http://host.docker.internal:' . $httpPort . $healthPath] + : ['http://localhost:' . $httpPort . $healthPath]; } else { $candidates = [ self::APPWRITE_API_URL . $healthPath, @@ -1079,11 +1086,10 @@ class Install extends Action ]; } - private function writeComposeFile(View $template): void + private function writeComposeFile(string $renderedContent): void { $composeFileName = $this->getComposeFileName(); $targetPath = $this->path . '/' . $composeFileName; - $renderedContent = $template->render(false); $result = @file_put_contents($targetPath, $renderedContent); if ($result === false) { @@ -1101,13 +1107,23 @@ class Install extends Action } } - private function copyMongoEntrypointIfNeeded(): void + private function copyMongoFilesIfNeeded(): void { - $mongoEntrypoint = $this->buildFromProjectPath('/mongo-entrypoint.sh'); + $files = [ + 'mongo-entrypoint.sh', + 'mongo-init.js', + ]; - if (file_exists($mongoEntrypoint)) { - // Always use container path for file operations - copy($mongoEntrypoint, $this->path . '/mongo-entrypoint.sh'); + foreach ($files as $file) { + $source = $this->buildFromProjectPath('/' . $file); + if (file_exists($source)) { + $target = $this->path . '/' . $file; + if (@copy($source, $target) === false) { + $lastError = error_get_last(); + $errorMsg = $lastError ? $lastError['message'] : 'Unknown error'; + throw new \RuntimeException('Failed to copy ' . $file . ' to ' . $target . ': ' . $errorMsg); + } + } } } @@ -1153,6 +1169,16 @@ class Install extends Action $command[] = '--project-directory'; $command[] = $composePath; + + $validateCommand = $command; + $validateCommand[] = 'config'; + $validateCommand[] = '--quiet'; + \exec($env . implode(' ', array_map(escapeshellarg(...), $validateCommand)) . ' 2>&1', $validateOutput, $validateExit); + if ($validateExit !== 0) { + $message = trim(implode("\n", $validateOutput)); + throw new \RuntimeException('Invalid Docker Compose file', 0, $message !== '' ? new \RuntimeException($message) : null); + } + $command[] = 'up'; $command[] = '-d'; $command[] = '--remove-orphans'; diff --git a/src/Appwrite/Platform/Tasks/SDKs.php b/src/Appwrite/Platform/Tasks/SDKs.php index b3802b8eac..30b355d8ae 100644 --- a/src/Appwrite/Platform/Tasks/SDKs.php +++ b/src/Appwrite/Platform/Tasks/SDKs.php @@ -10,7 +10,6 @@ use Appwrite\SDK\Language\CLI; use Appwrite\SDK\Language\CodexPlugin; use Appwrite\SDK\Language\CursorPlugin; use Appwrite\SDK\Language\Dart; -use Appwrite\SDK\Language\Deno; use Appwrite\SDK\Language\DotNet; use Appwrite\SDK\Language\Flutter; use Appwrite\SDK\Language\Go; @@ -389,9 +388,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND $warning = $warning . "\n\n > This is the Node.js SDK for integrating with Appwrite from your Node.js server-side code. If you're looking to integrate from the browser, you should check [appwrite/sdk-for-web](https://github.com/appwrite/sdk-for-web)"; break; - case 'deno': - $config = new Deno(); - break; case 'python': $config = new Python(); $config->setPipPackage('appwrite'); @@ -409,10 +405,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND $config = new ReactNative(); $config->setNPMPackage('react-native-appwrite'); break; - case 'flutter-dev': - $config = new Flutter(); - $config->setPackageName('appwrite_dev'); - break; case 'dart': $config = new Dart(); $config->setPackageName('dart_appwrite'); diff --git a/src/Appwrite/Reference/Renderer.php b/src/Appwrite/Reference/Renderer.php new file mode 100644 index 0000000000..841560dd1a --- /dev/null +++ b/src/Appwrite/Reference/Renderer.php @@ -0,0 +1,77 @@ +context->getAttribute('response', [])); + + preg_match_all('/{([^}]+)}/', $template, $matches); + foreach ($matches[1] as $pos => $match) { + $find = $matches[0][$pos]; + $parts = explode('.', $match, 2); + if (count($parts) !== 2) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Invalid resource reference template: {$template}"); + } + + [$namespace, $key] = $parts; + $bag = self::asArray($this->context->getAttribute($namespace, $fallback)); + if (!array_key_exists($key, $bag)) { + continue; + } + + $value = $bag[$key]; + if (!is_string($value)) { + if (is_array($value)) { + $value = json_encode($value); + } elseif (is_object($value) && method_exists($value, '__toString')) { + $value = (string) $value; + } elseif (is_scalar($value)) { + $value = (string) $value; + } else { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Cannot stringify reference value: {$template}"); + } + } + + $template = str_replace($find, $value, $template); + } + + return $template; + } + + /** + * @return array + */ + private static function asArray(mixed $value): array + { + if (is_array($value)) { + return $value; + } + if ($value instanceof Document) { + return $value->getArrayCopy(); + } + if (is_object($value)) { + return (array) $value; + } + return []; + } +} diff --git a/src/Appwrite/Task/Validator/Cron.php b/src/Appwrite/Task/Validator/Cron.php index 18f3333a57..9e6fcd92a1 100644 --- a/src/Appwrite/Task/Validator/Cron.php +++ b/src/Appwrite/Task/Validator/Cron.php @@ -39,10 +39,19 @@ class Cron extends Validator } try { + \set_error_handler(static function (int $severity, string $message): bool { + if (($severity & E_WARNING) === E_WARNING) { + throw new \RuntimeException($message); + } + + return false; + }); (new CronExpression($value))->getNextRunDate(); return true; } catch (\RuntimeException) { return false; + } finally { + \restore_error_handler(); } } diff --git a/src/Appwrite/Usage/Context.php b/src/Appwrite/Usage/Context.php index 7283cff836..f095eb4981 100644 --- a/src/Appwrite/Usage/Context.php +++ b/src/Appwrite/Usage/Context.php @@ -61,6 +61,16 @@ class Context return empty($this->metrics) && empty($this->reduce); } + public function setResourcePath(string $path): self + { + return $this; + } + + public function getResourcePath(): string + { + return ''; + } + /** * Reset the context */ diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 45d0b5dc25..e8701b315e 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -252,6 +252,8 @@ class Response extends SwooleResponse // Project public const MODEL_PROJECT = 'project'; public const MODEL_PROJECT_LIST = 'projectList'; + public const MODEL_STAGE = 'stage'; + public const MODEL_STAGE_LIST = 'stageList'; public const MODEL_PROJECT_AUTH_METHOD = 'projectAuthMethod'; public const MODEL_PROJECT_SERVICE = 'projectService'; public const MODEL_PROJECT_PROTOCOL = 'projectProtocol'; diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index 3d5fd76de3..c4c2fe0607 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -153,6 +153,12 @@ class Project extends Model 'default' => 'active', 'example' => 'active', ]) + ->addRule('onboarding', [ + 'type' => self::TYPE_JSON, + 'description' => 'Stage progress (completed or skipped) with timestamps and actor types, keyed by stage id.', + 'default' => [], + 'example' => [], + ]) // Resource: Auth methods ->addRule('authMethods', [ diff --git a/src/Appwrite/Utopia/Response/Model/Stage.php b/src/Appwrite/Utopia/Response/Model/Stage.php new file mode 100644 index 0000000000..2b39499f8f --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Stage.php @@ -0,0 +1,61 @@ +addRule('id', [ + 'type' => self::TYPE_STRING, + 'description' => 'Stage ID.', + 'default' => '', + 'example' => 'tablesDB.create', + ]) + ->addRule('sdk', [ + 'type' => self::TYPE_STRING, + 'description' => 'SDK method key (namespace.name) for this stage.', + 'default' => '', + 'example' => 'tablesDB.create', + ]) + ->addRule('status', [ + 'type' => self::TYPE_STRING, + 'description' => 'Stage status.', + 'default' => 'pending', + 'example' => 'completed', + ]) + ->addRule('at', [ + 'type' => self::TYPE_DATETIME, + 'description' => 'When the stage was completed or skipped, in ISO 8601 format.', + 'default' => '', + 'example' => self::TYPE_DATETIME_EXAMPLE, + ]) + ->addRule('actorType', [ + 'type' => self::TYPE_STRING, + 'description' => 'Actor type when the stage was recorded.', + 'default' => '', + 'example' => 'user', + ]) + ; + } + + public function getName(): string + { + return 'Stage'; + } + + public function getType(): string + { + return Response::MODEL_STAGE; + } + + public function filter(Document $document): Document + { + return $document; + } +} diff --git a/tests/benchmarks/bulk-operations/LargeDocumentCreation.js b/tests/benchmarks/bulk-operations/LargeDocumentCreation.js index c903ed2dba..138c68c4d1 100644 --- a/tests/benchmarks/bulk-operations/LargeDocumentCreation.js +++ b/tests/benchmarks/bulk-operations/LargeDocumentCreation.js @@ -1,6 +1,6 @@ import { check, sleep } from "k6"; import http from "k6/http"; -import { provisionProject, provisionDatabase, cleanup, unique } from "./utils.js"; +import { provisionProject, provisionDatabase, cleanup, unique, ENDPOINT } from "./utils.js"; const millionRecords = 1_000_000; const batchSize = 10_000; @@ -8,7 +8,7 @@ const numBatches = millionRecords / batchSize; export function setup() { const resources = provisionProject({ - endpoint: 'http://localhost/v1', + endpoint: ENDPOINT, email: 'test@test.com', password: 'password123', name: 'Test User', @@ -16,7 +16,7 @@ export function setup() { }); const { databaseId, collectionId } = provisionDatabase({ - endpoint: 'http://localhost/v1', + endpoint: ENDPOINT, apiHeaders: resources.apiHeaders }); @@ -31,7 +31,7 @@ export function setup() { attributes: ["name", "email"] }; - const indexRes = http.post(`http://localhost/v1/databases/${databaseId}/collections/${collectionId}/indexes`, + const indexRes = http.post(`${ENDPOINT}/databases/${databaseId}/collections/${collectionId}/indexes`, JSON.stringify(index), { headers: resources.apiHeaders }); @@ -57,7 +57,7 @@ export function setup() { })); requests.push({ method: "POST", - url: `http://localhost/v1/databases/${databaseId}/collections/${collectionId}/documents`, + url: `${ENDPOINT}/databases/${databaseId}/collections/${collectionId}/documents`, body: JSON.stringify({ documents: docs }), params: { headers: resources.apiHeaders, @@ -96,7 +96,7 @@ export default function (data) { const payload = JSON.stringify({ documents: docs }); const res = http.post( - `http://localhost/v1/databases/${data.databaseId}/collections/${data.collectionId}/documents`, + `${ENDPOINT}/databases/${data.databaseId}/collections/${data.collectionId}/documents`, payload, { headers: data.apiHeaders, diff --git a/tests/benchmarks/bulk-operations/documentCreation.js b/tests/benchmarks/bulk-operations/documentCreation.js index 730b6bb541..94ba690c0f 100644 --- a/tests/benchmarks/bulk-operations/documentCreation.js +++ b/tests/benchmarks/bulk-operations/documentCreation.js @@ -1,12 +1,12 @@ import { check, sleep } from "k6"; import http from "k6/http"; -import { provisionProject, provisionDatabase, cleanup, unique } from "./utils.js"; +import { provisionProject, provisionDatabase, cleanup, unique, ENDPOINT } from "./utils.js"; const amount = 10_000; export function setup() { const resources = provisionProject({ - endpoint: 'http://localhost/v1', + endpoint: ENDPOINT, email: 'test@test.com', password: 'password123', name: 'Test User', @@ -14,7 +14,7 @@ export function setup() { }); const { databaseId, collectionId } = provisionDatabase({ - endpoint: 'http://localhost/v1', + endpoint: ENDPOINT, apiHeaders: resources.apiHeaders }); @@ -54,7 +54,7 @@ export default function (data) { }); const res = http.post( - `http://localhost/v1/databases/${data.databaseId}/collections/${data.collectionId}/documents`, + `${ENDPOINT}/databases/${data.databaseId}/collections/${data.collectionId}/documents`, payload, { headers: data.apiHeaders diff --git a/tests/benchmarks/bulk-operations/noisyNeighbor.js b/tests/benchmarks/bulk-operations/noisyNeighbor.js index 4bfec4e564..3cb4c62510 100644 --- a/tests/benchmarks/bulk-operations/noisyNeighbor.js +++ b/tests/benchmarks/bulk-operations/noisyNeighbor.js @@ -1,7 +1,7 @@ import { check, sleep } from "k6"; import http from "k6/http"; import { Trend } from "k6/metrics"; -import { provisionProject, provisionDatabase, cleanup, unique } from "./utils.js"; +import { provisionProject, provisionDatabase, cleanup, unique, ENDPOINT } from "./utils.js"; // Custom Trend metric for light response time tracking export const lightResponseTime = new Trend("light_response_time", true); @@ -12,7 +12,7 @@ const LIGHT_AMOUNT = 10; // Light operation amount export function setup() { // Set up two separate projects - one for bulk operations (noisy neighbor) and one for light operations const heavyResources = provisionProject({ - endpoint: 'http://localhost/v1', + endpoint: ENDPOINT, email: 'heavy@test.com', password: 'password123', name: 'Heavy User', @@ -20,7 +20,7 @@ export function setup() { }); const lightResources = provisionProject({ - endpoint: 'http://localhost/v1', + endpoint: ENDPOINT, email: 'light@test.com', password: 'password123', name: 'Light User', @@ -29,12 +29,12 @@ export function setup() { // Set up databases for both projects const heavy = provisionDatabase({ - endpoint: 'http://localhost/v1', + endpoint: ENDPOINT, apiHeaders: heavyResources.apiHeaders }); const light = provisionDatabase({ - endpoint: 'http://localhost/v1', + endpoint: ENDPOINT, apiHeaders: lightResources.apiHeaders }); @@ -84,7 +84,7 @@ export function heavy(data) { const payload = JSON.stringify({ documents }); const res = http.post( - `http://localhost/v1/databases/${data.heavy.databaseId}/collections/${data.heavy.collectionId}/documents`, + `${ENDPOINT}/databases/${data.heavy.databaseId}/collections/${data.heavy.collectionId}/documents`, payload, { headers: data.heavy.apiHeaders @@ -103,7 +103,7 @@ export function light(data) { const startTime = new Date(); const res = http.post( - `http://localhost/v1/databases/${data.light.databaseId}/collections/${data.light.collectionId}/documents`, + `${ENDPOINT}/databases/${data.light.databaseId}/collections/${data.light.collectionId}/documents`, payload, { headers: data.light.apiHeaders diff --git a/tests/benchmarks/bulk-operations/utils.js b/tests/benchmarks/bulk-operations/utils.js index 5b8bbc6c67..56771e7acc 100644 --- a/tests/benchmarks/bulk-operations/utils.js +++ b/tests/benchmarks/bulk-operations/utils.js @@ -1,5 +1,8 @@ import http from 'k6/http'; import { check } from 'k6'; +import { ENDPOINT } from '../config.js'; + +export { ENDPOINT }; /** * @typedef {Object} AuthHeaders @@ -47,7 +50,7 @@ function assert(response, checkName, condition) { * - API Key creation * * @param {Object} config Configuration object - * @param {string} config.endpoint Base endpoint URL (e.g., 'http://localhost:80/v1') + * @param {string} config.endpoint Base endpoint URL (e.g., 'http://localhost:9520/v1') * @param {string} config.email Email for account creation * @param {string} config.password Password for account creation * @param {string} config.name Name for account creation @@ -165,7 +168,7 @@ export function provisionProject(config) { * Example usage: * * const config = { - * endpoint: 'http://localhost:80/v1', + * endpoint: 'http://localhost:9520/v1', * email: 'test@example.com', * password: 'complex-password', * name: 'Test User', diff --git a/tests/benchmarks/config.js b/tests/benchmarks/config.js new file mode 100644 index 0000000000..cb7b22677a --- /dev/null +++ b/tests/benchmarks/config.js @@ -0,0 +1,2 @@ +export const ENDPOINT = (__ENV.APPWRITE_ENDPOINT || 'http://localhost:9520/v1').replace(/\/+$/, ''); +export const REALTIME_URL = (__ENV.APPWRITE_REALTIME_URL || `${ENDPOINT.replace(/^http/, 'ws')}/realtime`).replace(/\/+$/, ''); diff --git a/tests/benchmarks/graphql/account/graphql-full-selection.js b/tests/benchmarks/graphql/account/graphql-full-selection.js index 84d41328d6..85521547c1 100644 --- a/tests/benchmarks/graphql/account/graphql-full-selection.js +++ b/tests/benchmarks/graphql/account/graphql-full-selection.js @@ -1,10 +1,11 @@ import http from 'k6/http'; +import { ENDPOINT } from '../../config.js'; export const options = { vus: 20, duration: '60s', }; export default function () { - http.post('http://localhost/v1/graphql', JSON.stringify({ + http.post(`${ENDPOINT}/graphql`, JSON.stringify({ query: `query { accountGet { _id diff --git a/tests/benchmarks/graphql/account/graphql-selection-set.js b/tests/benchmarks/graphql/account/graphql-selection-set.js index fd605121e9..befc161fbc 100644 --- a/tests/benchmarks/graphql/account/graphql-selection-set.js +++ b/tests/benchmarks/graphql/account/graphql-selection-set.js @@ -1,10 +1,11 @@ import http from 'k6/http'; +import { ENDPOINT } from '../../config.js'; export const options = { vus: 20, duration: '60s', }; export default function () { - http.post('http://localhost/v1/graphql', JSON.stringify({ + http.post(`${ENDPOINT}/graphql`, JSON.stringify({ query: `query { accountGet { _id email } }` }), { headers: { diff --git a/tests/benchmarks/graphql/account/rest.js b/tests/benchmarks/graphql/account/rest.js index 04037c28f1..2f60892b09 100644 --- a/tests/benchmarks/graphql/account/rest.js +++ b/tests/benchmarks/graphql/account/rest.js @@ -1,10 +1,11 @@ import http from 'k6/http'; +import { ENDPOINT } from '../../config.js'; export const options = { vus: 20, duration: '60s', }; export default function () { - http.get('http://localhost/v1/account', { + http.get(`${ENDPOINT}/account`, { headers: { 'Content-Type': 'application/json', 'X-Appwrite-Project': 'test', diff --git a/tests/benchmarks/graphql/locale/graphql-batched.js b/tests/benchmarks/graphql/locale/graphql-batched.js index b2c633d49a..0dfd933f6d 100644 --- a/tests/benchmarks/graphql/locale/graphql-batched.js +++ b/tests/benchmarks/graphql/locale/graphql-batched.js @@ -1,10 +1,11 @@ import http from 'k6/http'; +import { ENDPOINT } from '../../config.js'; export const options = { vus: 20, duration: '60s', }; export default function () { - http.post('http://localhost/v1/graphql', JSON.stringify([{ + http.post(`${ENDPOINT}/graphql`, JSON.stringify([{ query: 'query { localeGetCountries { total countries { code } } }', }, { query: 'query { localeGetContinents { total continents { code } } }', diff --git a/tests/benchmarks/graphql/locale/graphql-full-selection.js b/tests/benchmarks/graphql/locale/graphql-full-selection.js index d66d6c44a7..219a78d0e9 100644 --- a/tests/benchmarks/graphql/locale/graphql-full-selection.js +++ b/tests/benchmarks/graphql/locale/graphql-full-selection.js @@ -1,10 +1,11 @@ import http from 'k6/http'; +import { ENDPOINT } from '../../config.js'; export const options = { vus: 20, duration: '60s', }; export default function () { - http.post('http://localhost/v1/graphql', JSON.stringify({ + http.post(`${ENDPOINT}/graphql`, JSON.stringify({ query: 'query { localeGetCountries { total countries { code name } } }', }), { headers: { diff --git a/tests/benchmarks/graphql/locale/graphql-selection-set.js b/tests/benchmarks/graphql/locale/graphql-selection-set.js index 46c6dcaa53..59f00e47e3 100644 --- a/tests/benchmarks/graphql/locale/graphql-selection-set.js +++ b/tests/benchmarks/graphql/locale/graphql-selection-set.js @@ -1,10 +1,11 @@ import http from 'k6/http'; +import { ENDPOINT } from '../../config.js'; export const options = { vus: 20, duration: '60s', }; export default function () { - http.post('http://localhost/v1/graphql', JSON.stringify({ + http.post(`${ENDPOINT}/graphql`, JSON.stringify({ query: 'query { localeGetCountries { total } }', }), { headers: { diff --git a/tests/benchmarks/graphql/locale/rest-serial.js b/tests/benchmarks/graphql/locale/rest-serial.js index 22f0c48ab0..acad4bcbc9 100644 --- a/tests/benchmarks/graphql/locale/rest-serial.js +++ b/tests/benchmarks/graphql/locale/rest-serial.js @@ -1,37 +1,38 @@ import http from 'k6/http'; +import { ENDPOINT } from '../../config.js'; export const options = { vus: 20, duration: '60s', }; export default function () { - http.get('http://localhost/v1/locale/countries', { + http.get(`${ENDPOINT}/locale/countries`, { headers: { 'Content-Type': 'application/json', 'X-Appwrite-Project': 'test', } }) - http.get('http://localhost/v1/locale/continents', { + http.get(`${ENDPOINT}/locale/continents`, { headers: { 'Content-Type': 'application/json', 'X-Appwrite-Project': 'test', } }) - http.get('http://localhost/v1/locale/countries/eu', { + http.get(`${ENDPOINT}/locale/countries/eu`, { headers: { 'Content-Type': 'application/json', 'X-Appwrite-Project': 'test', } }) - http.get('http://localhost/v1/locale/countries/phones', { + http.get(`${ENDPOINT}/locale/countries/phones`, { headers: { 'Content-Type': 'application/json', 'X-Appwrite-Project': 'test', } }) - http.get('http://localhost/v1/locale/languages', { + http.get(`${ENDPOINT}/locale/languages`, { headers: { 'Content-Type': 'application/json', 'X-Appwrite-Project': 'test', } }) -} \ No newline at end of file +} diff --git a/tests/benchmarks/graphql/locale/rest.js b/tests/benchmarks/graphql/locale/rest.js index 0c9c57355f..d830fe58dc 100644 --- a/tests/benchmarks/graphql/locale/rest.js +++ b/tests/benchmarks/graphql/locale/rest.js @@ -1,10 +1,11 @@ import http from 'k6/http'; +import { ENDPOINT } from '../../config.js'; export const options = { vus: 20, duration: '60s', }; export default function () { - http.get('http://localhost/v1/locale/countries', { + http.get(`${ENDPOINT}/locale/countries`, { headers: { 'Content-Type': 'application/json', 'X-Appwrite-Project': 'test', diff --git a/tests/benchmarks/http-local.sh b/tests/benchmarks/http-local.sh index 734c825fda..15c4b64cbe 100755 --- a/tests/benchmarks/http-local.sh +++ b/tests/benchmarks/http-local.sh @@ -5,7 +5,7 @@ export K6_WEB_DASHBOARD="${K6_WEB_DASHBOARD:-true}" export K6_WEB_DASHBOARD_HOST="${K6_WEB_DASHBOARD_HOST:-127.0.0.1}" export K6_WEB_DASHBOARD_PORT="${K6_WEB_DASHBOARD_PORT:-5665}" export K6_WEB_DASHBOARD_EXPORT="${K6_WEB_DASHBOARD_EXPORT:-/tmp/appwrite-k6-report.html}" -export APPWRITE_ENDPOINT="${APPWRITE_ENDPOINT:-http://localhost/v1}" +export APPWRITE_ENDPOINT="${APPWRITE_ENDPOINT:-http://localhost:9520/v1}" export APPWRITE_WORKER_TIMEOUT_MS="${APPWRITE_WORKER_TIMEOUT_MS:-120000}" export APPWRITE_BENCHMARK_SUMMARY_PATH="${APPWRITE_BENCHMARK_SUMMARY_PATH:-/tmp/appwrite-k6-summary.json}" diff --git a/tests/benchmarks/http.js b/tests/benchmarks/http.js index ef42e99663..a41b4778df 100644 --- a/tests/benchmarks/http.js +++ b/tests/benchmarks/http.js @@ -1,3 +1,5 @@ +import { ENDPOINT } from './config.js'; + /* * Run locally: * Requires k6 and a running Appwrite instance. @@ -11,14 +13,14 @@ import { check, group, sleep } from 'k6'; import encoding from 'k6/encoding'; import { Counter, Trend } from 'k6/metrics'; -const ENDPOINT = (__ENV.APPWRITE_ENDPOINT || 'http://localhost/v1').replace(/\/+$/, ''); const CONSOLE_PROJECT = __ENV.APPWRITE_CONSOLE_PROJECT || 'console'; const REGION = __ENV.APPWRITE_REGION || 'default'; const REDIRECT_URL = __ENV.APPWRITE_BENCHMARK_REDIRECT_URL || 'http://localhost'; const PASSWORD = __ENV.APPWRITE_BENCHMARK_PASSWORD || 'Password123!'; const WORKER_TIMEOUT_MS = Number(__ENV.APPWRITE_WORKER_TIMEOUT_MS || 120000); -const ITERATIONS = Number(__ENV.APPWRITE_BENCHMARK_ITERATIONS || 1); const VUS = Number(__ENV.APPWRITE_BENCHMARK_VUS || 1); +const DURATION = __ENV.APPWRITE_BENCHMARK_DURATION || '1m'; +const ROWS_PER_FLOW = Number(__ENV.APPWRITE_BENCHMARK_ROWS || 5); const SUMMARY_PATH = __ENV.APPWRITE_BENCHMARK_SUMMARY_PATH || '/tmp/appwrite-k6-summary.json'; const PREVIOUS_SUMMARY_PATH = __ENV.APPWRITE_BENCHMARK_PREVIOUS_SUMMARY_PATH || ''; const PREVIOUS_SUMMARY = PREVIOUS_SUMMARY_PATH ? loadPreviousSummary(PREVIOUS_SUMMARY_PATH) : null; @@ -31,16 +33,14 @@ export const flowFailures = new Counter('appwrite_benchmark_flow_failures'); export const options = { scenarios: { curated_flows: { - executor: 'shared-iterations', + executor: 'constant-vus', exec: 'curatedFlows', vus: VUS, - iterations: ITERATIONS, - maxDuration: __ENV.APPWRITE_BENCHMARK_MAX_DURATION || '30m', + duration: DURATION, }, }, thresholds: { http_req_failed: ['rate<0.05'], - appwrite_api_duration: ['p(95)<2000'], appwrite_benchmark_flow_failures: ['count<1'], }, }; @@ -173,6 +173,7 @@ export function setup() { }, apiHeaders, [201, 409], 'setup.project.platforms.web.create'); const tablesDb = setupTablesDb(apiHeaders); + const users = setupUsers(projectId, VUS); return { runId, @@ -182,10 +183,41 @@ export function setup() { tableId: tablesDb.tableId, consoleSessionHeaders, apiHeaders, + users, platformStatus: platform.status, }; } +// Pre-create one signed-in user per VU so password hashing happens once +// during setup (excluded from metrics) instead of in every iteration. +function setupUsers(projectId, count) { + const headers = projectHeaders(projectId); + const users = []; + + for (let index = 0; index < count; index++) { + const email = `bench-user-${unique('mail')}@example.com`; + setupApi('POST', '/account', { + userId: unique('user'), + email, + password: PASSWORD, + name: 'Benchmark User', + }, headers, [201], 'setup.account.create'); + + const session = setupApi('POST', '/account/sessions/email', { + email, + password: PASSWORD, + }, headers, [201], 'setup.account.session'); + + users.push({ sessionHeaders: { ...headers, Cookie: cookieHeader(session) } }); + + // Drop the auto-stored session cookie so the next user can sign in; + // setup() runs in a single iteration, so the jar is not reset for us. + http.cookieJar().clear(ENDPOINT); + } + + return users; +} + function setupTablesDb(apiHeaders) { const databaseId = unique('tdb'); const tableId = unique('tbl'); @@ -219,7 +251,8 @@ function setupTablesDb(apiHeaders) { } export function curatedFlows(data) { - const ctx = { ...data }; + const user = data.users[(__VU - 1) % data.users.length]; + const ctx = { ...data, sessionHeaders: user.sessionHeaders }; try { group('account flow', () => accountFlow(ctx)); @@ -243,62 +276,42 @@ export function teardown(data) { } function accountFlow(ctx) { - const userId = unique('user'); - const email = `bench-user-${unique('mail')}@example.com`; - const headers = projectHeaders(ctx.projectId); + requireSession(ctx, 'accountFlow'); - api('POST', '/account', { - userId, - email, - password: PASSWORD, - name: 'Benchmark User', - }, headers, [201], 'account.create'); - - const session = api('POST', '/account/sessions/email', { - email, - password: PASSWORD, - }, headers, [201], 'account.sessions.email.create'); - - const sessionHeaders = { - ...headers, - Cookie: cookieHeader(session), - }; - - ctx.userId = userId; - ctx.userEmail = email; - ctx.sessionHeaders = sessionHeaders; - - api('GET', '/account', null, sessionHeaders, [200], 'account.get'); - api('GET', '/account/logs', null, sessionHeaders, [200], 'account.logs.list'); - api('PATCH', '/account/prefs', { prefs: { benchmark: true, runId: ctx.runId } }, sessionHeaders, [200], 'account.prefs.update'); - api('PATCH', '/account/name', { name: 'Benchmark User Updated' }, sessionHeaders, [200], 'account.name.update'); - api('PATCH', '/account/password', { password: `${PASSWORD}2`, oldPassword: PASSWORD }, sessionHeaders, [200], 'account.password.update'); + api('GET', '/account', null, ctx.sessionHeaders, [200], 'account.get'); + api('GET', '/account/logs', null, ctx.sessionHeaders, [200], 'account.logs.list'); + api('PATCH', '/account/prefs', { prefs: { benchmark: true, runId: ctx.runId } }, ctx.sessionHeaders, [200], 'account.prefs.update'); + api('PATCH', '/account/name', { name: 'Benchmark User Updated' }, ctx.sessionHeaders, [200], 'account.name.update'); } function tablesDbFlow(ctx) { requireSession(ctx, 'tablesDbFlow'); - const databaseId = ctx.databaseId; - const tableId = ctx.tableId; - const rowId = unique('row'); + const { databaseId, tableId, sessionHeaders } = ctx; + const base = `/tablesdb/${databaseId}/tables/${tableId}/rows`; + const rowIds = []; - api('POST', `/tablesdb/${databaseId}/tables/${tableId}/rows`, { - rowId, - data: tablePayload(), - permissions: ITEM_PERMISSIONS, - }, ctx.sessionHeaders, [201], 'tablesdb.rows.create'); - api('GET', `/tablesdb/${databaseId}/tables/${tableId}/rows`, null, ctx.sessionHeaders, [200], 'tablesdb.rows.list'); - api('GET', `/tablesdb/${databaseId}/tables/${tableId}/rows/${rowId}`, null, ctx.sessionHeaders, [200], 'tablesdb.rows.get'); - api('PATCH', `/tablesdb/${databaseId}/tables/${tableId}/rows/${rowId}`, { - data: { title: 'Benchmark Row Updated' }, - }, ctx.sessionHeaders, [200], 'tablesdb.rows.update'); - api('PATCH', `/tablesdb/${databaseId}/tables/${tableId}/rows/${rowId}/quantity/increment`, { - value: 1, - }, ctx.sessionHeaders, [200], 'tablesdb.rows.increment'); - api('PATCH', `/tablesdb/${databaseId}/tables/${tableId}/rows/${rowId}/quantity/decrement`, { - value: 1, - }, ctx.sessionHeaders, [200], 'tablesdb.rows.decrement'); - api('DELETE', `/tablesdb/${databaseId}/tables/${tableId}/rows/${rowId}`, null, ctx.sessionHeaders, [204], 'tablesdb.rows.delete'); + for (let index = 0; index < ROWS_PER_FLOW; index++) { + const rowId = unique('row'); + rowIds.push(rowId); + api('POST', base, { + rowId, + data: tablePayload(), + permissions: ITEM_PERMISSIONS, + }, sessionHeaders, [201], 'tablesdb.rows.create'); + } + + api('GET', base, null, sessionHeaders, [200], 'tablesdb.rows.list'); + + for (const rowId of rowIds) { + api('GET', `${base}/${rowId}`, null, sessionHeaders, [200], 'tablesdb.rows.get'); + api('PATCH', `${base}/${rowId}`, { + data: { title: 'Benchmark Row Updated' }, + }, sessionHeaders, [200], 'tablesdb.rows.update'); + api('PATCH', `${base}/${rowId}/quantity/increment`, { value: 1 }, sessionHeaders, [200], 'tablesdb.rows.increment'); + api('PATCH', `${base}/${rowId}/quantity/decrement`, { value: 1 }, sessionHeaders, [200], 'tablesdb.rows.decrement'); + api('DELETE', `${base}/${rowId}`, null, sessionHeaders, [204], 'tablesdb.rows.delete'); + } } function storageFlow(ctx) { diff --git a/tests/benchmarks/ws.js b/tests/benchmarks/ws.js index 916458856f..0b657f6e4e 100644 --- a/tests/benchmarks/ws.js +++ b/tests/benchmarks/ws.js @@ -3,6 +3,7 @@ import { URL } from 'https://jslib.k6.io/url/1.0.0/index.js'; import ws from 'k6/ws'; import { check } from 'k6'; +import { REALTIME_URL } from './config.js'; export let options = { stages: [ @@ -20,7 +21,7 @@ export let options = { export default function () { // const url = new URL('wss://appwrite-realtime.monitor-api.com/v1/realtime'); // url.searchParams.append('project', '604249e6b1a9f'); - const url = new URL('ws://localhost/v1/realtime'); + const url = new URL(REALTIME_URL); url.searchParams.append('project', 'console'); url.searchParams.append('channels[]', 'files'); diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index 217991c58f..42321395cc 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -1869,7 +1869,7 @@ final class UsageTest extends Scope $this->validateDates($response['body']['executions']); $this->assertEquals($executionTime, $response['body']['executionsTime'][array_key_last($response['body']['executionsTime'])]['value']); $this->validateDates($response['body']['executionsTime']); - }); + }, 60000, 500); $this->assertEventually(function () use ($executions, $executionTime) { $response = $this->client->call( @@ -1901,7 +1901,7 @@ final class UsageTest extends Scope $this->validateDates($response['body']['executionsTime']); $this->assertGreaterThan(0, $response['body']['buildsTime'][array_key_last($response['body']['buildsTime'])]['value']); $this->validateDates($response['body']['buildsTime']); - }); + }, 60000, 500); } public function testCustomDomainsFunctionStats(): void diff --git a/tests/e2e/Services/Project/StagesBase.php b/tests/e2e/Services/Project/StagesBase.php new file mode 100644 index 0000000000..471fdd9acb --- /dev/null +++ b/tests/e2e/Services/Project/StagesBase.php @@ -0,0 +1,140 @@ +getProject()['$id']; + + $response = $this->listStages($projectId); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertIsArray($response['body']['stages']); + $this->assertCount(\count(Config::getParam('onboarding', [])), $response['body']['stages']); + + $ids = array_column($response['body']['stages'], 'id'); + $this->assertContains('tablesDB.create', $ids); + $this->assertContains('storage.createBucket', $ids); + $this->assertContains('functions.create', $ids); + + foreach ($response['body']['stages'] as $stage) { + $this->assertSame($stage['id'], $stage['sdk']); + $this->assertArrayHasKey('status', $stage); + $this->assertArrayHasKey('at', $stage); + $this->assertArrayHasKey('actorType', $stage); + } + } + + public function testListProjectStagesWithoutAuthentication(): void + { + $response = $this->listStages($this->getProject()['$id'], false); + + $this->assertSame(401, $response['headers']['status-code']); + } + + // ========================================================================= + // Update stage (skip) tests + // ========================================================================= + + public function testUpdateProjectStageSkip(): void + { + $projectId = $this->getProject()['$id']; + $method = 'tablesDB.create'; + + $response = $this->updateStage($projectId, $method, true); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame($method, $response['body']['id']); + $this->assertSame($method, $response['body']['sdk']); + $this->assertSame(ONBOARDING_STATUS_SKIPPED, $response['body']['status']); + $this->assertNotEmpty($response['body']['at']); + $this->assertSame(ACTOR_TYPE_USER, $response['body']['actorType']); + + $dateValidator = new DatetimeValidator(); + $this->assertSame(true, $dateValidator->isValid($response['body']['at'])); + + $list = $this->listStages($projectId); + $this->assertSame(200, $list['headers']['status-code']); + $databaseStage = null; + foreach ($list['body']['stages'] as $stage) { + if ($stage['id'] === $method) { + $databaseStage = $stage; + break; + } + } + $this->assertNotNull($databaseStage); + $this->assertSame(ONBOARDING_STATUS_SKIPPED, $databaseStage['status']); + $this->assertSame(ACTOR_TYPE_USER, $databaseStage['actorType']); + + $response = $this->updateStage($projectId, 'unknown.method', true); + $this->assertSame(400, $response['headers']['status-code']); + $this->assertSame(Exception::GENERAL_ARGUMENT_INVALID, $response['body']['type']); + } + + public function testUpdateProjectStageSkipFalseLeavesPending(): void + { + $projectId = $this->getProject()['$id']; + $method = 'storage.createBucket'; + + $response = $this->updateStage($projectId, $method, false); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame($method, $response['body']['id']); + $this->assertSame('pending', $response['body']['status']); + } + + public function testUpdateProjectStageWithoutAuthentication(): void + { + $response = $this->updateStage($this->getProject()['$id'], 'tablesDB.create', true, false); + + $this->assertSame(401, $response['headers']['status-code']); + } + + // ========================================================================= + // Helpers + // ========================================================================= + + protected function listStages(string $projectId, bool $authenticated = true): mixed + { + // Stages live under /projects (console scope); use the root console session. + $headers = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console', + ]; + + if ($authenticated) { + $headers['origin'] = 'http://localhost'; + $headers['cookie'] = 'a_session_console=' . $this->getRoot()['session']; + } + + return $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/stages', $headers, []); + } + + protected function updateStage(string $projectId, string $stageId, bool $skip, bool $authenticated = true): mixed + { + $headers = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console', + ]; + + if ($authenticated) { + $headers['origin'] = 'http://localhost'; + $headers['cookie'] = 'a_session_console=' . $this->getRoot()['session']; + } + + return $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/stages/' . rawurlencode($stageId), $headers, [ + 'skip' => $skip, + ]); + } +} diff --git a/tests/e2e/Services/Project/StagesConsoleClientTest.php b/tests/e2e/Services/Project/StagesConsoleClientTest.php new file mode 100644 index 0000000000..51ba5fa3e4 --- /dev/null +++ b/tests/e2e/Services/Project/StagesConsoleClientTest.php @@ -0,0 +1,16 @@ +registerSubscriber(new TestPreparationStartedSubscriber()); $facade->registerSubscriber(new TestFinishedSubscriber(self::MAX_SECONDS_ALLOWED)); $facade->registerSubscriber(new RetrySubscriber()); + $facade->registerSubscriber(new SwooleCleanupSubscriber()); } } diff --git a/tests/unit/Docker/Compose/GeneratorTest.php b/tests/unit/Docker/Compose/GeneratorTest.php new file mode 100644 index 0000000000..3741a6004b --- /dev/null +++ b/tests/unit/Docker/Compose/GeneratorTest.php @@ -0,0 +1,134 @@ +assertIsString($compose); + + $this->generator = new Generator($compose); + } + + public function testSelectsDatabaseService(): void + { + $compose = $this->render([ + 'database' => 'mariadb', + 'enableAssistant' => false, + ]); + + $this->assertArrayHasKey('mariadb', $compose['services']); + $this->assertArrayNotHasKey('mongodb', $compose['services']); + $this->assertArrayNotHasKey('postgresql', $compose['services']); + $this->assertArrayHasKey('appwrite-mariadb', $compose['volumes']); + $this->assertArrayNotHasKey('appwrite-mongodb', $compose['volumes']); + $this->assertArrayNotHasKey('appwrite-postgresql', $compose['volumes']); + } + + public function testTogglesAssistantService(): void + { + $disabled = $this->render([ + 'enableAssistant' => false, + ]); + $enabled = $this->render([ + 'enableAssistant' => true, + ]); + + $this->assertArrayNotHasKey('appwrite-assistant', $disabled['services']); + $this->assertArrayHasKey('appwrite-assistant', $enabled['services']); + } + + public function testKeepsProductionWorkers(): void + { + $compose = $this->render(); + + $this->assertArrayHasKey('appwrite-worker-screenshots', $compose['services']); + $this->assertArrayHasKey('appwrite-task-interval', $compose['services']); + $this->assertArrayHasKey('appwrite-embedding', $compose['services']); + } + + public function testKeepsMongoInitFiles(): void + { + $compose = $this->render([ + 'database' => 'mongodb', + ]); + + $this->assertContains('./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro', $compose['services']['mongodb']['volumes']); + $this->assertContains('./mongo-entrypoint.sh:/mongo-entrypoint.sh:ro', $compose['services']['mongodb']['volumes']); + } + + public function testAddsLocalHostPathMount(): void + { + $compose = $this->render([ + 'version' => 'local', + 'hostPath' => '/tmp/appwrite', + ]); + + $this->assertSame('/tmp/appwrite:/usr/src/code:rw', $compose['services']['appwrite']['volumes'][0]); + } + + public function testDoesNotAddDatabaseDependencyWithoutPlaceholder(): void + { + $compose = $this->render([ + 'database' => 'postgresql', + ]); + + $this->assertSame(['appwrite'], $compose['services']['traefik']['depends_on']); + $this->assertContains('postgresql', $compose['services']['appwrite']['depends_on']); + $this->assertNotContains('${_APP_DB_HOST:-mongodb}', $compose['services']['appwrite']['depends_on']); + } + + public function testKeepsLongCommandsReadable(): void + { + $mariadb = $this->render([ + 'database' => 'mariadb', + ]); + $postgresql = $this->render([ + 'database' => 'postgresql', + ]); + + $this->assertSame(['mysqld', '--innodb-flush-method=fsync'], $mariadb['services']['mariadb']['command']); + $this->assertSame([ + 'postgres', + '-c', + 'fsync=off', + '-c', + 'synchronous_commit=off', + '-c', + 'full_page_writes=off', + ], $postgresql['services']['postgresql']['command']); + $this->assertSame([ + 'redis-server', + '--maxmemory', + '512mb', + '--maxmemory-policy', + 'allkeys-lru', + '--maxmemory-samples', + '5', + ], $postgresql['services']['redis']['command']); + } + + /** + * @param array $params + * @return array + */ + private function render(array $params = []): array + { + $yaml = $this->generator->render($params); + $compose = \yaml_parse($yaml); + + $this->assertIsArray($compose); + + return $compose; + } +} diff --git a/tests/unit/Functions/BuildsTest.php b/tests/unit/Functions/BuildsTest.php index b757856c83..36515d2f5b 100644 --- a/tests/unit/Functions/BuildsTest.php +++ b/tests/unit/Functions/BuildsTest.php @@ -8,6 +8,7 @@ use Appwrite\Platform\Modules\Functions\Workers\Builds; use PHPUnit\Framework\TestCase; use ReflectionMethod; use Utopia\Config\Config; +use Utopia\Database\Database; use Utopia\Database\Document; final class BuildsTest extends TestCase @@ -87,6 +88,62 @@ final class BuildsTest extends TestCase $this->assertNull($detection->getFallbackFile()); } + public function testDisconnectVcsClearsAllFieldsAndDeletesRepository(): void + { + $resource = new Document([ + '$id' => 'func123', + '$collection' => 'functions', + 'repositoryId' => 'repo456', + 'installationId' => 'install789', + 'installationInternalId' => 'install789internal', + 'providerRepositoryId' => 'gh123', + 'providerBranch' => 'main', + 'providerRootDirectory' => 'functions/my-func', + 'providerSilentMode' => true, + 'repositoryInternalId' => 'repo456internal', + ]); + + $dbForProject = $this->createMock(Database::class); + $dbForPlatform = $this->createMock(Database::class); + + $dbForPlatform->expects($this->once()) + ->method('deleteDocument') + ->with('repositories', 'repo456'); + + $dbForProject->expects($this->once()) + ->method('updateDocument') + ->with('functions', 'func123', $this->callback(function (Document $doc) { + $this->assertSame('', $doc->getAttribute('installationId')); + $this->assertSame('', $doc->getAttribute('installationInternalId')); + $this->assertSame('', $doc->getAttribute('providerRepositoryId')); + $this->assertSame('', $doc->getAttribute('providerBranch')); + $this->assertSame('', $doc->getAttribute('providerRootDirectory')); + $this->assertFalse($doc->getAttribute('providerSilentMode')); + $this->assertSame('', $doc->getAttribute('repositoryId')); + $this->assertSame('', $doc->getAttribute('repositoryInternalId')); + return true; + })); + + $this->callBuilds('disconnectVcs', $resource, $dbForProject, $dbForPlatform); + } + + public function testDisconnectVcsSkipsRepositoryDeletionWhenRepositoryIdEmpty(): void + { + $resource = new Document([ + '$id' => 'func123', + '$collection' => 'functions', + 'repositoryId' => '', + ]); + + $dbForProject = $this->createMock(Database::class); + $dbForPlatform = $this->createMock(Database::class); + + $dbForPlatform->expects($this->never())->method('deleteDocument'); + $dbForProject->expects($this->once())->method('updateDocument'); + + $this->callBuilds('disconnectVcs', $resource, $dbForProject, $dbForPlatform); + } + private function callBuilds(string $method, mixed ...$arguments): mixed { return (new ReflectionMethod($this->builds, $method))->invoke($this->builds, ...$arguments); diff --git a/tests/unit/Reference/RendererTest.php b/tests/unit/Reference/RendererTest.php new file mode 100644 index 0000000000..ac284103cc --- /dev/null +++ b/tests/unit/Reference/RendererTest.php @@ -0,0 +1,67 @@ + ['databaseId' => 'db1'], + 'response' => ['$id' => 'col9'], + ])); + + $this->assertSame( + 'database/db1/collection/col9', + $renderer->render('database/{request.databaseId}/collection/{response.$id}'), + ); + } + + public function testFallsBackToResponseForUnknownNamespace(): void + { + $renderer = new Renderer(new Document([ + 'response' => ['id' => 'r1'], + ])); + + $this->assertSame('thing/r1', $renderer->render('thing/{unknown.id}')); + } + + public function testSupportsUserAndProjectNamespaces(): void + { + $renderer = new Renderer(new Document([ + 'user' => ['$id' => 'usr1'], + 'project' => new Document(['$id' => 'prj1']), + ])); + + $this->assertSame( + 'user/usr1/project/prj1', + $renderer->render('user/{user.$id}/project/{project.$id}'), + ); + } + + public function testLeavesUnresolvedTokensIntact(): void + { + $renderer = new Renderer(new Document([ + 'request' => [], + ])); + + $this->assertSame( + 'database/{request.databaseId}', + $renderer->render('database/{request.databaseId}'), + ); + } + + public function testShortCircuitsWhenNoTemplate(): void + { + $renderer = new Renderer(new Document([])); + + $this->assertSame('database/db1', $renderer->render('database/db1')); + $this->assertSame('', $renderer->render('')); + } +} diff --git a/tests/unit/Vcs/GitHubInstallationEventTest.php b/tests/unit/Vcs/GitHubInstallationEventTest.php new file mode 100644 index 0000000000..045ac5d9d6 --- /dev/null +++ b/tests/unit/Vcs/GitHubInstallationEventTest.php @@ -0,0 +1,160 @@ +handler = new Create(); + } + + public function testHandleInstallationEventIgnoresNonDeletedActions(): void + { + $dbForPlatform = $this->createMock(Database::class); + $authorization = $this->createStub(Authorization::class); + + $dbForPlatform->expects($this->never())->method('find'); + $dbForPlatform->expects($this->never())->method('deleteDocument'); + + $result = $this->callHandler('handleInstallationEvent', [ + 'action' => 'created', + 'installationId' => '123', + ], $dbForPlatform, $authorization, fn () => null); + + $this->assertNull($result); + } + + public function testHandleInstallationEventDisconnectsFunctionsAndSites(): void + { + $installation = new Document([ + '$id' => 'install1', + '$sequence' => 'install1seq', + 'projectId' => 'project1', + 'providerInstallationId' => 'gh-install-123', + ]); + + $function = new Document([ + '$id' => 'func1', + '$collection' => 'functions', + 'installationId' => 'install1', + 'installationInternalId' => 'install1seq', + 'providerRepositoryId' => 'repo123', + 'providerBranch' => 'main', + 'providerRootDirectory' => 'functions/my-func', + 'providerSilentMode' => true, + 'repositoryId' => 'repo1', + 'repositoryInternalId' => 'repo1seq', + ]); + + $project = new Document(['$id' => 'project1']); + + $dbForProject = $this->createMock(Database::class); + $dbForPlatform = $this->createMock(Database::class); + $authorization = $this->createMock(Authorization::class); + + $dbForPlatform->expects($this->exactly(2)) + ->method('find') + ->willReturnCallback(fn (string $collection): array => match ($collection) { + 'installations' => [$installation], + 'repositories' => [], + default => [], + }); + + $dbForPlatform->expects($this->once()) + ->method('getDocument') + ->with('projects', 'project1') + ->willReturn($project); + + $dbForProject->expects($this->exactly(2)) + ->method('find') + ->willReturnCallback(fn (string $collection): array => $collection === 'functions' ? [$function] : []); + + $dbForProject->expects($this->once()) + ->method('updateDocument') + ->with('functions', 'func1', $this->callback(function (Document $doc) { + $this->assertSame('', $doc->getAttribute('installationId')); + $this->assertSame('', $doc->getAttribute('installationInternalId')); + $this->assertSame('', $doc->getAttribute('providerRepositoryId')); + $this->assertSame('', $doc->getAttribute('providerBranch')); + $this->assertSame('', $doc->getAttribute('providerRootDirectory')); + $this->assertFalse($doc->getAttribute('providerSilentMode')); + $this->assertSame('', $doc->getAttribute('repositoryId')); + $this->assertSame('', $doc->getAttribute('repositoryInternalId')); + return true; + })); + + // 1: find(installations), 2: getDocument(projects), 3: find(functions), 4: updateDocument(func1), + // 5: find(sites), 6: find(repositories), 7: deleteDocument(installations) + $authorization->expects($this->exactly(7)) + ->method('skip') + ->willReturnCallback(fn (callable $fn): mixed => $fn()); + + $dbForPlatform->expects($this->once()) + ->method('deleteDocument') + ->with('installations', 'install1'); + + $getProjectDB = fn () => $dbForProject; + + $this->callHandler('handleInstallationEvent', [ + 'action' => 'deleted', + 'installationId' => 'gh-install-123', + ], $dbForPlatform, $authorization, $getProjectDB); + } + + public function testHandleInstallationEventSkipsDisconnectWhenProjectNotFound(): void + { + $installation = new Document([ + '$id' => 'install1', + '$sequence' => 'install1seq', + 'projectId' => 'project1', + 'providerInstallationId' => 'gh-install-123', + ]); + + $dbForPlatform = $this->createMock(Database::class); + $authorization = $this->createMock(Authorization::class); + + $dbForPlatform->expects($this->exactly(2)) + ->method('find') + ->willReturnCallback(fn (string $collection): array => match ($collection) { + 'installations' => [$installation], + 'repositories' => [], + default => [], + }); + + $dbForPlatform->expects($this->once()) + ->method('getDocument') + ->with('projects', 'project1') + ->willReturn(new Document()); + + // 1: find(installations), 2: getDocument(projects), 3: find(repositories), 4: deleteDocument(installations) + $authorization->expects($this->exactly(4)) + ->method('skip') + ->willReturnCallback(fn (callable $fn): mixed => $fn()); + + $dbForPlatform->expects($this->once()) + ->method('deleteDocument') + ->with('installations', 'install1'); + + $this->callHandler('handleInstallationEvent', [ + 'action' => 'deleted', + 'installationId' => 'gh-install-123', + ], $dbForPlatform, $authorization, fn () => null); + } + + private function callHandler(string $method, mixed ...$arguments): mixed + { + return (new ReflectionMethod($this->handler, $method))->invoke($this->handler, ...$arguments); + } +}