From 9cb1cf418cc3b713abf44215b0f0a6cef3b20947 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 6 Oct 2023 17:02:01 +0100 Subject: [PATCH 01/36] Improve Error Handling and Add more Validation --- app/config/errors.php | 5 ++ app/controllers/api/migrations.php | 118 ++++++++++++++++++++++------- src/Appwrite/Extend/Exception.php | 1 + 3 files changed, 97 insertions(+), 27 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 575a4588ba..1f4bda4704 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -728,4 +728,9 @@ return [ 'description' => 'Migration is already in progress. You can check the status of the migration in your Appwrite Console\'s "Settings" > "Migrations".', 'code' => 409, ], + Exception::MIGRATION_PROVIDER_ERROR => [ + 'name' => Exception::MIGRATION_PROVIDER_ERROR, + 'description' => 'An error occurred on the provider\'s side. Please try again later.', + 'code' => 424, + ], ]; diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index 83888fff2c..360e1ae818 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -207,6 +207,16 @@ App::post('/v1/migrations/firebase') ->inject('user') ->inject('events') ->action(function (array $resources, string $serviceAccount, Response $response, Database $dbForProject, Document $project, Document $user, Event $events) { + $serviceAccountData = json_decode($serviceAccount, true); + + if (empty($serviceAccountData)) { + throw new Exception(Exception::MIGRATION_PROVIDER_ERROR, 'Invalid Service Account JSON'); + } + + if (!isset($serviceAccountData['project_id']) || !isset($serviceAccountData['client_email']) || !isset($serviceAccountData['private_key'])) { + throw new Exception(Exception::MIGRATION_PROVIDER_ERROR, 'Invalid Service Account JSON'); + } + $migration = $dbForProject->createDocument('migrations', new Document([ '$id' => ID::unique(), 'status' => 'pending', @@ -449,15 +459,26 @@ App::get('/v1/migrations/appwrite/report') ->inject('project') ->inject('user') ->action(function (array $resources, string $endpoint, string $projectID, string $key, Response $response) { - try { - $appwrite = new Appwrite($projectID, $endpoint, $key); + $appwrite = new Appwrite($projectID, $endpoint, $key); - $response - ->setStatusCode(Response::STATUS_CODE_OK) - ->dynamic(new Document($appwrite->report($resources)), Response::MODEL_MIGRATION_REPORT); + try { + $report = $appwrite->report($resources); } catch (\Throwable $e) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Source Error: ' . $e->getMessage()); + switch ($e->getCode()) { + case 401: + throw new Exception(Exception::GENERAL_UNAUTHORIZED_SCOPE, 'Source Error: ' . $e->getMessage()); + case 429: + throw new Exception(Exception::GENERAL_RATE_LIMIT_EXCEEDED, 'Source Error: Rate Limit Exceeded, Is your Cloud Provider blocking Appwrite\'s IP?'); + case 500: + throw new Exception(Exception::MIGRATION_PROVIDER_ERROR, 'Source Error: ' . $e->getMessage()); + } + + throw new Exception(Exception::MIGRATION_PROVIDER_ERROR, 'Source Error: ' . $e->getMessage()); } + + $response + ->setStatusCode(Response::STATUS_CODE_OK) + ->dynamic(new Document($report), Response::MODEL_MIGRATION_REPORT); }); App::get('/v1/migrations/firebase/report') @@ -475,15 +496,36 @@ App::get('/v1/migrations/firebase/report') ->param('serviceAccount', '', new Text(65536), 'JSON of the Firebase service account credentials') ->inject('response') ->action(function (array $resources, string $serviceAccount, Response $response) { - try { - $firebase = new Firebase(json_decode($serviceAccount, true)); + $serviceAccount = json_decode($serviceAccount, true); - $response - ->setStatusCode(Response::STATUS_CODE_OK) - ->dynamic(new Document($firebase->report($resources)), Response::MODEL_MIGRATION_REPORT); - } catch (\Exception $e) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Source Error: ' . $e->getMessage()); + if (empty($serviceAccount)) { + throw new Exception(Exception::MIGRATION_PROVIDER_ERROR, 'Invalid Service Account JSON'); } + + if (!isset($serviceAccount['project_id']) || !isset($serviceAccount['client_email']) || !isset($serviceAccount['private_key'])) { + throw new Exception(Exception::MIGRATION_PROVIDER_ERROR, 'Invalid Service Account JSON'); + } + + $firebase = new Firebase($serviceAccount); + + try { + $report = $firebase->report($resources); + } catch (\Throwable $e) { + switch ($e->getCode()) { + case 401: + throw new Exception(Exception::GENERAL_UNAUTHORIZED_SCOPE, 'Source Error: ' . $e->getMessage()); + case 429: + throw new Exception(Exception::GENERAL_RATE_LIMIT_EXCEEDED, 'Source Error: Rate Limit Exceeded, Is your Cloud Provider blocking Appwrite\'s IP?'); + case 500: + throw new Exception(Exception::MIGRATION_PROVIDER_ERROR, 'Source Error: ' . $e->getMessage()); + } + + throw new Exception(Exception::MIGRATION_PROVIDER_ERROR, 'Source Error: ' . $e->getMessage()); + } + + $response + ->setStatusCode(Response::STATUS_CODE_OK) + ->dynamic(new Document($report), Response::MODEL_MIGRATION_REPORT); }); App::get('/v1/migrations/firebase/report/oauth') @@ -869,15 +911,26 @@ App::get('/v1/migrations/supabase/report') ->inject('response') ->inject('dbForProject') ->action(function (array $resources, string $endpoint, string $apiKey, string $databaseHost, string $username, string $password, int $port, Response $response) { - try { - $supabase = new Supabase($endpoint, $apiKey, $databaseHost, 'postgres', $username, $password, $port); + $supabase = new Supabase($endpoint, $apiKey, $databaseHost, 'postgres', $username, $password, $port); - $response - ->setStatusCode(Response::STATUS_CODE_OK) - ->dynamic(new Document($supabase->report($resources)), Response::MODEL_MIGRATION_REPORT); - } catch (\Exception $e) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Source Error: ' . $e->getMessage()); + try { + $report = $supabase->report($resources); + } catch (\Throwable $e) { + switch ($e->getCode()) { + case 401: + throw new Exception(Exception::GENERAL_UNAUTHORIZED_SCOPE, 'Source Error: ' . $e->getMessage()); + case 429: + throw new Exception(Exception::GENERAL_RATE_LIMIT_EXCEEDED, 'Source Error: Rate Limit Exceeded, Is your Cloud Provider blocking Appwrite\'s IP?'); + case 500: + throw new Exception(Exception::MIGRATION_PROVIDER_ERROR, 'Source Error: ' . $e->getMessage()); + } + + throw new Exception(Exception::MIGRATION_PROVIDER_ERROR, 'Source Error: ' . $e->getMessage()); } + + $response + ->setStatusCode(Response::STATUS_CODE_OK) + ->dynamic(new Document($report), Response::MODEL_MIGRATION_REPORT); }); App::get('/v1/migrations/nhost/report') @@ -901,15 +954,26 @@ App::get('/v1/migrations/nhost/report') ->param('port', 5432, new Integer(true), 'Source\'s Database Port.', true) ->inject('response') ->action(function (array $resources, string $subdomain, string $region, string $adminSecret, string $database, string $username, string $password, int $port, Response $response) { - try { - $nhost = new NHost($subdomain, $region, $adminSecret, $database, $username, $password, $port); + $nhost = new NHost($subdomain, $region, $adminSecret, $database, $username, $password, $port); - $response - ->setStatusCode(Response::STATUS_CODE_OK) - ->dynamic(new Document($nhost->report($resources)), Response::MODEL_MIGRATION_REPORT); - } catch (\Exception $e) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Source Error: ' . $e->getMessage()); + try { + $report = $nhost->report($resources); + } catch (\Throwable $e) { + switch ($e->getCode()) { + case 401: + throw new Exception(Exception::GENERAL_UNAUTHORIZED_SCOPE, 'Source Error: ' . $e->getMessage()); + case 429: + throw new Exception(Exception::GENERAL_RATE_LIMIT_EXCEEDED, 'Source Error: Rate Limit Exceeded, Is your Cloud Provider blocking Appwrite\'s IP?'); + case 500: + throw new Exception(Exception::MIGRATION_PROVIDER_ERROR, 'Source Error: ' . $e->getMessage()); + } + + throw new Exception(Exception::MIGRATION_PROVIDER_ERROR, 'Source Error: ' . $e->getMessage()); } + + $response + ->setStatusCode(Response::STATUS_CODE_OK) + ->dynamic(new Document($report), Response::MODEL_MIGRATION_REPORT); }); App::patch('/v1/migrations/:migrationId') diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 77dc03e310..b4892f7aa3 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -223,6 +223,7 @@ class Exception extends \Exception public const MIGRATION_NOT_FOUND = 'migration_not_found'; public const MIGRATION_ALREADY_EXISTS = 'migration_already_exists'; public const MIGRATION_IN_PROGRESS = 'migration_in_progress'; + public const MIGRATION_PROVIDER_ERROR = 'migration_provider_error'; protected $type = ''; protected $errors = []; From d4b53e50145015f88a6eb1189090aa4f06016808 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 13 Oct 2023 16:23:20 +0100 Subject: [PATCH 02/36] Run Linter --- app/controllers/api/migrations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index 360e1ae818..4c4043de96 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -216,7 +216,7 @@ App::post('/v1/migrations/firebase') if (!isset($serviceAccountData['project_id']) || !isset($serviceAccountData['client_email']) || !isset($serviceAccountData['private_key'])) { throw new Exception(Exception::MIGRATION_PROVIDER_ERROR, 'Invalid Service Account JSON'); } - + $migration = $dbForProject->createDocument('migrations', new Document([ '$id' => ID::unique(), 'status' => 'pending', From 23a1da58fba417dd27a4781d1e91bf81bf7ef770 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 16 Oct 2023 11:57:17 +0100 Subject: [PATCH 03/36] Update Status Codes --- app/config/errors.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config/errors.php b/app/config/errors.php index 1f4bda4704..e7dc6c446e 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -731,6 +731,6 @@ return [ Exception::MIGRATION_PROVIDER_ERROR => [ 'name' => Exception::MIGRATION_PROVIDER_ERROR, 'description' => 'An error occurred on the provider\'s side. Please try again later.', - 'code' => 424, + 'code' => 400, ], ]; From ce6d873cf4ed02f4360aa4eb96788659d367f64e Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Tue, 31 Oct 2023 15:55:11 +0530 Subject: [PATCH 04/36] Added cURL timeout and not store response data for webhooks --- src/Appwrite/Platform/Workers/Webhooks.php | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index dd7b92bf5e..423f5bf5cf 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -25,7 +25,7 @@ class Webhooks extends Action $this ->desc('Webhooks worker') ->inject('message') - ->callback(fn($message) => $this->action($message)); + ->callback(fn ($message) => $this->action($message)); } /** @@ -48,7 +48,7 @@ class Webhooks extends Action foreach ($project->getAttribute('webhooks', []) as $webhook) { if (array_intersect($webhook->getAttribute('events', []), $events)) { - $this->execute($events, $webhookPayload, $webhook, $user, $project); + $this->execute($events, $webhookPayload, $webhook, $user, $project); } } @@ -78,7 +78,8 @@ class Webhooks extends Action \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); \curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); \curl_setopt($ch, CURLOPT_HEADER, 0); - \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); + \curl_setopt($ch, CURLOPT_TIMEOUT, 15); \curl_setopt($ch, CURLOPT_USERAGENT, \sprintf( APP_USERAGENT, App::getEnv('_APP_VERSION', 'UNKNOWN'), @@ -88,14 +89,14 @@ class Webhooks extends Action $ch, CURLOPT_HTTPHEADER, [ - 'Content-Type: application/json', - 'Content-Length: ' . \strlen($payload), - 'X-' . APP_NAME . '-Webhook-Id: ' . $webhook->getId(), - 'X-' . APP_NAME . '-Webhook-Events: ' . implode(',', $events), - 'X-' . APP_NAME . '-Webhook-Name: ' . $webhook->getAttribute('name', ''), - 'X-' . APP_NAME . '-Webhook-User-Id: ' . $user->getId(), - 'X-' . APP_NAME . '-Webhook-Project-Id: ' . $project->getId(), - 'X-' . APP_NAME . '-Webhook-Signature: ' . $signature, + 'Content-Type: application/json', + 'Content-Length: ' . \strlen($payload), + 'X-' . APP_NAME . '-Webhook-Id: ' . $webhook->getId(), + 'X-' . APP_NAME . '-Webhook-Events: ' . implode(',', $events), + 'X-' . APP_NAME . '-Webhook-Name: ' . $webhook->getAttribute('name', ''), + 'X-' . APP_NAME . '-Webhook-User-Id: ' . $user->getId(), + 'X-' . APP_NAME . '-Webhook-Project-Id: ' . $project->getId(), + 'X-' . APP_NAME . '-Webhook-Signature: ' . $signature, ] ); From 64630490a551114bb241c7cde44dd6a533a13466 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Wed, 1 Nov 2023 14:36:31 +0530 Subject: [PATCH 05/36] Delete linked VCS repos and comments on function deletion --- src/Appwrite/Platform/Workers/Deletes.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 2130499257..1a2b378590 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -45,7 +45,7 @@ class Deletes extends Action ->inject('getFunctionsDevice') ->inject('getBuildsDevice') ->inject('getCacheDevice') - ->callback(fn($message, $dbForConsole, callable $getProjectDB, callable $getFilesDevice, callable $getFunctionsDevice, callable $getBuildsDevice, callable $getCacheDevice) => $this->action($message, $dbForConsole, $getProjectDB, $getFilesDevice, $getFunctionsDevice, $getBuildsDevice, $getCacheDevice)); + ->callback(fn ($message, $dbForConsole, callable $getProjectDB, callable $getFilesDevice, callable $getFunctionsDevice, callable $getBuildsDevice, callable $getCacheDevice) => $this->action($message, $dbForConsole, $getProjectDB, $getFilesDevice, $getFunctionsDevice, $getBuildsDevice, $getCacheDevice)); } /** @@ -688,7 +688,7 @@ class Deletes extends Action $this->deleteDeploymentFiles($functionsStorage, $document); }); - /** + /** * Delete builds */ Console::info("Deleting builds for function " . $functionId); @@ -709,6 +709,22 @@ class Deletes extends Action Query::equal('functionInternalId', [$functionInternalId]) ], $dbForProject); + /** + * Delete VCS Repositories and VCS Comments + */ + Console::info("Deleting VCS repositories and comments linked to function " . $functionId); + $this->deleteByGroup('repositories', [ + Query::equal('resourceInternalId', [$functionInternalId]), + Query::equal('resourceType', ['function']), + ], $dbForConsole, function (Document $document) use ($dbForConsole) { + $providerRepositoryId = $document->getAttribute('providerRepositoryId', ''); + $projectId = $document->getAttribute('projectId', ''); + $this->deleteByGroup('vcsComments', [ + Query::equal('providerRepositoryId', [$providerRepositoryId]), + Query::equal('projectId', [$projectId]), + ], $dbForConsole); + }); + /** * Request executor to delete all deployment containers */ From d95e4790a0834b9d2e504c8d8adc1f2253c525ae Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Wed, 1 Nov 2023 15:06:28 +0530 Subject: [PATCH 06/36] Delete VCS documents when project is deleted --- src/Appwrite/Platform/Workers/Deletes.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 1a2b378590..048a7c81ec 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -450,6 +450,23 @@ class Deletes extends Action Query::equal('projectInternalId', [$projectInternalId]) ], $dbForConsole); + // Delete VCS Installations, Repositories and Comments + $this->deleteByGroup('installations', [ + Query::equal('projectInternalId', [$projectInternalId]) + ], $dbForConsole, function (Document $document) use ($dbForConsole) { + $projectInternalId = $document->getAttribute('projectInternalId', ''); + $this->deleteByGroup('repositories', [ + Query::equal('installationInternalId', [$projectInternalId]), + ], $dbForConsole, function (Document $document) use ($dbForConsole) { + $providerRepositoryId = $document->getAttribute('providerRepositoryId', ''); + $projectId = $document->getAttribute('projectId', ''); + $this->deleteByGroup('vcsComments', [ + Query::equal('providerRepositoryId', [$providerRepositoryId]), + Query::equal('projectId', [$projectId]), + ], $dbForConsole); + }); + }); + // Delete metadata tables try { $dbForProject->deleteCollection('_metadata'); From 9be32184d6d187d637bd2061e124eb2ad1833d6d Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Fri, 3 Nov 2023 14:54:51 +0530 Subject: [PATCH 07/36] Refactor loop --- src/Appwrite/Platform/Workers/Deletes.php | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 048a7c81ec..5369419ff5 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -450,21 +450,21 @@ class Deletes extends Action Query::equal('projectInternalId', [$projectInternalId]) ], $dbForConsole); - // Delete VCS Installations, Repositories and Comments + // Delete VCS Installations $this->deleteByGroup('installations', [ Query::equal('projectInternalId', [$projectInternalId]) + ], $dbForConsole); + + // Delete VCS Repositories and Comments + $this->deleteByGroup('repositories', [ + Query::equal('installationInternalId', [$projectInternalId]), ], $dbForConsole, function (Document $document) use ($dbForConsole) { - $projectInternalId = $document->getAttribute('projectInternalId', ''); - $this->deleteByGroup('repositories', [ - Query::equal('installationInternalId', [$projectInternalId]), - ], $dbForConsole, function (Document $document) use ($dbForConsole) { - $providerRepositoryId = $document->getAttribute('providerRepositoryId', ''); - $projectId = $document->getAttribute('projectId', ''); - $this->deleteByGroup('vcsComments', [ - Query::equal('providerRepositoryId', [$providerRepositoryId]), - Query::equal('projectId', [$projectId]), - ], $dbForConsole); - }); + $providerRepositoryId = $document->getAttribute('providerRepositoryId', ''); + $projectId = $document->getAttribute('projectId', ''); + $this->deleteByGroup('vcsComments', [ + Query::equal('providerRepositoryId', [$providerRepositoryId]), + Query::equal('projectId', [$projectId]), + ], $dbForConsole); }); // Delete metadata tables From 4a3b8fb70e8a3b80c41b33900695fb981e17e902 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Fri, 3 Nov 2023 15:32:50 +0530 Subject: [PATCH 08/36] Change projectId to projectInternalId --- src/Appwrite/Platform/Workers/Deletes.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 5369419ff5..7a22128854 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -457,13 +457,13 @@ class Deletes extends Action // Delete VCS Repositories and Comments $this->deleteByGroup('repositories', [ - Query::equal('installationInternalId', [$projectInternalId]), + Query::equal('projectInternalId', [$projectInternalId]), ], $dbForConsole, function (Document $document) use ($dbForConsole) { $providerRepositoryId = $document->getAttribute('providerRepositoryId', ''); - $projectId = $document->getAttribute('projectId', ''); + $projectInternalId = $document->getAttribute('projectInternalId', ''); $this->deleteByGroup('vcsComments', [ Query::equal('providerRepositoryId', [$providerRepositoryId]), - Query::equal('projectId', [$projectId]), + Query::equal('projectInternalId', [$projectInternalId]), ], $dbForConsole); }); From 9f7bbe48691eea111e8189622b6b32514d919e4f Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Fri, 3 Nov 2023 16:57:30 +0000 Subject: [PATCH 09/36] Fix the Health service's get X queue endpoints Before this, the endpoints called $client->sumProcessingJobs() which only gets the currently processing jobs, but this endpoint should return what's currently in queue, pending to be processed. This should be retrieved using $client->getQueueSize(). --- app/controllers/api/health.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 8ca1371488..b1195cd878 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -352,7 +352,7 @@ App::get('/v1/health/queue/webhooks') ->inject('response') ->action(function (Connection $queue, Response $response) { $client = new Client(Event::WEBHOOK_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->sumProcessingJobs() ]), Response::MODEL_HEALTH_QUEUE); + $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/logs') @@ -370,7 +370,7 @@ App::get('/v1/health/queue/logs') ->inject('response') ->action(function (Connection $queue, Response $response) { $client = new Client(Event::AUDITS_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->sumProcessingJobs() ]), Response::MODEL_HEALTH_QUEUE); + $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/certificates') @@ -388,7 +388,7 @@ App::get('/v1/health/queue/certificates') ->inject('response') ->action(function (Connection $queue, Response $response) { $client = new Client(Event::CERTIFICATES_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->sumProcessingJobs() ]), Response::MODEL_HEALTH_QUEUE); + $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/builds') @@ -406,7 +406,7 @@ App::get('/v1/health/queue/builds') ->inject('response') ->action(function (Connection $queue, Response $response) { $client = new Client(Event::BUILDS_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->sumProcessingJobs() ]), Response::MODEL_HEALTH_QUEUE); + $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/databases') @@ -425,7 +425,7 @@ App::get('/v1/health/queue/databases') ->inject('response') ->action(function (string $name, Connection $queue, Response $response) { $client = new Client($name, $queue); - $response->dynamic(new Document([ 'size' => $client->sumProcessingJobs() ]), Response::MODEL_HEALTH_QUEUE); + $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/deletes') @@ -443,7 +443,7 @@ App::get('/v1/health/queue/deletes') ->inject('response') ->action(function (Connection $queue, Response $response) { $client = new Client(Event::DELETE_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->sumProcessingJobs() ]), Response::MODEL_HEALTH_QUEUE); + $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/mails') @@ -461,7 +461,7 @@ App::get('/v1/health/queue/mails') ->inject('response') ->action(function (Connection $queue, Response $response) { $client = new Client(Event::MAILS_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->sumProcessingJobs() ]), Response::MODEL_HEALTH_QUEUE); + $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/messaging') @@ -479,7 +479,7 @@ App::get('/v1/health/queue/messaging') ->inject('response') ->action(function (Connection $queue, Response $response) { $client = new Client(Event::MESSAGING_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->sumProcessingJobs() ]), Response::MODEL_HEALTH_QUEUE); + $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/migrations') @@ -497,7 +497,7 @@ App::get('/v1/health/queue/migrations') ->inject('response') ->action(function (Connection $queue, Response $response) { $client = new Client(Event::MIGRATIONS_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->sumProcessingJobs() ]), Response::MODEL_HEALTH_QUEUE); + $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/functions') @@ -515,7 +515,7 @@ App::get('/v1/health/queue/functions') ->inject('response') ->action(function (Connection $queue, Response $response) { $client = new Client(Event::FUNCTIONS_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->sumProcessingJobs() ]), Response::MODEL_HEALTH_QUEUE); + $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/storage/local') From 03da0380ea8bfc11d2d5611a9b416128245b98cc Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Fri, 3 Nov 2023 17:47:16 +0000 Subject: [PATCH 10/36] Ensure schedules for deleted projects are deleted --- src/Appwrite/Platform/Workers/Deletes.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 2130499257..b699ba9e17 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -178,7 +178,8 @@ class Deletes extends Action $project = $dbForConsole->getDocument('projects', $document->getAttribute('projectId')); if ($project->isEmpty()) { - Console::warning('Unable to delete schedule for function ' . $document->getAttribute('resourceId')); + $dbForConsole->deleteDocument('schedules', $document->getId()); + Console::success('Deleted schedule for deleted project ' . $document->getAttribute('projectId')); return; } From 30b8ff9166f17aba3450fbbafc6caaf4a58c380d Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Fri, 3 Nov 2023 17:47:52 +0000 Subject: [PATCH 11/36] Add pagination to listByGroup to fix infinite loop problem --- src/Appwrite/Platform/Workers/Deletes.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index b699ba9e17..b91ddb901a 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -921,17 +921,28 @@ class Deletes extends Action $count = 0; $chunk = 0; $limit = 50; + $results = []; $sum = $limit; + $cursor = null; $executionStart = \microtime(true); while ($sum === $limit) { $chunk++; - $results = $database->find($collection, \array_merge([Query::limit($limit)], $queries)); + $mergedQueries = \array_merge([Query::limit($limit)], $queries); + if ($cursor instanceof Document) { + $mergedQueries[] = Query::cursorAfter($cursor); + } + + $results = $database->find($collection, $mergedQueries); $sum = count($results); + if ($sum > 0) { + $cursor = $results[$sum - 1]; + } + foreach ($results as $document) { if (is_callable($callback)) { $callback($document); From 1429c82aa07b2ffda8407ddb68462594c57be7ed Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 6 Nov 2023 12:04:56 +1300 Subject: [PATCH 12/36] Make VCS, proxy and migrations services non-optional so they aren't toggled with enable/disable all service routes --- app/config/services.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/config/services.php b/app/config/services.php index 3700af659a..5c2233dfc6 100644 --- a/app/config/services.php +++ b/app/config/services.php @@ -170,7 +170,7 @@ return [ 'docs' => false, 'docsUrl' => '', 'tests' => false, - 'optional' => true, + 'optional' => false, 'icon' => '', ], 'functions' => [ @@ -196,7 +196,7 @@ return [ 'docs' => true, 'docsUrl' => 'https://appwrite.io/docs/proxy', 'tests' => false, - 'optional' => true, + 'optional' => false, 'icon' => '/images/services/proxy.png', ], 'mock' => [ @@ -248,7 +248,7 @@ return [ 'docs' => true, 'docsUrl' => 'https://appwrite.io/docs/migrations', 'tests' => true, - 'optional' => true, + 'optional' => false, 'icon' => '/images/services/migrations.png', ], ]; From 2292143750a4b1527b159469bd5d70690146874f Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 6 Nov 2023 12:34:44 +1300 Subject: [PATCH 13/36] Add service/all test --- .../Projects/ProjectsConsoleClientTest.php | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index ff3f8e8e94..f90a04f290 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -1606,6 +1606,100 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(false, $response['body']['authPersonalDataCheck']); } + public function testUpdateProjectServicesAll(): void + { + $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + ]), [ + 'teamId' => ID::unique(), + 'name' => 'Project Test', + ]); + + $this->assertEquals(201, $team['headers']['status-code']); + $this->assertNotEmpty($team['body']['$id']); + + $project = $this->client->call(Client::METHOD_POST, '/projects', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + ]), [ + 'projectId' => ID::unique(), + 'name' => 'Project Test', + 'teamId' => $team['body']['$id'], + 'region' => 'default' + ]); + + $this->assertEquals(201, $project['headers']['status-code']); + $this->assertNotEmpty($project['body']['$id']); + + $id = $project['body']['$id']; + + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service/all', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + ]), [ + 'status' => false, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + ])); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + + $matches = []; + $pattern = '/serviceStatusFor.*/'; + + foreach ($response['body'] as $key => $value) { + if (\preg_match($pattern, $key)) { + \var_dump('Matched key: ' . $key); + $matches[$key] = $value; + } + } + + foreach ($matches as $value) { + $this->assertFalse($value); + } + + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service/all', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + ]), [ + 'status' => true, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + ])); + + $this->assertEquals(200, $response['headers']['status-code']); + + $matches = []; + foreach ($response['body'] as $key => $value) { + if (\preg_match($pattern, $key)) { + $matches[$key] = $value; + } + } + + foreach ($matches as $value) { + $this->assertTrue($value); + } + } public function testUpdateProjectServiceStatusAdmin(): array { From 8b24c44fb9fcad2d120e5b5b65a27c5bb8b206cc Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:44:00 +0000 Subject: [PATCH 14/36] fix: proxy create rule 500 --- app/controllers/api/proxy.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index f9621fb05a..0d1428cf23 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -87,8 +87,12 @@ App::post('/v1/proxy/rules') $resourceInternalId = $function->getInternalId(); } - $domain = new Domain($domain); - + try { + $domain = new Domain($domain); + } catch (Exception) { + throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Invalid domain. Domain may not start with http:// or https://.'); + } + $ruleId = ID::unique(); $rule = new Document([ '$id' => $ruleId, From 61c5f371b754146383e7b65126611b18917b856b Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:45:56 +0000 Subject: [PATCH 15/36] chore: use base Exception --- app/controllers/api/proxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index 0d1428cf23..9bfb546b95 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -89,7 +89,7 @@ App::post('/v1/proxy/rules') try { $domain = new Domain($domain); - } catch (Exception) { + } catch (\Exception) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Invalid domain. Domain may not start with http:// or https://.'); } From 4440859c0565b35a2da8778330f65793ae2d3be8 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:48:54 +0000 Subject: [PATCH 16/36] chore: fmt --- app/controllers/api/proxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index 9bfb546b95..6b93912a2a 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -92,7 +92,7 @@ App::post('/v1/proxy/rules') } catch (\Exception) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Invalid domain. Domain may not start with http:// or https://.'); } - + $ruleId = ID::unique(); $rule = new Document([ '$id' => $ruleId, From 75669b9b2ea59815e7ecabd87aba25ccb32fd18f Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:49:33 +0000 Subject: [PATCH 17/36] chore: better error msg --- app/controllers/api/proxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index 6b93912a2a..23916a114c 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -90,7 +90,7 @@ App::post('/v1/proxy/rules') try { $domain = new Domain($domain); } catch (\Exception) { - throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Invalid domain. Domain may not start with http:// or https://.'); + throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Domain may not start with http:// or https://.'); } $ruleId = ID::unique(); From dfc8c919d4c601e8d8ec20ea506616e01f12d87d Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Mon, 6 Nov 2023 15:06:56 +0000 Subject: [PATCH 18/36] fix: missing sessionId error --- app/controllers/api/users.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index fcaa2ff641..d6e21c212e 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -1127,7 +1127,7 @@ App::delete('/v1/users/:userId/sessions/:sessionId') App::delete('/v1/users/:userId/sessions') ->desc('Delete user sessions') ->groups(['api', 'users']) - ->label('event', 'users.[userId].sessions.[sessionId].delete') + ->label('event', 'users.[userId].sessions.delete') ->label('scope', 'users.write') ->label('audits.event', 'session.delete') ->label('audits.resource', 'user/{user.$id}') From 55a73efeab1a1a0b43b696c3c98b723e5298f1f4 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Mon, 6 Nov 2023 21:28:45 +0000 Subject: [PATCH 19/36] Ensure usage endpoints don't throw 500 when usage is disabled --- app/controllers/api/databases.php | 6 +++--- app/controllers/shared/api.php | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index aaf30e00c3..f47e3f8265 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -3632,7 +3632,7 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/documents/:docu App::get('/v1/databases/usage') ->desc('Get usage stats for the database') - ->groups(['api', 'database']) + ->groups(['api', 'database', 'usage']) ->label('scope', 'collections.read') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN]) ->label('sdk.namespace', 'databases') @@ -3750,7 +3750,7 @@ App::get('/v1/databases/usage') App::get('/v1/databases/:databaseId/usage') ->desc('Get usage stats for the database') - ->groups(['api', 'database']) + ->groups(['api', 'database', 'usage']) ->label('scope', 'collections.read') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN]) ->label('sdk.namespace', 'databases') @@ -3860,7 +3860,7 @@ App::get('/v1/databases/:databaseId/usage') App::get('/v1/databases/:databaseId/collections/:collectionId/usage') ->alias('/v1/database/:collectionId/usage', ['databaseId' => 'default']) ->desc('Get usage stats for a collection') - ->groups(['api', 'database']) + ->groups(['api', 'database', 'usage']) ->label('scope', 'collections.read') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN]) ->label('sdk.namespace', 'databases') diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 388851faef..b37d76a816 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -554,3 +554,11 @@ App::shutdown() ->submit(); } }); + +App::init() + ->groups(['usage']) + ->action(function () { + if (App::getEnv('_APP_USAGE_STATS', 'enabled') !== 'enabled') { + throw new Exception(Exception::GENERAL_USAGE_DISABLED); + } + }); From 7e37c973cec84113680ab4ace9e840be64cf8045 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 7 Nov 2023 10:25:33 +0000 Subject: [PATCH 20/36] fix: missing functionId error on create execution --- app/controllers/api/functions.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 96827beb3c..268acc0692 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1658,6 +1658,8 @@ App::post('/v1/functions/:functionId/executions') ->setJWT($jwt) ->setProject($project) ->setUser($user) + ->setParam('functionId', $function->getId()) + ->setParam('executionId', $execution->getId()) ->trigger(); return $response From 44cbfb2769485257a023e7dc0788c2b9ade303dd Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Tue, 7 Nov 2023 16:17:14 +0000 Subject: [PATCH 21/36] Add null check to hash --- src/Appwrite/Auth/Validator/PasswordHistory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Auth/Validator/PasswordHistory.php b/src/Appwrite/Auth/Validator/PasswordHistory.php index 8cfabf4666..fb73ea6c9f 100644 --- a/src/Appwrite/Auth/Validator/PasswordHistory.php +++ b/src/Appwrite/Auth/Validator/PasswordHistory.php @@ -44,7 +44,7 @@ class PasswordHistory extends Password public function isValid($value): bool { foreach ($this->history as $hash) { - if (Auth::passwordVerify($value, $hash, $this->algo, $this->algoOptions)) { + if (!empty($hash) && Auth::passwordVerify($value, $hash, $this->algo, $this->algoOptions)) { return false; } } From 698bce2c364308bef7283751c2c3eb175977da2e Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Wed, 8 Nov 2023 12:32:48 +0530 Subject: [PATCH 22/36] Limit max redirects to 5 --- src/Appwrite/Platform/Workers/Webhooks.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index 423f5bf5cf..889a1cb36c 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -99,7 +99,8 @@ class Webhooks extends Action 'X-' . APP_NAME . '-Webhook-Signature: ' . $signature, ] ); - + curl_setopt($ch, CURLOPT_MAXREDIRS, 5); + if (!$webhook->getAttribute('security', true)) { \curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); \curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); From 365c52026746a8d71c53358e95a09cc039f16503 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Wed, 8 Nov 2023 12:41:16 +0530 Subject: [PATCH 23/36] Fixed linter error --- src/Appwrite/Platform/Workers/Webhooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index 889a1cb36c..2eff81ee7f 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -100,7 +100,7 @@ class Webhooks extends Action ] ); curl_setopt($ch, CURLOPT_MAXREDIRS, 5); - + if (!$webhook->getAttribute('security', true)) { \curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); \curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); From e461a4f14bbbd5bf6e2e26b00a699974a3de2d30 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Wed, 8 Nov 2023 16:09:17 +0530 Subject: [PATCH 24/36] Added max download limit of 1 GB --- src/Appwrite/Platform/Workers/Webhooks.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index 2eff81ee7f..4d67df804c 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -80,6 +80,7 @@ class Webhooks extends Action \curl_setopt($ch, CURLOPT_HEADER, 0); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); \curl_setopt($ch, CURLOPT_TIMEOUT, 15); + \curl_setopt($ch, CURLOPT_MAXFILESIZE, 1073741824); \curl_setopt($ch, CURLOPT_USERAGENT, \sprintf( APP_USERAGENT, App::getEnv('_APP_VERSION', 'UNKNOWN'), From 05ab73ee37d2c14c7fa79d4d0066118eab8f7095 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Wed, 8 Nov 2023 17:12:07 +0530 Subject: [PATCH 25/36] Update download limit to 5 MB --- src/Appwrite/Platform/Workers/Webhooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index 4d67df804c..fa25145a13 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -80,7 +80,7 @@ class Webhooks extends Action \curl_setopt($ch, CURLOPT_HEADER, 0); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); \curl_setopt($ch, CURLOPT_TIMEOUT, 15); - \curl_setopt($ch, CURLOPT_MAXFILESIZE, 1073741824); + \curl_setopt($ch, CURLOPT_MAXFILESIZE, 5242880); \curl_setopt($ch, CURLOPT_USERAGENT, \sprintf( APP_USERAGENT, App::getEnv('_APP_VERSION', 'UNKNOWN'), From 54e5985940a90f53ca2b6b281e9942fb59caf91d Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 8 Nov 2023 14:35:16 +0000 Subject: [PATCH 26/36] Fix wrong operator for password history This fixes a potential chance for nulls to be introduced into the password history array when $password is null and $passwordHistory != 0 --- app/controllers/api/users.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index fcaa2ff641..b9ae42e2d6 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -85,7 +85,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e 'status' => true, 'labels' => [], 'password' => $password, - 'passwordHistory' => is_null($password) && $passwordHistory === 0 ? [] : [$password], + 'passwordHistory' => is_null($password) || $passwordHistory === 0 ? [] : [$password], 'passwordUpdate' => (!empty($password)) ? DateTime::now() : null, 'hash' => $hash === 'plaintext' ? Auth::DEFAULT_ALGO : $hash, 'hashOptions' => $hash === 'plaintext' ? Auth::DEFAULT_ALGO_OPTIONS : $hashOptionsObject + ['type' => $hash], From 2bf247053d8f71de336e2fa152db0fa411dd771d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=B7=E5=8D=8E=20=E5=88=98?= Date: Wed, 8 Nov 2023 21:59:29 +0000 Subject: [PATCH 27/36] chore: address review comments --- src/Appwrite/Platform/Workers/Deletes.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 7a22128854..269dc61e3c 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -455,17 +455,15 @@ class Deletes extends Action Query::equal('projectInternalId', [$projectInternalId]) ], $dbForConsole); - // Delete VCS Repositories and Comments + // Delete VCS Repositories $this->deleteByGroup('repositories', [ Query::equal('projectInternalId', [$projectInternalId]), - ], $dbForConsole, function (Document $document) use ($dbForConsole) { - $providerRepositoryId = $document->getAttribute('providerRepositoryId', ''); - $projectInternalId = $document->getAttribute('projectInternalId', ''); - $this->deleteByGroup('vcsComments', [ - Query::equal('providerRepositoryId', [$providerRepositoryId]), - Query::equal('projectInternalId', [$projectInternalId]), - ], $dbForConsole); - }); + ], $dbForConsole); + + // Delete VCS commments + $this->deleteByGroup('vcsComments', [ + Query::equal('projectInternalId', [$projectInternalId]), + ], $dbForConsole); // Delete metadata tables try { From 5087ae61e796674aaff06ac1010c53477168f500 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Thu, 9 Nov 2023 05:51:47 +0000 Subject: [PATCH 28/36] Bump utopia-php/vcs and utopia-php/messaging --- composer.lock | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/composer.lock b/composer.lock index e8334179ff..899db7560d 100644 --- a/composer.lock +++ b/composer.lock @@ -2318,16 +2318,16 @@ }, { "name": "utopia-php/migration", - "version": "0.3.5", + "version": "0.3.6", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "b2fd3a8310296f4e44ff0e85b0eb0230ad9a2f83" + "reference": "f78273b38bade23db5866e5c7cb5f55427ba82af" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/b2fd3a8310296f4e44ff0e85b0eb0230ad9a2f83", - "reference": "b2fd3a8310296f4e44ff0e85b0eb0230ad9a2f83", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/f78273b38bade23db5866e5c7cb5f55427ba82af", + "reference": "f78273b38bade23db5866e5c7cb5f55427ba82af", "shasum": "" }, "require": { @@ -2360,9 +2360,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/0.3.5" + "source": "https://github.com/utopia-php/migration/tree/0.3.6" }, - "time": "2023-09-25T16:51:47+00:00" + "time": "2023-11-02T15:13:03+00:00" }, { "name": "utopia-php/mongo", @@ -2904,16 +2904,16 @@ }, { "name": "utopia-php/vcs", - "version": "0.6.1", + "version": "0.6.2", "source": { "type": "git", "url": "https://github.com/utopia-php/vcs.git", - "reference": "d161d1156ef336d197a8d45384b531e5ec31243d" + "reference": "f135291b87cb45335fc6608722e7f89894bc33ee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/vcs/zipball/d161d1156ef336d197a8d45384b531e5ec31243d", - "reference": "d161d1156ef336d197a8d45384b531e5ec31243d", + "url": "https://api.github.com/repos/utopia-php/vcs/zipball/f135291b87cb45335fc6608722e7f89894bc33ee", + "reference": "f135291b87cb45335fc6608722e7f89894bc33ee", "shasum": "" }, "require": { @@ -2947,9 +2947,9 @@ ], "support": { "issues": "https://github.com/utopia-php/vcs/issues", - "source": "https://github.com/utopia-php/vcs/tree/0.6.1" + "source": "https://github.com/utopia-php/vcs/tree/0.6.2" }, - "time": "2023-10-19T07:43:31+00:00" + "time": "2023-11-08T15:36:03+00:00" }, { "name": "utopia-php/websocket", @@ -5822,5 +5822,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } From f70b418c5c370d7bc741379be17fff70c12393e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=B7=E5=8D=8E=20=E5=88=98?= Date: Thu, 9 Nov 2023 15:57:37 +0000 Subject: [PATCH 29/36] chore: updates for appwrite 1.4.10 --- .gitmodules | 2 +- CHANGES.md | 5 +++++ README-CN.md | 6 +++--- README.md | 6 +++--- app/console | 2 +- app/init.php | 2 +- src/Appwrite/Migration/Migration.php | 1 + 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.gitmodules b/.gitmodules index fc1a92efee..ff2e0a6aab 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "app/console"] path = app/console url = https://github.com/appwrite/console - branch = 3.2.5 + branch = 3.2.6 diff --git a/CHANGES.md b/CHANGES.md index 0363f28683..0e06f734f8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +# Version 1.4.10 + +## Bug fixes + + # Version 1.4.9 ## Bug fixes diff --git a/README-CN.md b/README-CN.md index 4a2f9edd65..da6785c750 100644 --- a/README-CN.md +++ b/README-CN.md @@ -66,7 +66,7 @@ docker run -it --rm \ --volume /var/run/docker.sock:/var/run/docker.sock \ --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \ --entrypoint="install" \ - appwrite/appwrite:1.4.9 + appwrite/appwrite:1.4.10 ``` ### Windows @@ -78,7 +78,7 @@ docker run -it --rm ^ --volume //var/run/docker.sock:/var/run/docker.sock ^ --volume "%cd%"/appwrite:/usr/src/code/appwrite:rw ^ --entrypoint="install" ^ - appwrite/appwrite:1.4.9 + appwrite/appwrite:1.4.10 ``` #### PowerShell @@ -88,7 +88,7 @@ docker run -it --rm ` --volume /var/run/docker.sock:/var/run/docker.sock ` --volume ${pwd}/appwrite:/usr/src/code/appwrite:rw ` --entrypoint="install" ` - appwrite/appwrite:1.4.9 + appwrite/appwrite:1.4.10 ``` 运行后,可以在浏览器上访问 http://localhost 找到 Appwrite 控制台。在非 Linux 的本机主机上完成安装后,服务器可能需要几分钟才能启动。 diff --git a/README.md b/README.md index 9b4ba2bb58..9a59f52ec7 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ docker run -it --rm \ --volume /var/run/docker.sock:/var/run/docker.sock \ --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \ --entrypoint="install" \ - appwrite/appwrite:1.4.9 + appwrite/appwrite:1.4.10 ``` ### Windows @@ -88,7 +88,7 @@ docker run -it --rm ^ --volume //var/run/docker.sock:/var/run/docker.sock ^ --volume "%cd%"/appwrite:/usr/src/code/appwrite:rw ^ --entrypoint="install" ^ - appwrite/appwrite:1.4.9 + appwrite/appwrite:1.4.10 ``` #### PowerShell @@ -98,7 +98,7 @@ docker run -it --rm ` --volume /var/run/docker.sock:/var/run/docker.sock ` --volume ${pwd}/appwrite:/usr/src/code/appwrite:rw ` --entrypoint="install" ` - appwrite/appwrite:1.4.9 + appwrite/appwrite:1.4.10 ``` Once the Docker installation is complete, go to http://localhost to access the Appwrite console from your browser. Please note that on non-Linux native hosts, the server might take a few minutes to start after completing the installation. diff --git a/app/console b/app/console index 9810ce8581..f7c34a1b37 160000 --- a/app/console +++ b/app/console @@ -1 +1 @@ -Subproject commit 9810ce85812ca26c95b7d35196848c92e8ba813d +Subproject commit f7c34a1b37d53dd5f28c83b4e12a4e68fcd9b484 diff --git a/app/init.php b/app/init.php index e4b9e7573d..a6809bae36 100644 --- a/app/init.php +++ b/app/init.php @@ -110,7 +110,7 @@ const APP_KEY_ACCCESS = 24 * 60 * 60; // 24 hours const APP_USER_ACCCESS = 24 * 60 * 60; // 24 hours const APP_CACHE_UPDATE = 24 * 60 * 60; // 24 hours const APP_CACHE_BUSTER = 515; -const APP_VERSION_STABLE = '1.4.9'; +const APP_VERSION_STABLE = '1.4.10'; const APP_DATABASE_ATTRIBUTE_EMAIL = 'email'; const APP_DATABASE_ATTRIBUTE_ENUM = 'enum'; const APP_DATABASE_ATTRIBUTE_IP = 'ip'; diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index efa0fad8fb..e370f4dc75 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -74,6 +74,7 @@ abstract class Migration '1.4.7' => 'V19', '1.4.8' => 'V19', '1.4.9' => 'V19', + '1.4.10' => 'V19', ]; /** From c014e40c5485fdbf43b2e3605bed6d9e4568dad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=B7=E5=8D=8E=20=E5=88=98?= Date: Thu, 9 Nov 2023 16:05:33 +0000 Subject: [PATCH 30/36] chore: update changelog --- CHANGES.md | 10 +++++++++- src/Appwrite/Migration/Migration.php | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0e06f734f8..15673a133b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,15 @@ # Version 1.4.10 ## Bug fixes - +* Handle cases where password history could contain NULLs [#7092](https://github.com/appwrite/appwrite/pull/7092) +* Missing functionId error on create execution [#7091] (https://github.com/appwrite/appwrite/pull/7091) +* Ensure usage endpoints don't throw 500 when usage is disabled [#7087](https://github.com/appwrite/appwrite/pull/7087) +* Missing sessionId error when deleting all user sessions [#7085](https://github.com/appwrite/appwrite/pull/7085) +* Domain validation in Create Proxy rule results in 500 error [#7084](https://github.com/appwrite/appwrite/pull/7084) +* Fix optional services [#7078](https://github.com/appwrite/appwrite/pull/7078) +* Fix regression from worker refactor [#7074](https://github.com/appwrite/appwrite/pull/7074) +* Use getQueueSize() in the Health service's get X queue endpoints [#7073](https://github.com/appwrite/appwrite/pull/7073) +* Delete linked VCS repos and comments [#7066](https://github.com/appwrite/appwrite/pull/7066) # Version 1.4.9 diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index e370f4dc75..929eeb4d36 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -74,7 +74,7 @@ abstract class Migration '1.4.7' => 'V19', '1.4.8' => 'V19', '1.4.9' => 'V19', - '1.4.10' => 'V19', + '1.4.10' => 'V19' ]; /** From f1ea4f761e541ac4f4c762a12e57a091ce52ed8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=B7=E5=8D=8E=20=E5=88=98?= Date: Thu, 9 Nov 2023 16:08:20 +0000 Subject: [PATCH 31/36] chore: fix markdown syntax --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 15673a133b..b5140d7b88 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,7 @@ ## Bug fixes * Handle cases where password history could contain NULLs [#7092](https://github.com/appwrite/appwrite/pull/7092) -* Missing functionId error on create execution [#7091] (https://github.com/appwrite/appwrite/pull/7091) +* Missing functionId error on create execution [#7091](https://github.com/appwrite/appwrite/pull/7091) * Ensure usage endpoints don't throw 500 when usage is disabled [#7087](https://github.com/appwrite/appwrite/pull/7087) * Missing sessionId error when deleting all user sessions [#7085](https://github.com/appwrite/appwrite/pull/7085) * Domain validation in Create Proxy rule results in 500 error [#7084](https://github.com/appwrite/appwrite/pull/7084) From 17919ecfbe205bb84efeb0e63888819dca17e614 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 10 Nov 2023 12:11:21 +1300 Subject: [PATCH 32/36] Update database --- composer.json | 6 +++--- composer.lock | 42 +++++++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index 4ce175abea..a24feca83b 100644 --- a/composer.json +++ b/composer.json @@ -43,13 +43,13 @@ "ext-sockets": "*", "appwrite/php-runtimes": "0.13.*", "appwrite/php-clamav": "2.0.*", - "utopia-php/abuse": "0.32.*", + "utopia-php/abuse": "0.33.*", "utopia-php/analytics": "0.10.*", - "utopia-php/audit": "0.34.*", + "utopia-php/audit": "0.35.*", "utopia-php/cache": "0.8.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.44.*", + "utopia-php/database": "0.45.*", "utopia-php/domains": "0.3.*", "utopia-php/dsn": "0.1.*", "utopia-php/framework": "0.31.0", diff --git a/composer.lock b/composer.lock index 899db7560d..25f0c3964d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9afc62ce9c6ba587b9c028e11494e026", + "content-hash": "69bc2e21a65b78344393706b39d789b4", "packages": [ { "name": "adhocore/jwt", @@ -1615,23 +1615,23 @@ }, { "name": "utopia-php/abuse", - "version": "0.32.0", + "version": "0.33.0", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "9717ffb2d7711f3fd621bb6df3edf5724c08ea78" + "reference": "1ba8d5f2793885cbf779e3b5b9d886968af43d2c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/9717ffb2d7711f3fd621bb6df3edf5724c08ea78", - "reference": "9717ffb2d7711f3fd621bb6df3edf5724c08ea78", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/1ba8d5f2793885cbf779e3b5b9d886968af43d2c", + "reference": "1ba8d5f2793885cbf779e3b5b9d886968af43d2c", "shasum": "" }, "require": { "ext-curl": "*", "ext-pdo": "*", "php": ">=8.0", - "utopia-php/database": "0.44.*" + "utopia-php/database": "0.45.*" }, "require-dev": { "laravel/pint": "1.5.*", @@ -1658,9 +1658,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/0.32.0" + "source": "https://github.com/utopia-php/abuse/tree/0.33.0" }, - "time": "2023-10-18T07:28:55+00:00" + "time": "2023-11-01T08:51:33+00:00" }, { "name": "utopia-php/analytics", @@ -1710,21 +1710,21 @@ }, { "name": "utopia-php/audit", - "version": "0.34.0", + "version": "0.35.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "cf34cc3f9f20da4e574a9be4517e1a11025a858f" + "reference": "ed9366ef05556da040de7a8b570f4160c7d8ea4a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/cf34cc3f9f20da4e574a9be4517e1a11025a858f", - "reference": "cf34cc3f9f20da4e574a9be4517e1a11025a858f", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/ed9366ef05556da040de7a8b570f4160c7d8ea4a", + "reference": "ed9366ef05556da040de7a8b570f4160c7d8ea4a", "shasum": "" }, "require": { "php": ">=8.0", - "utopia-php/database": "0.44.*" + "utopia-php/database": "0.45.*" }, "require-dev": { "laravel/pint": "1.5.*", @@ -1751,9 +1751,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/0.34.0" + "source": "https://github.com/utopia-php/audit/tree/0.35.0" }, - "time": "2023-10-18T07:43:25+00:00" + "time": "2023-11-01T08:51:29+00:00" }, { "name": "utopia-php/cache", @@ -1906,16 +1906,16 @@ }, { "name": "utopia-php/database", - "version": "0.44.4", + "version": "0.45.1", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "b0c3fd8ecfedc3646d7780f2d6b38955a66baf48" + "reference": "0e76f996439b80794ab73c2fffdb51ebd6676e4b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/b0c3fd8ecfedc3646d7780f2d6b38955a66baf48", - "reference": "b0c3fd8ecfedc3646d7780f2d6b38955a66baf48", + "url": "https://api.github.com/repos/utopia-php/database/zipball/0e76f996439b80794ab73c2fffdb51ebd6676e4b", + "reference": "0e76f996439b80794ab73c2fffdb51ebd6676e4b", "shasum": "" }, "require": { @@ -1956,9 +1956,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.44.4" + "source": "https://github.com/utopia-php/database/tree/0.45.1" }, - "time": "2023-10-26T07:08:12+00:00" + "time": "2023-11-01T08:30:19+00:00" }, { "name": "utopia-php/domains", From 4d54e7bb3641afb79d0977fd6a691210df7f7433 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 10 Nov 2023 13:09:00 +1300 Subject: [PATCH 33/36] Update version + cache buster --- app/init.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/init.php b/app/init.php index a6809bae36..be6b440498 100644 --- a/app/init.php +++ b/app/init.php @@ -109,8 +109,8 @@ const APP_LIMIT_LIST_DEFAULT = 25; // Default maximum number of items to return const APP_KEY_ACCCESS = 24 * 60 * 60; // 24 hours const APP_USER_ACCCESS = 24 * 60 * 60; // 24 hours const APP_CACHE_UPDATE = 24 * 60 * 60; // 24 hours -const APP_CACHE_BUSTER = 515; -const APP_VERSION_STABLE = '1.4.10'; +const APP_CACHE_BUSTER = 516; +const APP_VERSION_STABLE = '1.4.11'; const APP_DATABASE_ATTRIBUTE_EMAIL = 'email'; const APP_DATABASE_ATTRIBUTE_ENUM = 'enum'; const APP_DATABASE_ATTRIBUTE_IP = 'ip'; From 97757c9984bd327c96e3b90c68ae878185b01899 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 10 Nov 2023 13:25:28 +1300 Subject: [PATCH 34/36] Update readmes + migrations --- CHANGES.md | 6 ++++++ README-CN.md | 6 +++--- README.md | 6 +++--- src/Appwrite/Migration/Migration.php | 3 ++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b5140d7b88..e8f0c08c1f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,9 @@ +# Version 1.4.11 + +## Miscellaneous + +* Update database by @abnegate in [#7111](https://github.com/appwrite/appwrite/pull/7111) + # Version 1.4.10 ## Bug fixes diff --git a/README-CN.md b/README-CN.md index da6785c750..4e45c423c4 100644 --- a/README-CN.md +++ b/README-CN.md @@ -66,7 +66,7 @@ docker run -it --rm \ --volume /var/run/docker.sock:/var/run/docker.sock \ --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \ --entrypoint="install" \ - appwrite/appwrite:1.4.10 + appwrite/appwrite:1.4.11 ``` ### Windows @@ -78,7 +78,7 @@ docker run -it --rm ^ --volume //var/run/docker.sock:/var/run/docker.sock ^ --volume "%cd%"/appwrite:/usr/src/code/appwrite:rw ^ --entrypoint="install" ^ - appwrite/appwrite:1.4.10 + appwrite/appwrite:1.4.11 ``` #### PowerShell @@ -88,7 +88,7 @@ docker run -it --rm ` --volume /var/run/docker.sock:/var/run/docker.sock ` --volume ${pwd}/appwrite:/usr/src/code/appwrite:rw ` --entrypoint="install" ` - appwrite/appwrite:1.4.10 + appwrite/appwrite:1.4.11 ``` 运行后,可以在浏览器上访问 http://localhost 找到 Appwrite 控制台。在非 Linux 的本机主机上完成安装后,服务器可能需要几分钟才能启动。 diff --git a/README.md b/README.md index 9a59f52ec7..88615a355a 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ docker run -it --rm \ --volume /var/run/docker.sock:/var/run/docker.sock \ --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \ --entrypoint="install" \ - appwrite/appwrite:1.4.10 + appwrite/appwrite:1.4.11 ``` ### Windows @@ -88,7 +88,7 @@ docker run -it --rm ^ --volume //var/run/docker.sock:/var/run/docker.sock ^ --volume "%cd%"/appwrite:/usr/src/code/appwrite:rw ^ --entrypoint="install" ^ - appwrite/appwrite:1.4.10 + appwrite/appwrite:1.4.11 ``` #### PowerShell @@ -98,7 +98,7 @@ docker run -it --rm ` --volume /var/run/docker.sock:/var/run/docker.sock ` --volume ${pwd}/appwrite:/usr/src/code/appwrite:rw ` --entrypoint="install" ` - appwrite/appwrite:1.4.10 + appwrite/appwrite:1.4.11 ``` Once the Docker installation is complete, go to http://localhost to access the Appwrite console from your browser. Please note that on non-Linux native hosts, the server might take a few minutes to start after completing the installation. diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index 929eeb4d36..406acae7df 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -74,7 +74,8 @@ abstract class Migration '1.4.7' => 'V19', '1.4.8' => 'V19', '1.4.9' => 'V19', - '1.4.10' => 'V19' + '1.4.10' => 'V19', + '1.4.11' => 'V19', ]; /** From a029287e5a1cb958e59dde4f06268c304f1ab270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 13 Nov 2023 14:07:11 +0100 Subject: [PATCH 35/36] Implement health tresholds --- app/controllers/api/health.php | 131 +++++++++++++++--- .../Health/HealthCustomServerTest.php | 93 +++++++++++++ 2 files changed, 204 insertions(+), 20 deletions(-) diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index e0e26781cf..5d64e71526 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -14,6 +14,7 @@ use Utopia\Registry\Registry; use Utopia\Storage\Device; use Utopia\Storage\Device\Local; use Utopia\Storage\Storage; +use Utopia\Validator\Integer; use Utopia\Validator\Text; App::get('/v1/health') @@ -344,11 +345,20 @@ App::get('/v1/health/queue/webhooks') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) + ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (Connection $queue, Response $response) { + ->action(function (int|string $treshold, Connection $queue, Response $response) { + $treshold = \intval($treshold); + $client = new Client(Event::WEBHOOK_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); + $size = $client->getQueueSize(); + + if ($size >= $treshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + } + + $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/logs') @@ -362,11 +372,20 @@ App::get('/v1/health/queue/logs') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) + ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (Connection $queue, Response $response) { + ->action(function (int|string $treshold, Connection $queue, Response $response) { + $treshold = \intval($treshold); + $client = new Client(Event::AUDITS_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); + $size = $client->getQueueSize(); + + if ($size >= $treshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + } + + $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/certificates') @@ -380,11 +399,20 @@ App::get('/v1/health/queue/certificates') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) + ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (Connection $queue, Response $response) { + ->action(function (int|string $treshold, Connection $queue, Response $response) { + $treshold = \intval($treshold); + $client = new Client(Event::CERTIFICATES_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); + $size = $client->getQueueSize(); + + if ($size >= $treshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + } + + $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/builds') @@ -398,11 +426,20 @@ App::get('/v1/health/queue/builds') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) + ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (Connection $queue, Response $response) { + ->action(function (int|string $treshold, Connection $queue, Response $response) { + $treshold = \intval($treshold); + $client = new Client(Event::BUILDS_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); + $size = $client->getQueueSize(); + + if ($size >= $treshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + } + + $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/databases') @@ -417,11 +454,20 @@ App::get('/v1/health/queue/databases') ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) ->param('name', 'database_db_main', new Text(256), 'Queue name for which to check the queue size', true) + ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (string $name, Connection $queue, Response $response) { + ->action(function (string $name, int|string $treshold, Connection $queue, Response $response) { + $treshold = \intval($treshold); + $client = new Client($name, $queue); - $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); + $size = $client->getQueueSize(); + + if ($size >= $treshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + } + + $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/deletes') @@ -435,11 +481,20 @@ App::get('/v1/health/queue/deletes') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) + ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (Connection $queue, Response $response) { + ->action(function (int|string $treshold, Connection $queue, Response $response) { + $treshold = \intval($treshold); + $client = new Client(Event::DELETE_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); + $size = $client->getQueueSize(); + + if ($size >= $treshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + } + + $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/mails') @@ -453,11 +508,20 @@ App::get('/v1/health/queue/mails') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) + ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (Connection $queue, Response $response) { + ->action(function (int|string $treshold, Connection $queue, Response $response) { + $treshold = \intval($treshold); + $client = new Client(Event::MAILS_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); + $size = $client->getQueueSize(); + + if ($size >= $treshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + } + + $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/messaging') @@ -471,11 +535,20 @@ App::get('/v1/health/queue/messaging') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) + ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (Connection $queue, Response $response) { + ->action(function (int|string $treshold, Connection $queue, Response $response) { + $treshold = \intval($treshold); + $client = new Client(Event::MESSAGING_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); + $size = $client->getQueueSize(); + + if ($size >= $treshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + } + + $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/migrations') @@ -489,11 +562,20 @@ App::get('/v1/health/queue/migrations') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) + ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (Connection $queue, Response $response) { + ->action(function (int|string $treshold, Connection $queue, Response $response) { + $treshold = \intval($treshold); + $client = new Client(Event::MIGRATIONS_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); + $size = $client->getQueueSize(); + + if ($size >= $treshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + } + + $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/functions') @@ -507,11 +589,20 @@ App::get('/v1/health/queue/functions') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) + ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (Connection $queue, Response $response) { + ->action(function (int|string $treshold, Connection $queue, Response $response) { + $treshold = \intval($treshold); + $client = new Client(Event::FUNCTIONS_QUEUE_NAME, $queue); - $response->dynamic(new Document([ 'size' => $client->getQueueSize() ]), Response::MODEL_HEALTH_QUEUE); + $size = $client->getQueueSize(); + + if ($size >= $treshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + } + + $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/storage/local') diff --git a/tests/e2e/Services/Health/HealthCustomServerTest.php b/tests/e2e/Services/Health/HealthCustomServerTest.php index eafc961e8b..9a178ef1fa 100644 --- a/tests/e2e/Services/Health/HealthCustomServerTest.php +++ b/tests/e2e/Services/Health/HealthCustomServerTest.php @@ -138,6 +138,15 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['size']); $this->assertLessThan(100, $response['body']['size']); + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/webhooks?treshold=0', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + $this->assertEquals(500, $response['headers']['status-code']); + return []; } @@ -155,6 +164,15 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['size']); $this->assertLessThan(100, $response['body']['size']); + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/logs?treshold=0', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + $this->assertEquals(500, $response['headers']['status-code']); + return []; } @@ -172,6 +190,15 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['size']); $this->assertLessThan(100, $response['body']['size']); + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/certificates?treshold=0', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + $this->assertEquals(500, $response['headers']['status-code']); + return []; } @@ -189,6 +216,15 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['size']); $this->assertLessThan(100, $response['body']['size']); + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/functions?treshold=0', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + $this->assertEquals(500, $response['headers']['status-code']); + return []; } @@ -206,6 +242,15 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['size']); $this->assertLessThan(100, $response['body']['size']); + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/builds?treshold=0', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + $this->assertEquals(500, $response['headers']['status-code']); + return []; } @@ -225,6 +270,18 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['size']); $this->assertLessThan(100, $response['body']['size']); + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/databases', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'name' => 'database_db_main', + 'treshold' => '0' + ]); + $this->assertEquals(500, $response['headers']['status-code']); + return []; } @@ -242,6 +299,15 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['size']); $this->assertLessThan(100, $response['body']['size']); + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/deletes?treshold=0', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + $this->assertEquals(500, $response['headers']['status-code']); + return []; } @@ -259,6 +325,15 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['size']); $this->assertLessThan(100, $response['body']['size']); + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/mails?treshold=0', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + $this->assertEquals(500, $response['headers']['status-code']); + return []; } @@ -276,6 +351,15 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['size']); $this->assertLessThan(100, $response['body']['size']); + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/messaging?treshold=0', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + $this->assertEquals(500, $response['headers']['status-code']); + return []; } @@ -293,6 +377,15 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['size']); $this->assertLessThan(100, $response['body']['size']); + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/migrations?treshold=0', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + $this->assertEquals(500, $response['headers']['status-code']); + return []; } From 967854d34af107b4b3c97d6360bf367150f61dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 13 Nov 2023 14:39:33 +0100 Subject: [PATCH 36/36] Fix grammar --- app/controllers/api/health.php | 100 +++++++++--------- .../Health/HealthCustomServerTest.php | 20 ++-- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 5d64e71526..90e080d5fa 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -345,17 +345,17 @@ App::get('/v1/health/queue/webhooks') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) - ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) + ->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (int|string $treshold, Connection $queue, Response $response) { - $treshold = \intval($treshold); + ->action(function (int|string $threshold, Connection $queue, Response $response) { + $threshold = \intval($threshold); $client = new Client(Event::WEBHOOK_QUEUE_NAME, $queue); $size = $client->getQueueSize(); - if ($size >= $treshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + if ($size >= $threshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -372,17 +372,17 @@ App::get('/v1/health/queue/logs') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) - ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) + ->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (int|string $treshold, Connection $queue, Response $response) { - $treshold = \intval($treshold); + ->action(function (int|string $threshold, Connection $queue, Response $response) { + $threshold = \intval($threshold); $client = new Client(Event::AUDITS_QUEUE_NAME, $queue); $size = $client->getQueueSize(); - if ($size >= $treshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + if ($size >= $threshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -399,17 +399,17 @@ App::get('/v1/health/queue/certificates') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) - ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) + ->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (int|string $treshold, Connection $queue, Response $response) { - $treshold = \intval($treshold); + ->action(function (int|string $threshold, Connection $queue, Response $response) { + $threshold = \intval($threshold); $client = new Client(Event::CERTIFICATES_QUEUE_NAME, $queue); $size = $client->getQueueSize(); - if ($size >= $treshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + if ($size >= $threshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -426,17 +426,17 @@ App::get('/v1/health/queue/builds') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) - ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) + ->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (int|string $treshold, Connection $queue, Response $response) { - $treshold = \intval($treshold); + ->action(function (int|string $threshold, Connection $queue, Response $response) { + $threshold = \intval($threshold); $client = new Client(Event::BUILDS_QUEUE_NAME, $queue); $size = $client->getQueueSize(); - if ($size >= $treshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + if ($size >= $threshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -454,17 +454,17 @@ App::get('/v1/health/queue/databases') ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) ->param('name', 'database_db_main', new Text(256), 'Queue name for which to check the queue size', true) - ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) + ->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (string $name, int|string $treshold, Connection $queue, Response $response) { - $treshold = \intval($treshold); + ->action(function (string $name, int|string $threshold, Connection $queue, Response $response) { + $threshold = \intval($threshold); $client = new Client($name, $queue); $size = $client->getQueueSize(); - if ($size >= $treshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + if ($size >= $threshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -481,17 +481,17 @@ App::get('/v1/health/queue/deletes') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) - ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) + ->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (int|string $treshold, Connection $queue, Response $response) { - $treshold = \intval($treshold); + ->action(function (int|string $threshold, Connection $queue, Response $response) { + $threshold = \intval($threshold); $client = new Client(Event::DELETE_QUEUE_NAME, $queue); $size = $client->getQueueSize(); - if ($size >= $treshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + if ($size >= $threshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -508,17 +508,17 @@ App::get('/v1/health/queue/mails') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) - ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) + ->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (int|string $treshold, Connection $queue, Response $response) { - $treshold = \intval($treshold); + ->action(function (int|string $threshold, Connection $queue, Response $response) { + $threshold = \intval($threshold); $client = new Client(Event::MAILS_QUEUE_NAME, $queue); $size = $client->getQueueSize(); - if ($size >= $treshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + if ($size >= $threshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -535,17 +535,17 @@ App::get('/v1/health/queue/messaging') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) - ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) + ->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (int|string $treshold, Connection $queue, Response $response) { - $treshold = \intval($treshold); + ->action(function (int|string $threshold, Connection $queue, Response $response) { + $threshold = \intval($threshold); $client = new Client(Event::MESSAGING_QUEUE_NAME, $queue); $size = $client->getQueueSize(); - if ($size >= $treshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + if ($size >= $threshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -562,17 +562,17 @@ App::get('/v1/health/queue/migrations') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) - ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) + ->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (int|string $treshold, Connection $queue, Response $response) { - $treshold = \intval($treshold); + ->action(function (int|string $threshold, Connection $queue, Response $response) { + $threshold = \intval($threshold); $client = new Client(Event::MIGRATIONS_QUEUE_NAME, $queue); $size = $client->getQueueSize(); - if ($size >= $treshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + if ($size >= $threshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -589,17 +589,17 @@ App::get('/v1/health/queue/functions') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) - ->param('treshold', 5000, new Integer(true), 'Queue size treshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) + ->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('queue') ->inject('response') - ->action(function (int|string $treshold, Connection $queue, Response $response) { - $treshold = \intval($treshold); + ->action(function (int|string $threshold, Connection $queue, Response $response) { + $threshold = \intval($threshold); $client = new Client(Event::FUNCTIONS_QUEUE_NAME, $queue); $size = $client->getQueueSize(); - if ($size >= $treshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size treshold hit. Current size is {$size} and treshold is {$treshold}."); + if ($size >= $threshold) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); diff --git a/tests/e2e/Services/Health/HealthCustomServerTest.php b/tests/e2e/Services/Health/HealthCustomServerTest.php index 9a178ef1fa..8fa9faadd2 100644 --- a/tests/e2e/Services/Health/HealthCustomServerTest.php +++ b/tests/e2e/Services/Health/HealthCustomServerTest.php @@ -141,7 +141,7 @@ class HealthCustomServerTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/webhooks?treshold=0', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/webhooks?threshold=0', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -167,7 +167,7 @@ class HealthCustomServerTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/logs?treshold=0', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/logs?threshold=0', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -193,7 +193,7 @@ class HealthCustomServerTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/certificates?treshold=0', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/certificates?threshold=0', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -219,7 +219,7 @@ class HealthCustomServerTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/functions?treshold=0', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/functions?threshold=0', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -245,7 +245,7 @@ class HealthCustomServerTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/builds?treshold=0', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/builds?threshold=0', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -278,7 +278,7 @@ class HealthCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'database_db_main', - 'treshold' => '0' + 'threshold' => '0' ]); $this->assertEquals(500, $response['headers']['status-code']); @@ -302,7 +302,7 @@ class HealthCustomServerTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/deletes?treshold=0', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/deletes?threshold=0', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -328,7 +328,7 @@ class HealthCustomServerTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/mails?treshold=0', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/mails?threshold=0', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -354,7 +354,7 @@ class HealthCustomServerTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/messaging?treshold=0', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/messaging?threshold=0', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -380,7 +380,7 @@ class HealthCustomServerTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/migrations?treshold=0', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/migrations?threshold=0', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []);