1
0
Fork 0
mirror of synced 2024-06-01 10:29:48 +12:00

Updated ENV config

This commit is contained in:
Eldad Fux 2020-07-14 19:13:18 +03:00
parent f97019ddb0
commit 8618f4d764
8 changed files with 50 additions and 29 deletions

View file

@ -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',

View file

@ -1,28 +1,33 @@
<?php
return [
[
'name' => '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',
],

View file

@ -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,
]);

View file

@ -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)

View file

@ -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);

View file

@ -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

View file

@ -1,3 +1,6 @@
<?php
$environments = $this->getParam('environments', []);
?>
<div class="cover">
<h1 class="zone xl margin-bottom-large">
<a data-ls-attrs="href=/console/home?project={{router.params.project}}" class="back text-size-small link-return-animation--start"><i class="icon-left-open"></i> Home</a>
@ -60,7 +63,14 @@
data-failure-param-alert-classname="error">
<label for="name">Name</label>
<input type="text" id="name" name="name" required autocomplete="off" class="margin-bottom-xl" />
<input type="text" id="name" name="name" required autocomplete="off" class="margin-bottom" />
<label for="env">Environment</label>
<select name="env" id="env" required class="margin-bottom-xl">
<?php foreach($environments as $key => $environment): ?>
<option value="<?php echo $this->escape($key); ?>"><?php echo $this->escape($environment['name']); ?> <?php echo $this->escape($environment['version']); ?></option>
<?php endforeach; ?>
</select>
<footer>
<button type="submit">Create</button> &nbsp; <button data-ui-modal-close="" type="button" class="reverse">Cancel</button>

View file

@ -23,6 +23,7 @@ class FunctionsConsoleServerTest extends Scope
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Test',
'env' => 'node-14',
'vars' => [
'key1' => 'value1',
'key2' => 'value2',
@ -179,7 +180,6 @@ class FunctionsConsoleServerTest extends Scope
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'env' => 'node-14',
'command' => 'node ./test.js',
'code' => 'codefilehere',
]);