From 8618f4d76489fff01d407fd07268bf37eaad3901 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Tue, 14 Jul 2020 19:13:18 +0300 Subject: [PATCH] Updated ENV config --- app/config/collections.php | 18 ++++++------- app/config/environments.php | 25 +++++++++++-------- app/controllers/api/functions.php | 13 +++++----- app/controllers/api/projects.php | 4 +-- app/controllers/web/console.php | 4 +++ app/init.php | 1 + app/views/console/functions/index.phtml | 12 ++++++++- .../Functions/FunctionsCustomServerTest.php | 2 +- 8 files changed, 50 insertions(+), 29 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index 78855b083b..5bc75ca0f0 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -1223,6 +1223,15 @@ $collections = [ 'required' => false, 'array' => false, ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Env', + 'key' => 'env', + 'type' => Database::SYSTEM_VAR_TYPE_TEXT, + 'default' => '', + 'required' => false, + 'array' => false, + ], [ '$collection' => Database::SYSTEM_COLLECTION_RULES, 'label' => 'Tag', @@ -1314,15 +1323,6 @@ $collections = [ 'required' => false, 'array' => false, ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'Env', - 'key' => 'env', - 'type' => Database::SYSTEM_VAR_TYPE_TEXT, - 'default' => '', - 'required' => false, - 'array' => false, - ], [ '$collection' => Database::SYSTEM_COLLECTION_RULES, 'label' => 'Command', diff --git a/app/config/environments.php b/app/config/environments.php index fd9f9b77a4..49e398a3da 100644 --- a/app/config/environments.php +++ b/app/config/environments.php @@ -1,28 +1,33 @@ 'Node.js 14', + 'node-14' => [ + 'name' => 'Node.js', + 'version' => '14.0', 'image' => 'node:14', 'logo' => 'node.png', ], - [ - 'name' => 'PHP 7.4', + 'php-7.4' => [ + 'name' => 'PHP', + 'version' => '7.4', 'image' => 'php:7.4-cli', 'logo' => 'php.png', ], - [ - 'name' => 'Ruby 2.7', + 'ruby-2.7' => [ + 'name' => 'Ruby', + 'version' => '2.7', 'image' => 'ruby:2.7', 'logo' => 'ruby.png', ], - [ - 'name' => 'Dart 2.8', + 'dart-2.8' => [ + 'name' => 'Dart', + 'version' => '2.8', 'image' => 'google/dart:2.8', 'logo' => 'dart.png', ], - [ - 'name' => 'Python 3.8', + 'python-3.8' => [ + 'name' => 'Python', + 'version' => '3.8', 'image' => 'python:3.8', 'logo' => 'python.png', ], diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 37b512e305..f13baff11e 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -10,6 +10,7 @@ use Utopia\Validator\Assoc; use Utopia\Validator\Text; use Utopia\Validator\Range; use Utopia\Validator\WhiteList; +use Utopia\Config\Config; use Cron\CronExpression; include_once __DIR__ . '/../shared/api.php'; @@ -23,11 +24,12 @@ App::post('/v1/functions') ->label('sdk.method', 'create') ->label('sdk.description', '/docs/references/functions/create-function.md') ->param('name', '', function () { return new Text(128); }, 'Function name.') + ->param('env', '', function () { return new WhiteList(array_keys(Config::getParam('environments'))); }, 'Execution enviornment.') ->param('vars', [], function () { return new Assoc();}, 'Key-value JSON object.', true) - ->param('events', [], function () { return new ArrayList(new Text(256)); }, 'Events list.', true) + ->param('events', null, function () { return new ArrayList(new WhiteList(array_keys(Config::getParam('events')), true)); }, 'Events list.', true) ->param('schedule', '', function () { return new Cron(); }, 'Schedule CRON syntax.', true) ->param('timeout', 15, function () { return new Range(1, 900); }, 'Function maximum execution time in seconds.', true) - ->action(function ($name, $vars, $events, $schedule, $timeout, $response, $projectDB) { + ->action(function ($name, $env, $vars, $events, $schedule, $timeout, $response, $projectDB) { $function = $projectDB->createDocument([ '$collection' => Database::SYSTEM_COLLECTION_FUNCTIONS, '$permissions' => [ @@ -38,6 +40,7 @@ App::post('/v1/functions') 'dateUpdated' => time(), 'status' => 'paused', 'name' => $name, + 'env' => $env, 'tag' => '', 'vars' => $vars, 'events' => $events, @@ -115,7 +118,7 @@ App::put('/v1/functions/:functionId') ->param('functionId', '', function () { return new UID(); }, 'Function unique ID.') ->param('name', '', function () { return new Text(128); }, 'Function name.') ->param('vars', [], function () { return new Assoc();}, 'Key-value JSON object.', true) - ->param('events', [], function () { return new ArrayList(new Text(256)); }, 'Events list.', true) + ->param('events', null, function () { return new ArrayList(new WhiteList(array_keys(Config::getParam('events')), true)); }, 'Events list.', true) ->param('schedule', '', function () { return new Cron(); }, 'Schedule CRON syntax.', true) ->param('timeout', 15, function () { return new Range(1, 900); }, 'Function maximum execution time in seconds.', true) ->action(function ($functionId, $name, $vars, $events, $schedule, $timeout, $response, $projectDB) { @@ -211,10 +214,9 @@ App::post('/v1/functions/:functionId/tags') ->label('sdk.method', 'createTag') ->label('sdk.description', '/docs/references/functions/create-tag.md') ->param('functionId', '', function () { return new UID(); }, 'Function unique ID.') - ->param('env', '', function () { return new WhiteList(['node-14', 'node-12', 'php-7.4']); }, 'Execution enviornment.') ->param('command', '', function () { return new Text('1028'); }, 'Code execution command.') ->param('code', '', function () { return new Text(128); }, 'Code package. Use the '.APP_NAME.' code packager to create a deployable package file.') - ->action(function ($functionId, $env, $command, $code, $response, $projectDB) { + ->action(function ($functionId, $command, $code, $response, $projectDB) { $function = $projectDB->getDocument($functionId); if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) { @@ -229,7 +231,6 @@ App::post('/v1/functions/:functionId/tags') ], 'dateCreated' => time(), 'functionId' => $function->getId(), - 'env' => $env, 'command' => $command, 'code' => $code, ]); diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index cc4232d7ba..84378146cc 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -466,7 +466,7 @@ App::post('/v1/projects/:projectId/webhooks') ->label('sdk.method', 'createWebhook') ->param('projectId', null, function () { return new UID(); }, 'Project unique ID.') ->param('name', null, function () { return new Text(256); }, 'Webhook name.') - ->param('events', null, function () { return new ArrayList(new WhiteList(array_keys(Config::getParam('events')), true)); }, 'Webhook events list.') + ->param('events', null, function () { return new ArrayList(new WhiteList(array_keys(Config::getParam('events')), true)); }, 'Events list.') ->param('url', null, function () { return new URL(); }, 'Webhook URL.') ->param('security', false, function () { return new Boolean(true); }, 'Certificate verification, false for disabled or true for enabled.') ->param('httpUser', '', function () { return new Text(256); }, 'Webhook HTTP user.', true) @@ -602,7 +602,7 @@ App::put('/v1/projects/:projectId/webhooks/:webhookId') ->param('projectId', null, function () { return new UID(); }, 'Project unique ID.') ->param('webhookId', null, function () { return new UID(); }, 'Webhook unique ID.') ->param('name', null, function () { return new Text(256); }, 'Webhook name.') - ->param('events', null, function () { return new ArrayList(new WhiteList(array_keys(Config::getParam('events')), true)); }, 'Webhook events list.') + ->param('events', null, function () { return new ArrayList(new WhiteList(array_keys(Config::getParam('events')), true)); }, 'Events list.') ->param('url', null, function () { return new URL(); }, 'Webhook URL.') ->param('security', false, function () { return new Boolean(true); }, 'Certificate verification, false for disabled or true for enabled.') ->param('httpUser', '', function () { return new Text(256); }, 'Webhook HTTP user.', true) ->param('httpPass', '', function () { return new Text(256); }, 'Webhook HTTP password.', true) diff --git a/app/controllers/web/console.php b/app/controllers/web/console.php index 2d1c36a727..79f6850001 100644 --- a/app/controllers/web/console.php +++ b/app/controllers/web/console.php @@ -347,6 +347,10 @@ App::get('/console/functions') ->action(function ($layout) { $page = new View(__DIR__.'/../../views/console/functions/index.phtml'); + $page + ->setParam('environments', Config::getParam('environments')) + ; + $layout ->setParam('title', APP_NAME.' - Functions') ->setParam('body', $page); diff --git a/app/init.php b/app/init.php index 2d0ddf1102..408512fbb2 100644 --- a/app/init.php +++ b/app/init.php @@ -62,6 +62,7 @@ Config::load('events', __DIR__.'/config/events.php'); Config::load('providers', __DIR__.'/config/providers.php'); Config::load('platforms', __DIR__.'/config/platforms.php'); Config::load('collections', __DIR__.'/config/collections.php'); +Config::load('environments', __DIR__.'/config/environments.php'); Config::load('roles', __DIR__.'/config/roles.php'); // User roles and scopes Config::load('scopes', __DIR__.'/config/scopes.php'); // User roles and scopes Config::load('services', __DIR__.'/config/services.php'); // List of services diff --git a/app/views/console/functions/index.phtml b/app/views/console/functions/index.phtml index 65f6f8f28e..3e512dd5d3 100644 --- a/app/views/console/functions/index.phtml +++ b/app/views/console/functions/index.phtml @@ -1,3 +1,6 @@ +getParam('environments', []); +?>

Home @@ -60,7 +63,14 @@ data-failure-param-alert-classname="error"> - + + + +