From c92a820c6db2ca162e6e1ade2a6e725f1cccda08 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 21 Jun 2021 15:42:39 +0100 Subject: [PATCH 1/4] Renamed `env` param on `/v1/functions` to `runtime` --- CHANGES.md | 3 +++ app/controllers/api/functions.php | 6 +++--- .../e2e/Services/Functions/FunctionsCustomClientTest.php | 4 ++-- .../e2e/Services/Functions/FunctionsCustomServerTest.php | 8 ++++---- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0dd92eeff6..ecea3a3ac1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,9 @@ - Add Anonymous Account Placeholder - Upgraded telegraf docker image version to v1.1.0 +## Breaking Changes (Read before upgrading!) +- Renamed `env` param on `/v1/functions` to `runtime` + ## Bugs - Fixed bug when removing a project member on the Appwrite console (#1214) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 0f009aa404..8d49f38028 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -39,14 +39,14 @@ App::post('/v1/functions') ->label('sdk.response.model', Response::MODEL_FUNCTION) ->param('name', '', new Text(128), 'Function name. Max length: 128 chars.') ->param('execute', [], new ArrayList(new Text(64)), 'An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') - ->param('env', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution enviornment.') + ->param('runtime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution enviornment.') ->param('vars', [], new Assoc(), 'Key-value JSON object.', true) ->param('events', [], new ArrayList(new WhiteList(array_keys(Config::getParam('events')), true)), 'Events list.', true) ->param('schedule', '', new Cron(), 'Schedule CRON syntax.', true) ->param('timeout', 15, new Range(1, 900), 'Function maximum execution time in seconds.', true) ->inject('response') ->inject('projectDB') - ->action(function ($name, $execute, $env, $vars, $events, $schedule, $timeout, $response, $projectDB) { + ->action(function ($name, $execute, $runtime, $vars, $events, $schedule, $timeout, $response, $projectDB) { /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ @@ -59,7 +59,7 @@ App::post('/v1/functions') 'dateUpdated' => time(), 'status' => 'disabled', 'name' => $name, - 'env' => $env, + 'runtime' => $runtime, 'tag' => '', 'vars' => $vars, 'events' => $events, diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 12a9edf245..8ba16f8145 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -54,7 +54,7 @@ class FunctionsCustomClientTest extends Scope ], [ 'name' => 'Test', 'execute' => ['user:'.$this->getUser()['$id']], - 'env' => 'php-8.0', + 'runtime' => 'php-8.0', 'vars' => [ 'funcKey1' => 'funcValue1', 'funcKey2' => 'funcValue2', @@ -140,7 +140,7 @@ class FunctionsCustomClientTest extends Scope ], [ 'name' => 'Test', 'execute' => ['*'], - 'env' => 'php-8.0', + 'runtime' => 'php-8.0', 'vars' => [ 'funcKey1' => 'funcValue1', 'funcKey2' => 'funcValue2', diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index edd9081c91..b3140a7690 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -24,7 +24,7 @@ class FunctionsCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Test', - 'env' => 'php-8.0', + 'runtime' => 'php-8.0', 'vars' => [ 'funcKey1' => 'funcValue1', 'funcKey2' => 'funcValue2', @@ -327,7 +327,7 @@ class FunctionsCustomServerTest extends Scope $this->assertStringContainsString('PHP', $execution['body']['stdout']); $this->assertStringContainsString('8.0', $execution['body']['stdout']); $this->assertEquals('', $execution['body']['stderr']); - $this->assertGreaterThan(0.100, $execution['body']['time']); + $this->assertGreaterThan(0.05, $execution['body']['time']); $this->assertLessThan(0.500, $execution['body']['time']); /** @@ -462,7 +462,7 @@ class FunctionsCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Test '.$name, - 'env' => $name, + 'runtime' => $name, 'vars' => [], 'events' => [], 'schedule' => '', @@ -540,7 +540,7 @@ class FunctionsCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Test '.$name, - 'env' => $name, + 'runtime' => $name, 'vars' => [], 'events' => [], 'schedule' => '', From 22bc391047f9f8e19afd7496bf85f126179cc420 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Tue, 22 Jun 2021 11:18:26 +0100 Subject: [PATCH 2/4] Update app/controllers/api/functions.php Co-authored-by: Eldad A. Fux --- 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 8d49f38028..dd58108893 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -39,7 +39,7 @@ App::post('/v1/functions') ->label('sdk.response.model', Response::MODEL_FUNCTION) ->param('name', '', new Text(128), 'Function name. Max length: 128 chars.') ->param('execute', [], new ArrayList(new Text(64)), 'An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') - ->param('runtime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution enviornment.') + ->param('runtime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution runtime.') ->param('vars', [], new Assoc(), 'Key-value JSON object.', true) ->param('events', [], new ArrayList(new WhiteList(array_keys(Config::getParam('events')), true)), 'Events list.', true) ->param('schedule', '', new Cron(), 'Schedule CRON syntax.', true) From 86afebd726113a1e1588fda8c2f633bcacd9f358 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Tue, 22 Jun 2021 11:18:36 +0100 Subject: [PATCH 3/4] Update CHANGES.md Co-authored-by: Eldad A. Fux --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index ecea3a3ac1..ca4939ac93 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ - Upgraded telegraf docker image version to v1.1.0 ## Breaking Changes (Read before upgrading!) -- Renamed `env` param on `/v1/functions` to `runtime` +- Renamed `env` param on `/v1/functions` to `runtime` (#1314) ## Bugs From aa1e713b75810b35da068b5ee10af63dae36f268 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Tue, 22 Jun 2021 16:56:05 +0100 Subject: [PATCH 4/4] Fix tests --- app/config/collections.php | 4 ++-- app/workers/functions.php | 6 +++--- src/Appwrite/Utopia/Response/Model/Func.php | 4 ++-- tests/e2e/Services/Functions/FunctionsCustomServerTest.php | 2 +- tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index 6789237c9c..e6d67f08c3 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -1481,8 +1481,8 @@ $collections = [ ], [ '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'Env', - 'key' => 'env', + 'label' => 'Runtime', + 'key' => 'runtime', 'type' => Database::SYSTEM_VAR_TYPE_TEXT, 'default' => '', 'required' => false, diff --git a/app/workers/functions.php b/app/workers/functions.php index 8bf719e607..4dfab9a245 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -330,12 +330,12 @@ class FunctionsV1 Authorization::reset(); - $runtime = (isset($runtimes[$function->getAttribute('env', '')])) - ? $runtimes[$function->getAttribute('env', '')] + $runtime = (isset($runtimes[$function->getAttribute('runtime', '')])) + ? $runtimes[$function->getAttribute('runtime', '')] : null; if(\is_null($runtime)) { - throw new Exception('Environment "'.$function->getAttribute('env', '').' is not supported'); + throw new Exception('Runtime "'.$function->getAttribute('runtime', '').' is not supported'); } $vars = \array_merge($function->getAttribute('vars', []), [ diff --git a/src/Appwrite/Utopia/Response/Model/Func.php b/src/Appwrite/Utopia/Response/Model/Func.php index 94690a9467..6d5bf8c01a 100644 --- a/src/Appwrite/Utopia/Response/Model/Func.php +++ b/src/Appwrite/Utopia/Response/Model/Func.php @@ -47,9 +47,9 @@ class Func extends Model 'default' => '', 'example' => 'enabled', ]) - ->addRule('env', [ + ->addRule('runtime', [ 'type' => self::TYPE_STRING, - 'description' => 'Function execution environment.', + 'description' => 'Function execution runtime.', 'default' => '', 'example' => 'python-3.8', ]) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index b3140a7690..cf0a1cafc4 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -43,7 +43,7 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(201, $response1['headers']['status-code']); $this->assertNotEmpty($response1['body']['$id']); $this->assertEquals('Test', $response1['body']['name']); - $this->assertEquals('php-8.0', $response1['body']['env']); + $this->assertEquals('php-8.0', $response1['body']['runtime']); $this->assertIsInt($response1['body']['dateCreated']); $this->assertIsInt($response1['body']['dateUpdated']); $this->assertEquals('', $response1['body']['tag']); diff --git a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php index 0ef01ec850..0d3678eaf2 100644 --- a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php +++ b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php @@ -306,7 +306,7 @@ class WebhooksCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Test', - 'env' => 'php-8.0', + 'runtime' => 'php-8.0', 'execute' => ['*'], 'timeout' => 10, ]); @@ -348,7 +348,7 @@ class WebhooksCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Test', - 'env' => 'php-8.0', + 'runtime' => 'php-8.0', 'execute' => ['*'], 'vars' => [ 'key1' => 'value1',