From f02bf6ac5a2e5d3be03f13f128e5ca70ec9a513d Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 18 Jul 2024 13:03:24 +0100 Subject: [PATCH 01/25] feat: use coroutines delay system --- .../Platform/Tasks/ScheduleExecutions.php | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/ScheduleExecutions.php b/src/Appwrite/Platform/Tasks/ScheduleExecutions.php index 2fdbd98da3..e7364c7a4b 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleExecutions.php +++ b/src/Appwrite/Platform/Tasks/ScheduleExecutions.php @@ -26,6 +26,7 @@ class ScheduleExecutions extends ScheduleBase $queue = $pools->get('queue')->pop(); $connection = $queue->getResource(); $queueForFunctions = new Func($connection); + $intervalEnd = (new \DateTime())->modify('+' . self::ENQUEUE_TIMER . ' seconds'); foreach ($this->schedules as $schedule) { if (!$schedule['active']) { @@ -38,25 +39,29 @@ class ScheduleExecutions extends ScheduleBase continue; } - $now = new \DateTime(); $scheduledAt = new \DateTime($schedule['schedule']); - - if ($scheduledAt > $now) { + if ($scheduledAt <= $intervalEnd) { continue; } - $queueForFunctions - ->setType('schedule') - // Set functionId instead of function as we don't have $dbForProject - // TODO: Refactor to use function instead of functionId - ->setFunctionId($schedule['resource']['functionId']) - ->setExecution($schedule['resource']) - ->setMethod($schedule['data']['method'] ?? 'POST') - ->setPath($schedule['data']['path'] ?? '/') - ->setHeaders($schedule['data']['headers'] ?? []) - ->setBody($schedule['data']['body'] ?? '') - ->setProject($schedule['project']) - ->trigger(); + $delay = $scheduledAt->getTimestamp() - (new \DateTime())->getTimestamp(); + + \go(function () use ($queueForFunctions, $schedule, $delay) { + \sleep($delay); + + $queueForFunctions + ->setType('schedule') + // Set functionId instead of function as we don't have $dbForProject + // TODO: Refactor to use function instead of functionId + ->setFunctionId($schedule['resource']['functionId']) + ->setExecution($schedule['resource']) + ->setMethod($schedule['data']['method'] ?? 'POST') + ->setPath($schedule['data']['path'] ?? '/') + ->setHeaders($schedule['data']['headers'] ?? []) + ->setBody($schedule['data']['body'] ?? '') + ->setProject($schedule['project']) + ->trigger(); + }); $dbForConsole->deleteDocument( 'schedules', From d0a0329cc8595684fe89db008b3fe4f8a48d334b Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 18 Jul 2024 13:12:39 +0100 Subject: [PATCH 02/25] test: smaller sleep --- tests/e2e/Services/Functions/FunctionsCustomClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index bf969d388a..e3817c1b46 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -289,7 +289,7 @@ class FunctionsCustomClientTest extends Scope $executionId = $execution['body']['$id']; - sleep(20); + sleep(15); $execution = $this->client->call(Client::METHOD_GET, '/functions/' . $function['body']['$id'] . '/executions/' . $executionId, [ 'content-type' => 'application/json', From 5a56131efa480d1eff8ad43f686ef0fe3e06d1cf Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 19 Jul 2024 10:22:50 +0100 Subject: [PATCH 03/25] chore: binyamin review --- src/Appwrite/Platform/Tasks/ScheduleExecutions.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Tasks/ScheduleExecutions.php b/src/Appwrite/Platform/Tasks/ScheduleExecutions.php index e7364c7a4b..c5f9b40d15 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleExecutions.php +++ b/src/Appwrite/Platform/Tasks/ScheduleExecutions.php @@ -3,6 +3,7 @@ namespace Appwrite\Platform\Tasks; use Appwrite\Event\Func; +use Swoole\Coroutine as Co; use Utopia\Database\Database; use Utopia\Pools\Group; @@ -46,8 +47,9 @@ class ScheduleExecutions extends ScheduleBase $delay = $scheduledAt->getTimestamp() - (new \DateTime())->getTimestamp(); + \go(function () use ($queueForFunctions, $schedule, $delay) { - \sleep($delay); + Co::sleep($delay); $queueForFunctions ->setType('schedule') From 76aaa50ad6f251d18339eea72ef7be33e8721a9b Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 19 Jul 2024 10:54:20 +0100 Subject: [PATCH 04/25] chore: matej suggested test --- .../Functions/FunctionsCustomClientTest.php | 17 +++++++++++++---- tests/resources/functions/php-time/index.php | 7 +++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 tests/resources/functions/php-time/index.php diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index e3817c1b46..3b5adf1abd 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -220,7 +220,7 @@ class FunctionsCustomClientTest extends Scope $this->assertEquals(201, $function['headers']['status-code']); - $folder = 'php'; + $folder = 'php-time'; $code = realpath(__DIR__ . '/../../../resources/functions') . "/$folder/code.tar.gz"; $this->packageCode($folder); @@ -268,14 +268,15 @@ class FunctionsCustomClientTest extends Scope // Schedule execution for the future \date_default_timezone_set('UTC'); - $futureTime = (new \DateTime())->add(new \DateInterval('PT10S'))->format('Y-m-d H:i:s'); + $futureTime = (new \DateTime())->add(new \DateInterval('PT10S')); + $futureTimeString = $futureTime->format('Y-m-d H:i:s'); $execution = $this->client->call(Client::METHOD_POST, '/functions/' . $function['body']['$id'] . '/executions', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'async' => true, - 'scheduledAt' => $futureTime, + 'scheduledAt' => $futureTimeString, 'path' => '/custom', 'method' => 'GET', 'body' => 'hello', @@ -289,7 +290,7 @@ class FunctionsCustomClientTest extends Scope $executionId = $execution['body']['$id']; - sleep(15); + sleep(13); $execution = $this->client->call(Client::METHOD_GET, '/functions/' . $function['body']['$id'] . '/executions/' . $executionId, [ 'content-type' => 'application/json', @@ -304,6 +305,14 @@ class FunctionsCustomClientTest extends Scope $this->assertEquals('GET', $execution['body']['requestMethod']); $this->assertGreaterThan(0, $execution['body']['duration']); + // Assert that the execution was completed within 3 seconds of the scheduled time + + $output = json_decode($execution['body']['responseBody'], true); + $this->assertArrayHasKey('time', $output); + $this->assertGreaterThan($output['time'], $futureTime->getTimestamp()); + $this->assertLessThan($output['time'], $futureTime->getTimestamp() + 3); + + /* Test for FAILURE */ // Schedule synchronous execution diff --git a/tests/resources/functions/php-time/index.php b/tests/resources/functions/php-time/index.php new file mode 100644 index 0000000000..9a3433d55b --- /dev/null +++ b/tests/resources/functions/php-time/index.php @@ -0,0 +1,7 @@ +res->json([ + 'time' => \time(), + ]); +}; From 1559fec29aef29595587ef89c161fe48ff0567f8 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Tue, 30 Jul 2024 16:53:18 -0400 Subject: [PATCH 05/25] fix: Increasing buckets metadata --- app/config/collections.php | 2 +- src/Appwrite/Migration/Version/V21.php | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/config/collections.php b/app/config/collections.php index b8667d0b8d..e4dadcf0fc 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -5772,7 +5772,7 @@ $bucketCollections = [ '$id' => ID::custom('metadata'), 'type' => Database::VAR_STRING, 'format' => '', - 'size' => 16384, // https://tools.ietf.org/html/rfc4288#section-4.2 + 'size' => 75000, // https://tools.ietf.org/html/rfc4288#section-4.2 'signed' => true, 'required' => false, 'default' => null, diff --git a/src/Appwrite/Migration/Version/V21.php b/src/Appwrite/Migration/Version/V21.php index 7dd2912234..0e7a8b78db 100644 --- a/src/Appwrite/Migration/Version/V21.php +++ b/src/Appwrite/Migration/Version/V21.php @@ -36,6 +36,11 @@ class V21 extends Migration Console::info('Migrating Documents'); $this->forEachDocument([$this, 'fixDocument']); + + if ($this->project->getInternalId() !== 'console') { + Console::info('Migrating Buckets'); + $this->migrateBuckets(); + } } /** @@ -177,4 +182,20 @@ class V21 extends Migration return $document; } + + /** + * Migrating Buckets. + * + * @return void + * @throws Exception + * @throws PDOException + */ + private function migrateBuckets() + { + foreach ($this->documentsIterator('buckets') as $bucket) { + $bucketId = 'bucket_' . $bucket['$internalId']; + + $this->projectDB->updateAttribute($bucketId, 'metadata', size: 75000); + } + } } From 999c2cfac722128019f670be6a15cf07ed4689ef Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Tue, 30 Jul 2024 17:39:32 -0400 Subject: [PATCH 06/25] fix: reviews --- src/Appwrite/Migration/Version/V21.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Migration/Version/V21.php b/src/Appwrite/Migration/Version/V21.php index 0e7a8b78db..2add928d4a 100644 --- a/src/Appwrite/Migration/Version/V21.php +++ b/src/Appwrite/Migration/Version/V21.php @@ -34,13 +34,13 @@ class V21 extends Migration Console::info('Migrating Collections'); $this->migrateCollections(); - Console::info('Migrating Documents'); - $this->forEachDocument([$this, 'fixDocument']); - if ($this->project->getInternalId() !== 'console') { Console::info('Migrating Buckets'); $this->migrateBuckets(); } + + Console::info('Migrating Documents'); + $this->forEachDocument([$this, 'fixDocument']); } /** @@ -187,15 +187,17 @@ class V21 extends Migration * Migrating Buckets. * * @return void - * @throws Exception - * @throws PDOException */ private function migrateBuckets() { foreach ($this->documentsIterator('buckets') as $bucket) { $bucketId = 'bucket_' . $bucket['$internalId']; - $this->projectDB->updateAttribute($bucketId, 'metadata', size: 75000); + try { + $this->projectDB->updateAttribute($bucketId, 'metadata', size: 75000); + } catch (\Throwable $th) { + Console::warning("'bucketId' from {$bucketId}: {$th->getMessage()}"); + } } } } From 821d0bee194b4b2b8d5fdb12e20e289208cbc7a5 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Tue, 30 Jul 2024 20:36:29 -0400 Subject: [PATCH 07/25] feat: Purging collection cache --- src/Appwrite/Migration/Version/V21.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Appwrite/Migration/Version/V21.php b/src/Appwrite/Migration/Version/V21.php index 2add928d4a..af2d86a2ba 100644 --- a/src/Appwrite/Migration/Version/V21.php +++ b/src/Appwrite/Migration/Version/V21.php @@ -195,6 +195,7 @@ class V21 extends Migration try { $this->projectDB->updateAttribute($bucketId, 'metadata', size: 75000); + $this->projectDB->purgeCachedCollection($bucketId); } catch (\Throwable $th) { Console::warning("'bucketId' from {$bucketId}: {$th->getMessage()}"); } From de1d205341e47d3cc3161b1f569f5c68129a3208 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 31 Jul 2024 20:43:28 +0000 Subject: [PATCH 08/25] chore: update changes from merge --- .../Functions/FunctionsCustomClientTest.php | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 85630c7fd8..676f93b113 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -234,8 +234,8 @@ class FunctionsCustomClientTest extends Scope // Schedule execution for the future \date_default_timezone_set('UTC'); - $futureTime = (new \DateTime())->add(new \DateInterval('PT10S'))->format('Y-m-d H:i:s'); - $futureTimeIso = DateTime::formatTz($futureTime); + $futureTime = (new \DateTime())->add(new \DateInterval('PT10S')); + $futureTimeString = $futureTime->format('Y-m-d H:i:s'); $execution = $this->client->call(Client::METHOD_POST, '/functions/' . $function['body']['$id'] . '/executions', array_merge([ 'content-type' => 'application/json', @@ -257,21 +257,12 @@ class FunctionsCustomClientTest extends Scope $executionId = $execution['body']['$id']; - // List executions and ensure it has schedule date - $response = $this->client->call(Client::METHOD_GET, '/functions/' . $function['body']['$id'] . '/executions', [ - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertGreaterThan(0, \count($response['body']['executions'])); - $recentExecution = $response['body']['executions'][0]; - $this->assertEquals($executionId, $recentExecution['$id']); - $this->assertEquals($futureTimeIso, $recentExecution['scheduledAt']); - - sleep(20); + sleep(13); $execution = $this->client->call(Client::METHOD_GET, '/functions/' . $function['body']['$id'] . '/executions/' . $executionId, [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], ]); $this->assertEquals(200, $execution['headers']['status-code']); From cf4030095f1d29271745212cf30124ce39a7d2a8 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 31 Jul 2024 20:48:59 +0000 Subject: [PATCH 09/25] chore: linter --- composer.lock | 34 +++++++++---------- .../Functions/FunctionsCustomClientTest.php | 1 - 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/composer.lock b/composer.lock index 68f109ed72..e058bfdb33 100644 --- a/composer.lock +++ b/composer.lock @@ -1721,16 +1721,16 @@ }, { "name": "utopia-php/database", - "version": "0.50.0", + "version": "0.50.2", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "ce3eaccb2f3bbd34b2b97419836fec633b26b8f7" + "reference": "c712d1f6c8ec37886a7a1ad4d60a8cd75dec00aa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/ce3eaccb2f3bbd34b2b97419836fec633b26b8f7", - "reference": "ce3eaccb2f3bbd34b2b97419836fec633b26b8f7", + "url": "https://api.github.com/repos/utopia-php/database/zipball/c712d1f6c8ec37886a7a1ad4d60a8cd75dec00aa", + "reference": "c712d1f6c8ec37886a7a1ad4d60a8cd75dec00aa", "shasum": "" }, "require": { @@ -1771,9 +1771,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.50.0" + "source": "https://github.com/utopia-php/database/tree/0.50.2" }, - "time": "2024-06-21T03:21:42+00:00" + "time": "2024-07-31T10:12:19+00:00" }, { "name": "utopia-php/domains", @@ -2990,16 +2990,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "0.39.3", + "version": "0.39.4", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "16142d88270e368030d7956cadf2d7816413f8c4" + "reference": "501b92d73ae55e0f880ed00f57bc64a54d0ce137" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/16142d88270e368030d7956cadf2d7816413f8c4", - "reference": "16142d88270e368030d7956cadf2d7816413f8c4", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/501b92d73ae55e0f880ed00f57bc64a54d0ce137", + "reference": "501b92d73ae55e0f880ed00f57bc64a54d0ce137", "shasum": "" }, "require": { @@ -3035,9 +3035,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/0.39.3" + "source": "https://github.com/appwrite/sdk-generator/tree/0.39.4" }, - "time": "2024-07-12T15:29:48+00:00" + "time": "2024-07-26T22:34:10+00:00" }, { "name": "doctrine/deprecations", @@ -3158,16 +3158,16 @@ }, { "name": "laravel/pint", - "version": "v1.16.2", + "version": "v1.17.0", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "51f1ba679a6afe0315621ad143d788bd7ded0eca" + "reference": "4dba80c1de4b81dc4c4fb10ea6f4781495eb29f5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/51f1ba679a6afe0315621ad143d788bd7ded0eca", - "reference": "51f1ba679a6afe0315621ad143d788bd7ded0eca", + "url": "https://api.github.com/repos/laravel/pint/zipball/4dba80c1de4b81dc4c4fb10ea6f4781495eb29f5", + "reference": "4dba80c1de4b81dc4c4fb10ea6f4781495eb29f5", "shasum": "" }, "require": { @@ -3220,7 +3220,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2024-07-09T15:58:08+00:00" + "time": "2024-07-23T16:40:20+00:00" }, { "name": "matthiasmullie/minify", diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 676f93b113..5b59094409 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -9,7 +9,6 @@ use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideClient; use Utopia\Config\Config; -use Utopia\Database\DateTime; use Utopia\Database\Document; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Role; From 73ecec099d52cf798aaf408d4e67430e6c53fa6b Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Fri, 2 Aug 2024 08:59:47 -0400 Subject: [PATCH 10/25] feat: adding team email and changing base to noreplay --- .env | 3 ++- app/config/variables.php | 13 +++++++++++-- src/Appwrite/Platform/Tasks/Specs.php | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.env b/.env index 9cccf5ee7e..ee93723c17 100644 --- a/.env +++ b/.env @@ -9,7 +9,8 @@ _APP_CONSOLE_WHITELIST_IPS= _APP_CONSOLE_COUNTRIES_DENYLIST=AQ _APP_CONSOLE_HOSTNAMES=localhost,appwrite.io,*.appwrite.io _APP_SYSTEM_EMAIL_NAME=Appwrite -_APP_SYSTEM_EMAIL_ADDRESS=team@appwrite.io +_APP_SYSTEM_EMAIL_ADDRESS=noreplay@appwrite.io +_APP_SYSTEM_TEAM_EMAIL=teams@appwrite.io _APP_EMAIL_SECURITY=security@appwrite.io _APP_EMAIL_CERTIFICATES=certificates@appwrite.io _APP_SYSTEM_RESPONSE_FORMAT= diff --git a/app/config/variables.php b/app/config/variables.php index b986ce4247..03d99d3ec2 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -144,9 +144,18 @@ return [ ], [ 'name' => '_APP_SYSTEM_EMAIL_ADDRESS', - 'description' => 'This is the sender email address that will appear on email messages sent to developers from the Appwrite console. The default value is \'team@appwrite.io\'. You should choose an email address that is allowed to be used from your SMTP server to avoid the server email ending in the users\' SPAM folders.', + 'description' => 'This is the sender email address that will appear on email messages sent to developers from the Appwrite console. The default value is \'noreplay@appwrite.io\'. You should choose an email address that is allowed to be used from your SMTP server to avoid the server email ending in the users\' SPAM folders.', 'introduction' => '0.7.0', - 'default' => 'team@appwrite.io', + 'default' => 'noreplay@appwrite.io', + 'required' => false, + 'question' => '', + 'filter' => '' + ], + [ + 'name' => '_APP_SYSTEM_TEAM_EMAIL', + 'description' => 'This is the sender email address that will appear in the generated specs. The default value is \'teams@appwrite.io\'.', + 'introduction' => '1.6.0', + 'default' => 'temas@appwrite.io', 'required' => false, 'question' => '', 'filter' => '' diff --git a/src/Appwrite/Platform/Tasks/Specs.php b/src/Appwrite/Platform/Tasks/Specs.php index 114e12ac85..c90d4dabd3 100644 --- a/src/Appwrite/Platform/Tasks/Specs.php +++ b/src/Appwrite/Platform/Tasks/Specs.php @@ -259,7 +259,7 @@ class Specs extends Action $specs = new Specification($formatInstance); $endpoint = System::getEnv('_APP_HOME', '[HOSTNAME]'); - $email = System::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM); + $email = System::getEnv('_APP_SYSTEM_TEAM_EMAIL', APP_EMAIL_TEAM); $formatInstance ->setParam('name', APP_NAME) From e12e28c1f198ce6ee2428690c74daa1c532d881f Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Mon, 5 Aug 2024 15:46:12 -0400 Subject: [PATCH 11/25] typo Co-authored-by: Steven Nguyen <1477010+stnguyen90@users.noreply.github.com> --- .env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env b/.env index ee93723c17..e0a1ce9bd8 100644 --- a/.env +++ b/.env @@ -9,7 +9,7 @@ _APP_CONSOLE_WHITELIST_IPS= _APP_CONSOLE_COUNTRIES_DENYLIST=AQ _APP_CONSOLE_HOSTNAMES=localhost,appwrite.io,*.appwrite.io _APP_SYSTEM_EMAIL_NAME=Appwrite -_APP_SYSTEM_EMAIL_ADDRESS=noreplay@appwrite.io +_APP_SYSTEM_EMAIL_ADDRESS=noreply@appwrite.io _APP_SYSTEM_TEAM_EMAIL=teams@appwrite.io _APP_EMAIL_SECURITY=security@appwrite.io _APP_EMAIL_CERTIFICATES=certificates@appwrite.io From 18a519f32da00c8462c47d4ea350bbf307b663bf Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Mon, 5 Aug 2024 15:46:23 -0400 Subject: [PATCH 12/25] typo Co-authored-by: Steven Nguyen <1477010+stnguyen90@users.noreply.github.com> --- app/config/variables.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config/variables.php b/app/config/variables.php index 03d99d3ec2..7d3161107c 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -146,7 +146,7 @@ return [ 'name' => '_APP_SYSTEM_EMAIL_ADDRESS', 'description' => 'This is the sender email address that will appear on email messages sent to developers from the Appwrite console. The default value is \'noreplay@appwrite.io\'. You should choose an email address that is allowed to be used from your SMTP server to avoid the server email ending in the users\' SPAM folders.', 'introduction' => '0.7.0', - 'default' => 'noreplay@appwrite.io', + 'default' => 'noreply@appwrite.io', 'required' => false, 'question' => '', 'filter' => '' From b87cabfc4949490e86881d8d8af12c027189b9c2 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 7 Aug 2024 17:49:03 +0100 Subject: [PATCH 13/25] test: fix unused var --- tests/e2e/Services/Functions/FunctionsCustomClientTest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 5b59094409..870c1b0bff 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -252,10 +252,10 @@ class FunctionsCustomClientTest extends Scope $this->assertEquals(202, $execution['headers']['status-code']); $this->assertEquals('scheduled', $execution['body']['status']); - $this->assertEquals($futureTimeIso, $execution['body']['scheduledAt']); $executionId = $execution['body']['$id']; + // 10 seconds delay, then allow 3 seconds for cold start sleep(13); $execution = $this->client->call(Client::METHOD_GET, '/functions/' . $function['body']['$id'] . '/executions/' . $executionId, [ @@ -270,10 +270,8 @@ class FunctionsCustomClientTest extends Scope $this->assertEquals('/custom', $execution['body']['requestPath']); $this->assertEquals('GET', $execution['body']['requestMethod']); $this->assertGreaterThan(0, $execution['body']['duration']); - $this->assertEquals($futureTimeIso, $execution['body']['scheduledAt']); - - // Assert that the execution was completed within 3 seconds of the scheduled time + // Assert execution completed within 3 seconds of schedule $output = json_decode($execution['body']['responseBody'], true); $this->assertArrayHasKey('time', $output); $this->assertGreaterThan($output['time'], $futureTime->getTimestamp()); From 9e81e5fe3cb0f077b665a4c7bb648ab6347aa384 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Thu, 8 Aug 2024 09:53:18 -0400 Subject: [PATCH 14/25] chore: Upgrading logger --- composer.json | 2 +- composer.lock | 56 +++++++++++++++++++++++++-------------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/composer.json b/composer.json index 3bb2816028..93b9879a10 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,7 @@ "utopia-php/fetch": "0.2.*", "utopia-php/image": "0.6.*", "utopia-php/locale": "0.4.*", - "utopia-php/logger": "0.5.*", + "utopia-php/logger": "0.6.*", "utopia-php/messaging": "0.12.*", "utopia-php/migration": "0.4.*", "utopia-php/orchestration": "0.9.*", diff --git a/composer.lock b/composer.lock index 27c11b9af2..1f74e0c159 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": "fc07cbc344782534962fd7bf0769f7b9", + "content-hash": "349cdb39bce652b164706de8b399b911", "packages": [ { "name": "adhocore/jwt", @@ -1721,16 +1721,16 @@ }, { "name": "utopia-php/database", - "version": "0.50.2", + "version": "0.50.3", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "c712d1f6c8ec37886a7a1ad4d60a8cd75dec00aa" + "reference": "4287e6625c7273411c7322abd151c4285ee7b50f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/c712d1f6c8ec37886a7a1ad4d60a8cd75dec00aa", - "reference": "c712d1f6c8ec37886a7a1ad4d60a8cd75dec00aa", + "url": "https://api.github.com/repos/utopia-php/database/zipball/4287e6625c7273411c7322abd151c4285ee7b50f", + "reference": "4287e6625c7273411c7322abd151c4285ee7b50f", "shasum": "" }, "require": { @@ -1771,9 +1771,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.50.2" + "source": "https://github.com/utopia-php/database/tree/0.50.3" }, - "time": "2024-07-31T10:12:19+00:00" + "time": "2024-08-08T01:40:54+00:00" }, { "name": "utopia-php/domains", @@ -2067,16 +2067,16 @@ }, { "name": "utopia-php/logger", - "version": "0.5.2", + "version": "0.6.0", "source": { "type": "git", "url": "https://github.com/utopia-php/logger.git", - "reference": "c6dfdb672e41364c309b0c30dc03bc6d45446dba" + "reference": "a2d1daeeb8f61fdec6d851950d9a021a3d05c9f9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/logger/zipball/c6dfdb672e41364c309b0c30dc03bc6d45446dba", - "reference": "c6dfdb672e41364c309b0c30dc03bc6d45446dba", + "url": "https://api.github.com/repos/utopia-php/logger/zipball/a2d1daeeb8f61fdec6d851950d9a021a3d05c9f9", + "reference": "a2d1daeeb8f61fdec6d851950d9a021a3d05c9f9", "shasum": "" }, "require": { @@ -2115,9 +2115,9 @@ ], "support": { "issues": "https://github.com/utopia-php/logger/issues", - "source": "https://github.com/utopia-php/logger/tree/0.5.2" + "source": "https://github.com/utopia-php/logger/tree/0.6.0" }, - "time": "2024-05-17T09:32:59+00:00" + "time": "2024-05-23T13:37:54+00:00" }, { "name": "utopia-php/messaging", @@ -2990,16 +2990,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "0.39.4", + "version": "0.39.6", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "501b92d73ae55e0f880ed00f57bc64a54d0ce137" + "reference": "00e6f9e77ea380d8ab3138a36548b353077e4061" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/501b92d73ae55e0f880ed00f57bc64a54d0ce137", - "reference": "501b92d73ae55e0f880ed00f57bc64a54d0ce137", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/00e6f9e77ea380d8ab3138a36548b353077e4061", + "reference": "00e6f9e77ea380d8ab3138a36548b353077e4061", "shasum": "" }, "require": { @@ -3035,9 +3035,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/0.39.4" + "source": "https://github.com/appwrite/sdk-generator/tree/0.39.6" }, - "time": "2024-07-26T22:34:10+00:00" + "time": "2024-08-08T12:44:28+00:00" }, { "name": "doctrine/deprecations", @@ -3158,16 +3158,16 @@ }, { "name": "laravel/pint", - "version": "v1.17.1", + "version": "v1.17.2", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "b5b6f716db298671c1dfea5b1082ec2c0ae7064f" + "reference": "e8a88130a25e3f9d4d5785e6a1afca98268ab110" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/b5b6f716db298671c1dfea5b1082ec2c0ae7064f", - "reference": "b5b6f716db298671c1dfea5b1082ec2c0ae7064f", + "url": "https://api.github.com/repos/laravel/pint/zipball/e8a88130a25e3f9d4d5785e6a1afca98268ab110", + "reference": "e8a88130a25e3f9d4d5785e6a1afca98268ab110", "shasum": "" }, "require": { @@ -3178,13 +3178,13 @@ "php": "^8.1.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.59.3", - "illuminate/view": "^10.48.12", - "larastan/larastan": "^2.9.7", + "friendsofphp/php-cs-fixer": "^3.61.1", + "illuminate/view": "^10.48.18", + "larastan/larastan": "^2.9.8", "laravel-zero/framework": "^10.4.0", "mockery/mockery": "^1.6.12", "nunomaduro/termwind": "^1.15.1", - "pestphp/pest": "^2.34.8" + "pestphp/pest": "^2.35.0" }, "bin": [ "builds/pint" @@ -3220,7 +3220,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2024-08-01T09:06:33+00:00" + "time": "2024-08-06T15:11:54+00:00" }, { "name": "matthiasmullie/minify", From 1c6b735a27141f04a20a2a05f0fe43c25f32ffe5 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:48:45 -0400 Subject: [PATCH 15/25] feat: disconnecting git only when provider it is an empty string --- app/controllers/api/functions.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 443260ea90..f23fbf2f69 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -47,6 +47,7 @@ use Utopia\System\System; use Utopia\Validator\ArrayList; use Utopia\Validator\Assoc; use Utopia\Validator\Boolean; +use Utopia\Validator\Nullable; use Utopia\Validator\Range; use Utopia\Validator\Text; use Utopia\Validator\WhiteList; @@ -688,7 +689,7 @@ App::put('/v1/functions/:functionId') ->param('commands', '', new Text(8192, 0), 'Build Commands.', true) ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('scopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of scopes allowed for API Key auto-generated for every execution. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.', true) ->param('installationId', '', new Text(128, 0), 'Appwrite Installation ID for VCS (Version Controle System) deployment.', true) - ->param('providerRepositoryId', '', new Text(128, 0), 'Repository ID of the repo linked to the function', true) + ->param('providerRepositoryId', null, new Nullable(new Text(128, 0)), 'Repository ID of the repo linked to the function', true) ->param('providerBranch', '', new Text(128, 0), 'Production branch for the repo linked to the function', true) ->param('providerSilentMode', false, new Boolean(), 'Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests.', true) ->param('providerRootDirectory', '', new Text(128, 0), 'Path to function code in the linked repo.', true) @@ -700,7 +701,7 @@ App::put('/v1/functions/:functionId') ->inject('queueForBuilds') ->inject('dbForConsole') ->inject('gitHub') - ->action(function (string $functionId, string $name, string $runtime, array $execute, array $events, string $schedule, int $timeout, bool $enabled, bool $logging, string $entrypoint, string $commands, array $scopes, string $installationId, string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, Request $request, Response $response, Database $dbForProject, Document $project, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) use ($redeployVcs) { + ->action(function (string $functionId, string $name, string $runtime, array $execute, array $events, string $schedule, int $timeout, bool $enabled, bool $logging, string $entrypoint, string $commands, array $scopes, string $installationId, ?string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, Request $request, Response $response, Database $dbForProject, Document $project, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) use ($redeployVcs) { // TODO: If only branch changes, re-deploy $function = $dbForProject->getDocument('functions', $functionId); @@ -739,7 +740,7 @@ App::put('/v1/functions/:functionId') $isConnected = !empty($function->getAttribute('providerRepositoryId', '')); // Git disconnect logic - if ($isConnected && empty($providerRepositoryId)) { + if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForConsole->find('repositories', [ Query::equal('projectInternalId', [$project->getInternalId()]), Query::equal('resourceInternalId', [$function->getInternalId()]), From 95fe93913608c1f708e73e741f1cbd2404e91b21 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:50:25 -0400 Subject: [PATCH 16/25] feat: adding explanation --- app/controllers/api/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index f23fbf2f69..c119bfd76a 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -739,7 +739,7 @@ App::put('/v1/functions/:functionId') $isConnected = !empty($function->getAttribute('providerRepositoryId', '')); - // Git disconnect logic + // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForConsole->find('repositories', [ Query::equal('projectInternalId', [$project->getInternalId()]), From 850052b92fff49ab812a1ecc6d602e0cc4be1641 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Thu, 8 Aug 2024 14:30:07 -0400 Subject: [PATCH 17/25] fix: Adding otp session email customizing --- app/config/locale/templates.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/config/locale/templates.php b/app/config/locale/templates.php index e013c3ccc9..6aa376678a 100644 --- a/app/config/locale/templates.php +++ b/app/config/locale/templates.php @@ -7,7 +7,8 @@ return [ 'recovery', 'invitation', 'mfaChallenge', - 'sessionAlert' + 'sessionAlert', + 'otpSession' ], 'sms' => [ 'verification', From 30132e7e9346a2a8fb96d1e58a0bb5782c5298d6 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 9 Aug 2024 10:43:08 +0100 Subject: [PATCH 18/25] test: fix body check, not possible --- .../Functions/FunctionsCustomClientTest.php | 60 ++++++++----------- tests/resources/functions/php-time/index.php | 7 --- 2 files changed, 24 insertions(+), 43 deletions(-) delete mode 100644 tests/resources/functions/php-time/index.php diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 870c1b0bff..e3c5a8a19c 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -191,19 +191,15 @@ class FunctionsCustomClientTest extends Scope ], [ 'functionId' => ID::unique(), 'name' => 'Test', - 'execute' => [Role::user($this->getUser()['$id'])->toString()], + 'execute' => [Role::any()->toString()], 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', - 'events' => [ - 'users.*.create', - 'users.*.delete', - ], 'timeout' => 10, ]); $this->assertEquals(201, $function['headers']['status-code']); - $folder = 'php-time'; + $folder = 'php'; $code = realpath(__DIR__ . '/../../../resources/functions') . "/$folder/code.tar.gz"; $this->packageCode($folder); @@ -216,20 +212,10 @@ class FunctionsCustomClientTest extends Scope 'code' => new CURLFile($code, 'application/x-gzip', \basename($code)), 'activate' => true ]); - $deploymentId = $deployment['body']['$id'] ?? ''; - $this->assertEquals(202, $deployment['headers']['status-code']); - $this->awaitDeploymentIsBuilt($function['body']['$id'], $deploymentId); - - $function = $this->client->call(Client::METHOD_PATCH, '/functions/' . $function['body']['$id'] . '/deployments/' . $deploymentId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ], []); - - $this->assertEquals(200, $function['headers']['status-code']); + $this->awaitDeploymentIsBuilt($function['body']['$id'], $deploymentId, true); // Schedule execution for the future \date_default_timezone_set('UTC'); @@ -243,11 +229,7 @@ class FunctionsCustomClientTest extends Scope 'async' => true, 'scheduledAt' => $futureTimeString, 'path' => '/custom', - 'method' => 'GET', - 'body' => 'hello', - 'headers' => [ - 'content-type' => 'application/plain', - ], + 'method' => 'GET' ]); $this->assertEquals(202, $execution['headers']['status-code']); @@ -255,14 +237,27 @@ class FunctionsCustomClientTest extends Scope $executionId = $execution['body']['$id']; - // 10 seconds delay, then allow 3 seconds for cold start - sleep(13); + // 10 seconds delay + sleep(10); - $execution = $this->client->call(Client::METHOD_GET, '/functions/' . $function['body']['$id'] . '/executions/' . $executionId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ]); + $start = \microtime(true); + while (true) { + $execution = $this->client->call(Client::METHOD_GET, '/functions/' . $function['body']['$id'] . '/executions/' . $executionId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + if ($execution['body']['status'] === 'completed') { + break; + } + + if (\microtime(true) - $start > 4) { + $this->fail('Execution did not complete within 4 seconds of schedule'); + } + + usleep(500000); + } $this->assertEquals(200, $execution['headers']['status-code']); $this->assertEquals(200, $execution['body']['responseStatusCode']); @@ -271,13 +266,6 @@ class FunctionsCustomClientTest extends Scope $this->assertEquals('GET', $execution['body']['requestMethod']); $this->assertGreaterThan(0, $execution['body']['duration']); - // Assert execution completed within 3 seconds of schedule - $output = json_decode($execution['body']['responseBody'], true); - $this->assertArrayHasKey('time', $output); - $this->assertGreaterThan($output['time'], $futureTime->getTimestamp()); - $this->assertLessThan($output['time'], $futureTime->getTimestamp() + 3); - - /* Test for FAILURE */ // Schedule synchronous execution diff --git a/tests/resources/functions/php-time/index.php b/tests/resources/functions/php-time/index.php deleted file mode 100644 index 9a3433d55b..0000000000 --- a/tests/resources/functions/php-time/index.php +++ /dev/null @@ -1,7 +0,0 @@ -res->json([ - 'time' => \time(), - ]); -}; From 464e1e247c2dbeaa53c6b001d5c6d351957cc4fe Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 9 Aug 2024 11:30:01 +0100 Subject: [PATCH 19/25] test: fix expect 400 --- tests/e2e/Services/Functions/FunctionsCustomClientTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index e3c5a8a19c..05987f07a4 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -4,6 +4,7 @@ namespace Tests\E2E\Services\Functions; use Appwrite\Tests\Retry; use CURLFile; +use DateTime; use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; @@ -220,14 +221,13 @@ class FunctionsCustomClientTest extends Scope // Schedule execution for the future \date_default_timezone_set('UTC'); $futureTime = (new \DateTime())->add(new \DateInterval('PT10S')); - $futureTimeString = $futureTime->format('Y-m-d H:i:s'); $execution = $this->client->call(Client::METHOD_POST, '/functions/' . $function['body']['$id'] . '/executions', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'async' => true, - 'scheduledAt' => $futureTimeString, + 'scheduledAt' => $futureTime->format(DateTime::ATOM), 'path' => '/custom', 'method' => 'GET' ]); @@ -275,7 +275,7 @@ class FunctionsCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'async' => false, - 'scheduledAt' => $futureTime, + 'scheduledAt' => $futureTime->format(DateTime::ATOM), ]); $this->assertEquals(400, $execution['headers']['status-code']); From 0e773fefdfaa7be110fe6360010cd76d3340ff23 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 9 Aug 2024 13:10:07 +0100 Subject: [PATCH 20/25] feat: improve test --- .../Functions/FunctionsCustomClientTest.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 592697e9ec..eb2a1a1df9 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -4,7 +4,6 @@ namespace Tests\E2E\Services\Functions; use Appwrite\Tests\Retry; use CURLFile; -use DateTime; use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; @@ -192,7 +191,7 @@ class FunctionsCustomClientTest extends Scope ], [ 'functionId' => ID::unique(), 'name' => 'Test', - 'execute' => [Role::any()->toString()], + 'execute' => [Role::user($this->getUser()['$id'])->toString()], 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', 'timeout' => 10, @@ -227,7 +226,7 @@ class FunctionsCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'async' => true, - 'scheduledAt' => $futureTime->format(DateTime::ATOM), + 'scheduledAt' => $futureTime->format(\DateTime::ATOM), 'path' => '/custom', 'method' => 'GET' ]); @@ -237,7 +236,6 @@ class FunctionsCustomClientTest extends Scope $executionId = $execution['body']['$id']; - // 10 seconds delay sleep(10); $start = \microtime(true); @@ -252,11 +250,11 @@ class FunctionsCustomClientTest extends Scope break; } - if (\microtime(true) - $start > 4) { - $this->fail('Execution did not complete within 4 seconds of schedule'); + if (\microtime(true) - $start > 5) { + $this->fail('Execution did not complete within 5 seconds of schedule'); } - usleep(500000); + usleep(500000); // 0.5 seconds } $this->assertEquals(200, $execution['headers']['status-code']); @@ -275,7 +273,7 @@ class FunctionsCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'async' => false, - 'scheduledAt' => $futureTime->format(DateTime::ATOM), + 'scheduledAt' => $futureTime->format(\DateTime::ATOM), ]); $this->assertEquals(400, $execution['headers']['status-code']); From 24137abd42f0215f29c3c06587350fba39340fe3 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Fri, 9 Aug 2024 09:05:35 -0400 Subject: [PATCH 21/25] fix: Adding otp session email customizing --- app/init.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app/init.php b/app/init.php index 892d9209a8..b566de9518 100644 --- a/app/init.php +++ b/app/init.php @@ -769,13 +769,22 @@ $register->set('logger', function () { throw new Exception(Exception::GENERAL_SERVER_ERROR, "Logging provider not supported. Logging is disabled"); } - $adapter = match ($providerName) { - 'sentry' => new Sentry($providerConfig['projectId'], $providerConfig['key'], $providerConfig['host']), - 'logowl' => new LogOwl($providerConfig['ticket'], $providerConfig['host']), - 'raygun' => new Raygun($providerConfig['key']), - 'appsignal' => new AppSignal($providerConfig['key']), - default => throw new Exception('Provider "' . $providerName . '" not supported.') - }; + try { + $adapter = match ($providerName) { + 'sentry' => new Sentry($providerConfig['projectId'], $providerConfig['key'], $providerConfig['host']), + 'logowl' => new LogOwl($providerConfig['ticket'], $providerConfig['host']), + 'raygun' => new Raygun($providerConfig['key']), + 'appsignal' => new AppSignal($providerConfig['key']), + default => null + }; + } catch (Throwable $th) { + $adapter = null; + } + + if($adapter === null) { + Console::error("Logging provider not supported. Logging is disabled"); + return; + } return new Logger($adapter); }); From 34fc855c8ac1ddce84ac6fee7fc3726592a52e79 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:49:16 +0530 Subject: [PATCH 22/25] Allow deployment queries on type and size --- .../Utopia/Database/Validator/Queries/Deployments.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Deployments.php b/src/Appwrite/Utopia/Database/Validator/Queries/Deployments.php index 427779efa5..42aed88ef6 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Deployments.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Deployments.php @@ -9,7 +9,9 @@ class Deployments extends Base 'buildId', 'activate', 'entrypoint', - 'commands' + 'commands', + 'type', + 'size' ]; /** From 6f1655a4207abf76e32b5158e3e85395d018d6ad Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 12 Aug 2024 15:20:24 +0530 Subject: [PATCH 23/25] Add tests for querying deployments with size and type --- .../Functions/FunctionsCustomServerTest.php | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 0b6bf985c1..7e2183a6f9 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -732,6 +732,57 @@ class FunctionsCustomServerTest extends Scope $this->assertCount(3, $function['body']['deployments']); $this->assertEquals($function['body']['deployments'][0]['$id'], $data['deploymentId']); + $function = $this->client->call( + Client::METHOD_GET, + '/functions/' . $data['functionId'] . '/deployments', + array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), + [ + 'queries' => [ + Query::equal('type', ['manual'])->toString(), + ], + ] + ); + + $this->assertEquals($function['headers']['status-code'], 200); + $this->assertEquals(3, $function['body']['total']); + + $function = $this->client->call( + Client::METHOD_GET, + '/functions/' . $data['functionId'] . '/deployments', + array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), + [ + 'queries' => [ + Query::greaterThan('size', 10000)->toString(), + ], + ] + ); + + $this->assertEquals($function['headers']['status-code'], 200); + $this->assertEquals(1, $function['body']['total']); + + $function = $this->client->call( + Client::METHOD_GET, + '/functions/' . $data['functionId'] . '/deployments', + array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), + [ + 'queries' => [ + Query::greaterThan('size', 0)->toString(), + ], + ] + ); + + $this->assertEquals($function['headers']['status-code'], 200); + $this->assertEquals(3, $function['body']['total']); + return $data; } From 70c0c7707a2708d2ba9c9ab8463a25f00b4e5c6f Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 12 Aug 2024 15:27:50 +0530 Subject: [PATCH 24/25] Add tests for negative size and invalid-string --- .../Functions/FunctionsCustomServerTest.php | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 67a342d843..2c20d46ccb 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -749,6 +749,40 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals($function['headers']['status-code'], 200); $this->assertEquals(3, $function['body']['total']); + $function = $this->client->call( + Client::METHOD_GET, + '/functions/' . $data['functionId'] . '/deployments', + array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), + [ + 'queries' => [ + Query::equal('type', ['vcs'])->toString(), + ], + ] + ); + + $this->assertEquals($function['headers']['status-code'], 200); + $this->assertEquals(0, $function['body']['total']); + + $function = $this->client->call( + Client::METHOD_GET, + '/functions/' . $data['functionId'] . '/deployments', + array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), + [ + 'queries' => [ + Query::equal('type', ['invalid-string'])->toString(), + ], + ] + ); + + $this->assertEquals($function['headers']['status-code'], 200); + $this->assertEquals(0, $function['body']['total']); + $function = $this->client->call( Client::METHOD_GET, '/functions/' . $data['functionId'] . '/deployments', @@ -783,6 +817,23 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals($function['headers']['status-code'], 200); $this->assertEquals(3, $function['body']['total']); + $function = $this->client->call( + Client::METHOD_GET, + '/functions/' . $data['functionId'] . '/deployments', + array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), + [ + 'queries' => [ + Query::greaterThan('size', -100)->toString(), + ], + ] + ); + + $this->assertEquals($function['headers']['status-code'], 200); + $this->assertEquals(3, $function['body']['total']); + return $data; } From c0770621cf482e467d46d73498d0fe3e852723ff Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Mon, 12 Aug 2024 07:36:15 -0400 Subject: [PATCH 25/25] fix: reviews --- .env | 2 +- app/config/variables.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.env b/.env index e0a1ce9bd8..b4341ba2ca 100644 --- a/.env +++ b/.env @@ -10,7 +10,7 @@ _APP_CONSOLE_COUNTRIES_DENYLIST=AQ _APP_CONSOLE_HOSTNAMES=localhost,appwrite.io,*.appwrite.io _APP_SYSTEM_EMAIL_NAME=Appwrite _APP_SYSTEM_EMAIL_ADDRESS=noreply@appwrite.io -_APP_SYSTEM_TEAM_EMAIL=teams@appwrite.io +_APP_SYSTEM_TEAM_EMAIL=team@appwrite.io _APP_EMAIL_SECURITY=security@appwrite.io _APP_EMAIL_CERTIFICATES=certificates@appwrite.io _APP_SYSTEM_RESPONSE_FORMAT= diff --git a/app/config/variables.php b/app/config/variables.php index 7d3161107c..c59af4a104 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -144,7 +144,7 @@ return [ ], [ 'name' => '_APP_SYSTEM_EMAIL_ADDRESS', - 'description' => 'This is the sender email address that will appear on email messages sent to developers from the Appwrite console. The default value is \'noreplay@appwrite.io\'. You should choose an email address that is allowed to be used from your SMTP server to avoid the server email ending in the users\' SPAM folders.', + 'description' => 'This is the sender email address that will appear on email messages sent to developers from the Appwrite console. The default value is \'noreply@appwrite.io\'. You should choose an email address that is allowed to be used from your SMTP server to avoid the server email ending in the users\' SPAM folders.', 'introduction' => '0.7.0', 'default' => 'noreply@appwrite.io', 'required' => false, @@ -153,9 +153,9 @@ return [ ], [ 'name' => '_APP_SYSTEM_TEAM_EMAIL', - 'description' => 'This is the sender email address that will appear in the generated specs. The default value is \'teams@appwrite.io\'.', + 'description' => 'This is the sender email address that will appear in the generated specs. The default value is \'team@appwrite.io\'.', 'introduction' => '1.6.0', - 'default' => 'temas@appwrite.io', + 'default' => 'team@appwrite.io', 'required' => false, 'question' => '', 'filter' => ''