diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4d7fbb7b7a..a87f1e574f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,9 +1,9 @@ -name: "Build and Publish" +name: "Build and Publish Appwrite Images for Cloud" on: push: tags: - - appwrite-* + - cl-* jobs: build-publish: @@ -16,7 +16,7 @@ jobs: with: fetch-depth: 2 submodules: recursive - ref: feat-db-pools-master + ref: master - name: Login to Docker Hub uses: docker/login-action@v2 diff --git a/CHANGES.md b/CHANGES.md index f4e412e82a..6ed6429540 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,31 @@ +# Version 1.4.3 + +## Features +- Support for the all new bun runtime [#6230](https://github.com/appwrite/appwrite/pull/6230) +- Stripe function templates [Console #540](https://github.com/appwrite/console/pull/540) + +## Fixes +- Fix missing _APP_OPENSSL_KEY_V1 in the compose file [#6199](https://github.com/appwrite/appwrite/pull/6199) +- Fix V2 functions env vars [#6215](https://github.com/appwrite/appwrite/pull/6215) +- Fix Don't update User Accessed At for Users and Teams APIs [#6222](https://github.com/appwrite/appwrite/pull/6222) +- Fix Git deploys with S3 [#6227](https://github.com/appwrite/appwrite/pull/6227) +- Fix manual internal id insertion [#6232](https://github.com/appwrite/appwrite/pull/6232) +- Fix function timeout [#6235](https://github.com/appwrite/appwrite/pull/6235) +- Fix collections with datetime attributes migration [#17](https://github.com/utopia-php/migration/pull/17) +- Fix not all user data being migrated [#17](https://github.com/utopia-php/migration/pull/17) +- Fix team memberships migration [#16](https://github.com/utopia-php/migration/pull/16) +- Fix events validation on create/update webhooks [#6219](https://github.com/appwrite/appwrite/pull/6219) +- Fix schedules task [#6246](https://github.com/appwrite/appwrite/pull/6246) +- Fix missing keys when updating document via relationship [Database #320](https://github.com/utopia-php/database/pull/320) +- Fix Discord template [Console #538](https://github.com/appwrite/console/pull/538) +- Fix form var is url not text [Console #539](https://github.com/appwrite/console/pull/539) +- Fix incorrect link to migration docs for self-hosted to cloud [Console #543](https://github.com/appwrite/console/pull/543) +- Fix can't disable smtp [Console #548](https://github.com/appwrite/console/pull/548) +- Fix create function cover for case where VCS is not enabled [Console #544](https://github.com/appwrite/console/pull/544) +- Fix users list not re-rendering [Console #537](https://github.com/appwrite/console/pull/537) +- Fix create attribute modal null when selecting same time twice [Console #549](https://github.com/appwrite/console/pull/549) +- Fix runtime versions in templates [Console #546](https://github.com/appwrite/console/pull/546) + # Version 1.4.2 ## Fixes diff --git a/Dockerfile b/Dockerfile index 602ddac29b..d87bed3977 100755 --- a/Dockerfile +++ b/Dockerfile @@ -37,95 +37,8 @@ ARG VERSION=dev ARG DEBUG=false ENV DEBUG=$DEBUG -ENV DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker} -ENV DOCKER_COMPOSE_VERSION=v2.5.0 - -ENV _APP_SERVER=swoole \ - _APP_ENV=production \ - _APP_LOCALE=en \ - _APP_WORKER_PER_CORE= \ - _APP_DOMAIN=localhost \ - _APP_DOMAIN_FUNCTIONS=functions.localhost \ - _APP_DOMAIN_TARGET=localhost \ - _APP_HOME=https://appwrite.io \ - _APP_EDITION=community \ - _APP_CONSOLE_WHITELIST_ROOT=enabled \ - _APP_CONSOLE_WHITELIST_EMAILS= \ - _APP_CONSOLE_WHITELIST_IPS= \ - _APP_SYSTEM_EMAIL_NAME= \ - _APP_SYSTEM_EMAIL_ADDRESS= \ - _APP_SYSTEM_RESPONSE_FORMAT= \ - _APP_SYSTEM_SECURITY_EMAIL_ADDRESS= \ - _APP_OPTIONS_ABUSE=enabled \ - _APP_OPTIONS_FORCE_HTTPS=disabled \ - _APP_OPENSSL_KEY_V1=your-secret-key \ - _APP_STORAGE_LIMIT=10000000 \ - _APP_STORAGE_ANTIVIRUS=enabled \ - _APP_STORAGE_ANTIVIRUS_HOST=clamav \ - _APP_STORAGE_ANTIVIRUS_PORT=3310 \ - _APP_STORAGE_DEVICE=Local \ - _APP_STORAGE_S3_ACCESS_KEY= \ - _APP_STORAGE_S3_SECRET= \ - _APP_STORAGE_S3_REGION= \ - _APP_STORAGE_S3_BUCKET= \ - _APP_STORAGE_DO_SPACES_ACCESS_KEY= \ - _APP_STORAGE_DO_SPACES_SECRET= \ - _APP_STORAGE_DO_SPACES_REGION= \ - _APP_STORAGE_DO_SPACES_BUCKET= \ - _APP_STORAGE_BACKBLAZE_ACCESS_KEY= \ - _APP_STORAGE_BACKBLAZE_SECRET= \ - _APP_STORAGE_BACKBLAZE_REGION= \ - _APP_STORAGE_BACKBLAZE_BUCKET= \ - _APP_STORAGE_LINODE_ACCESS_KEY= \ - _APP_STORAGE_LINODE_SECRET= \ - _APP_STORAGE_LINODE_REGION= \ - _APP_STORAGE_LINODE_BUCKET= \ - _APP_STORAGE_WASABI_ACCESS_KEY= \ - _APP_STORAGE_WASABI_SECRET= \ - _APP_STORAGE_WASABI_REGION= \ - _APP_STORAGE_WASABI_BUCKET= \ - _APP_REDIS_HOST=redis \ - _APP_REDIS_PORT=6379 \ - _APP_DB_HOST=mariadb \ - _APP_DB_PORT=3306 \ - _APP_DB_USER=root \ - _APP_DB_PASS=password \ - _APP_DB_SCHEMA=appwrite \ - _APP_SMTP_HOST= \ - _APP_SMTP_PORT= \ - _APP_SMTP_SECURE= \ - _APP_SMTP_USERNAME= \ - _APP_SMTP_PASSWORD= \ - _APP_SMS_PROVIDER= \ - _APP_SMS_FROM= \ - _APP_FUNCTIONS_SIZE_LIMIT=30000000 \ - _APP_FUNCTIONS_TIMEOUT=900 \ - _APP_FUNCTIONS_CONTAINERS=10 \ - _APP_FUNCTIONS_CPUS=1 \ - _APP_FUNCTIONS_MEMORY=128 \ - _APP_FUNCTIONS_MEMORY_SWAP=128 \ - _APP_EXECUTOR_SECRET=a-random-secret \ - _APP_EXECUTOR_HOST=http://appwrite-executor/v1 \ - _APP_EXECUTOR_RUNTIME_NETWORK=appwrite_runtimes \ - _APP_SETUP=self-hosted \ - _APP_VERSION=$VERSION \ - _APP_USAGE_STATS=enabled \ - _APP_USAGE_AGGREGATION_INTERVAL=30 \ - # 14 Days = 1209600 s - _APP_MAINTENANCE_RETENTION_EXECUTION=1209600 \ - _APP_MAINTENANCE_RETENTION_AUDIT=1209600 \ - # 1 Day = 86400 s - _APP_MAINTENANCE_RETENTION_ABUSE=86400 \ - _APP_MAINTENANCE_RETENTION_USAGE_HOURLY=8640000 \ - _APP_MAINTENANCE_INTERVAL=86400 \ - _APP_LOGGING_PROVIDER= \ - _APP_LOGGING_CONFIG= \ - _APP_VCS_GITHUB_APP_NAME= \ - _APP_VCS_GITHUB_PRIVATE_KEY= \ - _APP_VCS_GITHUB_APP_ID= \ - _APP_VCS_GITHUB_CLIENT_ID= \ - _APP_VCS_GITHUB_CLIENT_SECRET= \ - _APP_VCS_GITHUB_WEBHOOK_SECRET= +ENV _APP_VERSION=$VERSION \ + _APP_HOME=https://appwrite.io RUN \ if [ "$DEBUG" == "true" ]; then \ @@ -183,6 +96,15 @@ RUN chmod +x /usr/local/bin/doctor && \ chmod +x /usr/local/bin/worker-migrations && \ chmod +x /usr/local/bin/worker-usage +# Cloud Executabless +RUN chmod +x /usr/local/bin/hamster && \ + chmod +x /usr/local/bin/volume-sync && \ + chmod +x /usr/local/bin/patch-delete-schedule-updated-at-attribute && \ + chmod +x /usr/local/bin/patch-delete-project-collections && \ + chmod +x /usr/local/bin/clear-card-cache && \ + chmod +x /usr/local/bin/calc-users-stats && \ + chmod +x /usr/local/bin/calc-tier-stats + # Letsencrypt Permissions RUN mkdir -p /etc/letsencrypt/live/ && chmod -Rf 755 /etc/letsencrypt/live/ diff --git a/README-CN.md b/README-CN.md index 8550695cc4..d85532be66 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.2 + appwrite/appwrite:1.4.3 ``` ### 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.2 + appwrite/appwrite:1.4.3 ``` #### 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.2 + appwrite/appwrite:1.4.3 ``` 运行后,可以在浏览器上访问 http://localhost 找到 Appwrite 控制台。在非 Linux 的本机主机上完成安装后,服务器可能需要几分钟才能启动。 diff --git a/README.md b/README.md index 68f4fdb1c0..90a5896f98 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,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.2 + appwrite/appwrite:1.4.3 ``` ### Windows @@ -87,7 +87,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.2 + appwrite/appwrite:1.4.3 ``` #### PowerShell @@ -97,7 +97,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.2 + appwrite/appwrite:1.4.3 ``` 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/config/platforms.php b/app/config/platforms.php index 8a41b6e675..75789473b9 100644 --- a/app/config/platforms.php +++ b/app/config/platforms.php @@ -81,7 +81,7 @@ return [ [ 'key' => 'apple', 'name' => 'Apple', - 'version' => '4.0.0', + 'version' => '4.0.1', 'url' => 'https://github.com/appwrite/sdk-for-apple', 'package' => 'https://github.com/appwrite/sdk-for-apple', 'enabled' => true, @@ -203,7 +203,7 @@ return [ [ 'key' => 'cli', 'name' => 'Command Line', - 'version' => '4.0.0', + 'version' => '4.1.0', 'url' => 'https://github.com/appwrite/sdk-for-cli', 'package' => 'https://www.npmjs.com/package/appwrite-cli', 'enabled' => true, @@ -415,7 +415,7 @@ return [ [ 'key' => 'swift', 'name' => 'Swift', - 'version' => '4.0.0', + 'version' => '4.0.1', 'url' => 'https://github.com/appwrite/sdk-for-swift', 'package' => 'https://github.com/appwrite/sdk-for-swift', 'enabled' => true, diff --git a/app/config/variables.php b/app/config/variables.php index 363e60a4c5..42a2fd65d4 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -65,7 +65,7 @@ return [ 'name' => '_APP_DOMAIN_FUNCTIONS', 'description' => 'A domain to use for function preview URLs. Setting to empty turns off function preview URLs.', 'introduction' => '', - 'default' => '', + 'default' => 'functions.localhost', 'required' => false, 'question' => '', 'filter' => '' @@ -798,10 +798,11 @@ return [ ], [ 'name' => '_APP_FUNCTIONS_MAINTENANCE_INTERVAL', - 'description' => 'Interval how often executor checks for inactive runimes. The default value is 60 seconds.', - 'introduction' => '1.2.0', - 'default' => '60', + 'description' => 'Interval value containing the number of seconds that the executor should wait before checking for inactive runtimes. The default value is 3600 seconds (1 hour).', + 'introduction' => '1.4.0', + 'default' => '3600', 'required' => false, + 'overwrite' => true, 'question' => '', 'filter' => '' ], diff --git a/app/console b/app/console index 88b6d59051..59d6ebe70e 160000 --- a/app/console +++ b/app/console @@ -1 +1 @@ -Subproject commit 88b6d59051992ed86183ee83d77bf678d1cb73bf +Subproject commit 59d6ebe70e80f1914f2f44ee31bdd318ba6e35ee diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 898545f898..b1da4d6b33 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -145,6 +145,7 @@ App::post('/v1/account') 'search' => implode(' ', [$userId, $email, $name]), 'accessedAt' => DateTime::now(), ]); + $user->removeAttribute('$internalId'); Authorization::skip(fn() => $dbForProject->createDocument('users', $user)); } catch (Duplicate) { throw new Exception(Exception::USER_ALREADY_EXISTS); @@ -648,6 +649,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') 'search' => implode(' ', [$userId, $email, $name]), 'accessedAt' => DateTime::now(), ]); + $user->removeAttribute('$internalId'); Authorization::skip(fn() => $dbForProject->createDocument('users', $user)); } catch (Duplicate) { $failureRedirect(Exception::USER_ALREADY_EXISTS); @@ -950,6 +952,7 @@ App::post('/v1/account/sessions/magic-url') 'accessedAt' => DateTime::now(), ]); + $user->removeAttribute('$internalId'); Authorization::skip(fn () => $dbForProject->createDocument('users', $user)); } @@ -1277,6 +1280,7 @@ App::post('/v1/account/sessions/phone') 'accessedAt' => DateTime::now(), ]); + $user->removeAttribute('$internalId'); Authorization::skip(fn () => $dbForProject->createDocument('users', $user)); } @@ -1525,6 +1529,7 @@ App::post('/v1/account/sessions/anonymous') 'search' => $userId, 'accessedAt' => DateTime::now(), ]); + $user->removeAttribute('$internalId'); Authorization::skip(fn() => $dbForProject->createDocument('users', $user)); // Create session token diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index ff45c12b86..1d1840f025 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -7,7 +7,7 @@ use Appwrite\Event\Delete; use Appwrite\Event\Event; use Appwrite\Event\Func; use Appwrite\Event\Usage; -use Appwrite\Event\Validator\Event as ValidatorEvent; +use Appwrite\Event\Validator\FunctionEvent; use Appwrite\Utopia\Response\Model\Rule; use Appwrite\Extend\Exception; use Appwrite\Utopia\Database\Validator\CustomId; @@ -135,7 +135,7 @@ App::post('/v1/functions') ->param('name', '', new Text(128), 'Function name. Max length: 128 chars.') ->param('runtime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution runtime.') ->param('execute', [], new Roles(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of role strings with execution permissions. By default no user is granted with any execute permissions. [learn more about roles](https://appwrite.io/docs/permissions#permission-roles). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' roles are allowed, each 64 characters long.', true) - ->param('events', [], new ArrayList(new ValidatorEvent(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Events list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' events are allowed.', true) + ->param('events', [], new ArrayList(new FunctionEvent(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Events list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' events are allowed.', true) ->param('schedule', '', new Cron(), 'Schedule CRON syntax.', true) ->param('timeout', 15, new Range(1, (int) App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900)), 'Function maximum execution time in seconds.', true) ->param('enabled', true, new Boolean(), 'Is function enabled? When set to \'disabled\', users cannot access the function but Server SDKs with and API key can still access the function. No data is lost when this is toggled.', true) @@ -610,7 +610,7 @@ App::put('/v1/functions/:functionId') ->param('name', '', new Text(128), 'Function name. Max length: 128 chars.') ->param('runtime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution runtime.', true) ->param('execute', [], new Roles(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of role strings with execution permissions. By default no user is granted with any execute permissions. [learn more about roles](https://appwrite.io/docs/permissions#permission-roles). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' roles are allowed, each 64 characters long.', true) - ->param('events', [], new ArrayList(new ValidatorEvent(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Events list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' events are allowed.', true) + ->param('events', [], new ArrayList(new FunctionEvent(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Events list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' events are allowed.', true) ->param('schedule', '', new Cron(), 'Schedule CRON syntax.', true) ->param('timeout', 15, new Range(1, (int) App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900)), 'Maximum execution time in seconds.', true) ->param('enabled', true, new Boolean(), 'Is function enabled? When set to \'disabled\', users cannot access the function but Server SDKs with and API key can still access the function. No data is lost when this is toggled.', true) @@ -1404,9 +1404,9 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') $deploymentId = ID::unique(); + $deployment->removeAttribute('$internalId'); $deployment = $dbForProject->createDocument('deployments', $deployment->setAttributes([ '$id' => $deploymentId, - '$internalId' => '', 'buildId' => '', 'buildInternalId' => '', 'entrypoint' => $function->getAttribute('entrypoint'), @@ -1606,6 +1606,16 @@ App::post('/v1/functions/:functionId/executions') $vars = []; + // V2 vars + if ($version === 'v2') { + $vars = \array_merge($vars, [ + 'APPWRITE_FUNCTION_TRIGGER' => $headers['x-appwrite-trigger'] ?? '', + 'APPWRITE_FUNCTION_DATA' => $body ?? '', + 'APPWRITE_FUNCTION_USER_ID' => $headers['x-appwrite-user-id'] ?? '', + 'APPWRITE_FUNCTION_JWT' => $headers['x-appwrite-user-jwt'] ?? '' + ]); + } + // Shared vars foreach ($function->getAttribute('varsProject', []) as $var) { $vars[$var->getAttribute('key')] = $var->getAttribute('value', ''); diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 2e263827a6..f20df71dad 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -491,7 +491,6 @@ App::post('/v1/teams/:teamId/memberships') 'tokens' => null, 'memberships' => null, 'search' => implode(' ', [$userId, $email, $name]), - 'accessedAt' => DateTime::now(), ]))); } catch (Duplicate $th) { throw new Exception(Exception::USER_ALREADY_EXISTS); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 4e2557f571..7cefcc7585 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -97,7 +97,6 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e 'tokens' => null, 'memberships' => null, 'search' => implode(' ', [$userId, $email, $phone, $name]), - 'accessedAt' => DateTime::now(), ])); } catch (Duplicate $th) { throw new Exception(Exception::USER_ALREADY_EXISTS); diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 67f59b9e40..2abf4ef30c 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -23,6 +23,7 @@ use Utopia\Database\Helpers\Role; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; +use Utopia\Detector\Adapter\Bun; use Utopia\Detector\Adapter\CPP; use Utopia\Detector\Adapter\Dart; use Utopia\Detector\Adapter\Deno; @@ -469,6 +470,7 @@ App::post('/v1/vcs/github/installations/:installationId/providerRepositories/:pr $detectorFactory ->addDetector(new JavaScript()) + ->addDetector(new Bun()) ->addDetector(new PHP()) ->addDetector(new Python()) ->addDetector(new Dart()) @@ -549,6 +551,7 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories') $detectorFactory ->addDetector(new JavaScript()) + ->addDetector(new Bun()) ->addDetector(new PHP()) ->addDetector(new Python()) ->addDetector(new Dart()) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 130110b64f..5486bcd86f 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -255,7 +255,7 @@ App::init() $useCache = $route->getLabel('cache', false); if ($useCache) { - $key = md5($request->getURI() . implode('*', $request->getParams())) . '*' . APP_CACHE_BUSTER; + $key = md5($request->getURI() . implode('*', $request->getParams()) . '*' . APP_CACHE_BUSTER); $cache = new Cache( new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId()) ); @@ -541,7 +541,7 @@ App::shutdown() $resourceType = $parseLabel($pattern, $responsePayload, $requestParams, $user); } - $key = md5($request->getURI() . implode('*', $request->getParams())) . '*' . APP_CACHE_BUSTER; + $key = md5($request->getURI() . implode('*', $request->getParams()) . '*' . APP_CACHE_BUSTER); $data = json_encode([ 'resourceType' => $resourceType, 'resource' => $resource, diff --git a/app/init.php b/app/init.php index e1369fb1a8..bd8541b8b8 100644 --- a/app/init.php +++ b/app/init.php @@ -107,8 +107,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 = 509; -const APP_VERSION_STABLE = '1.4.2'; +const APP_CACHE_BUSTER = 510; +const APP_VERSION_STABLE = '1.4.3'; const APP_DATABASE_ATTRIBUTE_EMAIL = 'email'; const APP_DATABASE_ATTRIBUTE_ENUM = 'enum'; const APP_DATABASE_ATTRIBUTE_IP = 'ip'; diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index f1769ef517..d1137de18e 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -378,6 +378,27 @@ services: - _APP_FUNCTIONS_MEMORY - _APP_OPTIONS_FORCE_HTTPS - _APP_DOMAIN + - _APP_STORAGE_DEVICE + - _APP_STORAGE_S3_ACCESS_KEY + - _APP_STORAGE_S3_SECRET + - _APP_STORAGE_S3_REGION + - _APP_STORAGE_S3_BUCKET + - _APP_STORAGE_DO_SPACES_ACCESS_KEY + - _APP_STORAGE_DO_SPACES_SECRET + - _APP_STORAGE_DO_SPACES_REGION + - _APP_STORAGE_DO_SPACES_BUCKET + - _APP_STORAGE_BACKBLAZE_ACCESS_KEY + - _APP_STORAGE_BACKBLAZE_SECRET + - _APP_STORAGE_BACKBLAZE_REGION + - _APP_STORAGE_BACKBLAZE_BUCKET + - _APP_STORAGE_LINODE_ACCESS_KEY + - _APP_STORAGE_LINODE_SECRET + - _APP_STORAGE_LINODE_REGION + - _APP_STORAGE_LINODE_BUCKET + - _APP_STORAGE_WASABI_ACCESS_KEY + - _APP_STORAGE_WASABI_SECRET + - _APP_STORAGE_WASABI_REGION + - _APP_STORAGE_WASABI_BUCKET appwrite-worker-certificates: image: /: @@ -578,6 +599,7 @@ services: environment: - _APP_ENV - _APP_WORKER_PER_CORE + - _APP_OPENSSL_KEY_V1 - _APP_REDIS_HOST - _APP_REDIS_PORT - _APP_REDIS_USER @@ -603,7 +625,7 @@ services: hostname: appwrite-executor <<: *x-logging stop_signal: SIGINT - image: openruntimes/executor:0.4.0 + image: openruntimes/executor:0.4.1 networks: - appwrite - runtimes diff --git a/app/workers/builds.php b/app/workers/builds.php index 6ae8df5159..79e9abda57 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -20,6 +20,7 @@ use Utopia\Database\Database; use Utopia\Database\Query; use Utopia\Storage\Storage; use Utopia\Database\Validator\Authorization; +use Utopia\Storage\Device\Local; use Utopia\VCS\Adapter\Git\GitHub; require_once __DIR__ . '/../init.php'; @@ -248,22 +249,25 @@ class BuildsV1 extends Worker ); } - Console::execute('tar --exclude code.tar.gz -czf /tmp/builds/' . \escapeshellcmd($buildId) . '/code.tar.gz -C /tmp/builds/' . \escapeshellcmd($buildId) . '/code' . (empty($rootDirectory) ? '' : '/' . $rootDirectory) . ' .', '', $stdout, $stderr); + $tmpPath = '/tmp/builds/' . \escapeshellcmd($buildId); + $tmpPathFile = $tmpPath . '/code.tar.gz'; + + Console::execute('tar --exclude code.tar.gz -czf ' . $tmpPathFile . ' -C /tmp/builds/' . \escapeshellcmd($buildId) . '/code' . (empty($rootDirectory) ? '' : '/' . $rootDirectory) . ' .', '', $stdout, $stderr); $deviceFunctions = $this->getFunctionsDevice($project->getId()); - $fileName = 'code.tar.gz'; - $fileTmpName = '/tmp/builds/' . $buildId . '/code.tar.gz'; + $localDevice = new Local(); + $buffer = $localDevice->read($tmpPathFile); + $mimeType = $localDevice->getFileMimeType($tmpPathFile); - $path = $deviceFunctions->getPath($deployment->getId() . '.' . \pathinfo($fileName, PATHINFO_EXTENSION)); - - $result = $deviceFunctions->move($fileTmpName, $path); + $path = $deviceFunctions->getPath($deployment->getId() . '.' . \pathinfo('code.tar.gz', PATHINFO_EXTENSION)); + $result = $deviceFunctions->write($path, $buffer, $mimeType); if (!$result) { throw new \Exception("Unable to move file"); } - Console::execute('rm -rf /tmp/builds/' . \escapeshellcmd($buildId), '', $stdout, $stderr); + Console::execute('rm -rf ' . $tmpPath, '', $stdout, $stderr); $source = $path; diff --git a/app/workers/certificates.php b/app/workers/certificates.php index d390ed442e..4a3b9bccb5 100644 --- a/app/workers/certificates.php +++ b/app/workers/certificates.php @@ -174,6 +174,7 @@ class CertificatesV1 extends Worker $certificate = $this->dbForConsole->updateDocument('certificates', $certificate->getId(), $certificate); } else { + $certificate->removeAttribute('$internalId'); $certificate = $this->dbForConsole->createDocument('certificates', $certificate); } diff --git a/app/workers/functions.php b/app/workers/functions.php index 3fd81e3ee0..9b4f597d8a 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -149,8 +149,25 @@ Server::setResource('execute', function () { $durationStart = \microtime(true); + $body = $eventData ?? ''; + if (empty($body)) { + $body = $data ?? ''; + } + $vars = []; + // V2 vars + if ($version === 'v2') { + $vars = \array_merge($vars, [ + 'APPWRITE_FUNCTION_TRIGGER' => $headers['x-appwrite-trigger'] ?? '', + 'APPWRITE_FUNCTION_DATA' => $body ?? '', + 'APPWRITE_FUNCTION_EVENT_DATA' => $body ?? '', + 'APPWRITE_FUNCTION_EVENT' => $headers['x-appwrite-event'] ?? '', + 'APPWRITE_FUNCTION_USER_ID' => $headers['x-appwrite-user-id'] ?? '', + 'APPWRITE_FUNCTION_JWT' => $headers['x-appwrite-user-jwt'] ?? '' + ]); + } + // Shared vars foreach ($function->getAttribute('varsProject', []) as $var) { $vars[$var->getAttribute('key')] = $var->getAttribute('value', ''); @@ -171,11 +188,6 @@ Server::setResource('execute', function () { 'APPWRITE_FUNCTION_RUNTIME_VERSION' => $runtime['version'] ?? '', ]); - $body = $eventData ?? ''; - if (empty($body)) { - $body = $data ?? ''; - } - /** Execute function */ try { $version = $function->getAttribute('version', 'v2'); diff --git a/composer.json b/composer.json index 221af79167..cb83ea75bc 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "ext-openssl": "*", "ext-zlib": "*", "ext-sockets": "*", - "appwrite/php-runtimes": "0.12.0", + "appwrite/php-runtimes": "0.13.*", "appwrite/php-clamav": "2.0.*", "utopia-php/abuse": "0.31.*", "utopia-php/analytics": "0.10.*", @@ -49,7 +49,7 @@ "utopia-php/cache": "0.8.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.43.0", + "utopia-php/database": "0.43.*", "utopia-php/domains": "0.3.*", "utopia-php/dsn": "0.1.*", "utopia-php/framework": "0.31.0", @@ -66,7 +66,7 @@ "utopia-php/registry": "0.5.*", "utopia-php/storage": "0.14.*", "utopia-php/swoole": "0.5.*", - "utopia-php/vcs": "0.4.*", + "utopia-php/vcs": "0.5.*", "utopia-php/websocket": "0.1.*", "resque/php-resque": "1.3.6", "matomo/device-detector": "6.1.*", @@ -84,8 +84,8 @@ } ], "require-dev": { - "appwrite/sdk-generator": "0.35.0", "ext-fileinfo": "*", + "appwrite/sdk-generator": "0.35.*", "phpunit/phpunit": "9.5.20", "squizlabs/php_codesniffer": "^3.7", "swoole/ide-helper": "5.0.2", diff --git a/docker-compose.yml b/docker-compose.yml index 874b6c11a3..27e5f42b76 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -414,6 +414,27 @@ services: - _APP_FUNCTIONS_MEMORY - _APP_OPTIONS_FORCE_HTTPS - _APP_DOMAIN + - _APP_STORAGE_DEVICE + - _APP_STORAGE_S3_ACCESS_KEY + - _APP_STORAGE_S3_SECRET + - _APP_STORAGE_S3_REGION + - _APP_STORAGE_S3_BUCKET + - _APP_STORAGE_DO_SPACES_ACCESS_KEY + - _APP_STORAGE_DO_SPACES_SECRET + - _APP_STORAGE_DO_SPACES_REGION + - _APP_STORAGE_DO_SPACES_BUCKET + - _APP_STORAGE_BACKBLAZE_ACCESS_KEY + - _APP_STORAGE_BACKBLAZE_SECRET + - _APP_STORAGE_BACKBLAZE_REGION + - _APP_STORAGE_BACKBLAZE_BUCKET + - _APP_STORAGE_LINODE_ACCESS_KEY + - _APP_STORAGE_LINODE_SECRET + - _APP_STORAGE_LINODE_REGION + - _APP_STORAGE_LINODE_BUCKET + - _APP_STORAGE_WASABI_ACCESS_KEY + - _APP_STORAGE_WASABI_SECRET + - _APP_STORAGE_WASABI_REGION + - _APP_STORAGE_WASABI_BUCKET appwrite-worker-certificates: entrypoint: worker-certificates @@ -669,6 +690,7 @@ services: environment: - _APP_ENV - _APP_WORKER_PER_CORE + - _APP_OPENSSL_KEY_V1 - _APP_REDIS_HOST - _APP_REDIS_PORT - _APP_REDIS_USER @@ -692,7 +714,7 @@ services: hostname: appwrite-executor <<: *x-logging stop_signal: SIGINT - image: openruntimes/executor:0.4.0 + image: openruntimes/executor:0.4.1 networks: - appwrite - runtimes diff --git a/src/Appwrite/Event/Validator/Event.php b/src/Appwrite/Event/Validator/Event.php index 3f22900486..2061d53ed8 100644 --- a/src/Appwrite/Event/Validator/Event.php +++ b/src/Appwrite/Event/Validator/Event.php @@ -45,12 +45,6 @@ class Event extends Validator * Identify all sections of the pattern. */ $type = $parts[0] ?? false; - - if ($type == 'functions') { - $this->message = 'Triggering a function on a function event is not allowed.'; - return false; - } - $resource = $parts[1] ?? false; $hasSubResource = $count > 3 && ($events[$type]['$resource'] ?? false) && ($events[$type][$parts[2]]['$resource'] ?? false); $hasSubSubResource = $count > 5 && $hasSubResource && ($events[$type][$parts[2]][$parts[4]]['$resource'] ?? false); diff --git a/src/Appwrite/Event/Validator/FunctionEvent.php b/src/Appwrite/Event/Validator/FunctionEvent.php new file mode 100644 index 0000000000..6443b127ad --- /dev/null +++ b/src/Appwrite/Event/Validator/FunctionEvent.php @@ -0,0 +1,25 @@ +message = 'Triggering a function on a function event is not allowed.'; + return false; + } + + return parent::isValid($value); + } +} diff --git a/src/Appwrite/GraphQL/Types/Mapper.php b/src/Appwrite/GraphQL/Types/Mapper.php index 0f9ad661f6..280d094a0c 100644 --- a/src/Appwrite/GraphQL/Types/Mapper.php +++ b/src/Appwrite/GraphQL/Types/Mapper.php @@ -235,6 +235,7 @@ class Mapper case 'Utopia\Validator\Domain': case 'Appwrite\Network\Validator\Email': case 'Appwrite\Event\Validator\Event': + case 'Appwrite\Event\Validator\FunctionEvent': case 'Utopia\Validator\HexColor': case 'Utopia\Validator\Host': case 'Utopia\Validator\IP': diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index 2a53ae27ca..09f39d3169 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -67,6 +67,7 @@ abstract class Migration '1.4.0' => 'V19', '1.4.1' => 'V19', '1.4.2' => 'V19', + '1.4.3' => 'V19', ]; /** diff --git a/src/Appwrite/Platform/Tasks/Doctor.php b/src/Appwrite/Platform/Tasks/Doctor.php index 9a6d6a2847..423dd78fe7 100644 --- a/src/Appwrite/Platform/Tasks/Doctor.php +++ b/src/Appwrite/Platform/Tasks/Doctor.php @@ -245,7 +245,7 @@ class Doctor extends Action try { if (App::isProduction()) { Console::log(''); - $version = \json_decode(@\file_get_contents(App::getEnv('_APP_HOME', 'http://localhost') . '/v1/health/version'), true); + $version = \json_decode(@\file_get_contents(App::getEnv('_APP_HOME', 'http://localhost') . '/version'), true); if ($version && isset($version['version'])) { if (\version_compare($version['version'], App::getEnv('_APP_VERSION', 'UNKNOWN')) === 0) { diff --git a/src/Appwrite/Platform/Tasks/Schedule.php b/src/Appwrite/Platform/Tasks/Schedule.php index 6883ee30da..a136ee62b1 100644 --- a/src/Appwrite/Platform/Tasks/Schedule.php +++ b/src/Appwrite/Platform/Tasks/Schedule.php @@ -89,7 +89,12 @@ class Schedule extends Action $sum = count($results); $total = $total + $sum; foreach ($results as $document) { - $schedules[$document['resourceId']] = $getSchedule($document); + try { + $schedules[$document['resourceId']] = $getSchedule($document); + } catch (\Throwable $th) { + Console::error("Failed to load schedule for project {$document['projectId']} and function {$document['resourceId']}"); + Console::error($th->getMessage()); + } } $latestDocument = !empty(array_key_last($results)) ? $results[array_key_last($results)] : null; diff --git a/tests/unit/Event/Validator/EventValidatorTest.php b/tests/unit/Event/Validator/EventValidatorTest.php index cf62ecca65..e9f652adeb 100644 --- a/tests/unit/Event/Validator/EventValidatorTest.php +++ b/tests/unit/Event/Validator/EventValidatorTest.php @@ -50,7 +50,7 @@ class EventValidatorTest extends TestCase $this->assertTrue($this->object->isValid('databases.books')); $this->assertTrue($this->object->isValid('databases.books.collections.chapters')); $this->assertTrue($this->object->isValid('databases.books.collections.*')); - // $this->assertTrue($this->object->isValid('functions.*')); TODO @christyjacob4 : enable test once we allow functions.* events + $this->assertTrue($this->object->isValid('functions.*')); $this->assertTrue($this->object->isValid('buckets.*')); $this->assertTrue($this->object->isValid('teams.*')); $this->assertTrue($this->object->isValid('users.*')); diff --git a/tests/unit/Event/Validator/FunctionEventValidatorTest.php b/tests/unit/Event/Validator/FunctionEventValidatorTest.php new file mode 100644 index 0000000000..ea59f6771a --- /dev/null +++ b/tests/unit/Event/Validator/FunctionEventValidatorTest.php @@ -0,0 +1,73 @@ +object = new FunctionEvent(); + } + + public function tearDown(): void + { + } + + public function testValues(): void + { + /** + * Test for SUCCESS + */ + $this->assertTrue($this->object->isValid('users.*.create')); + $this->assertTrue($this->object->isValid('users.torsten.update')); + $this->assertTrue($this->object->isValid('users.torsten')); + $this->assertTrue($this->object->isValid('users.*.update.email')); + $this->assertTrue($this->object->isValid('users.*.update')); + $this->assertTrue($this->object->isValid('users.*')); + $this->assertTrue($this->object->isValid('databases.books.collections.chapters.documents.prolog.create')); + $this->assertTrue($this->object->isValid('databases.books.collections.chapters.documents.prolog')); + $this->assertTrue($this->object->isValid('databases.books.collections.chapters.documents.*.create')); + $this->assertTrue($this->object->isValid('databases.books.collections.chapters.documents.*')); + $this->assertTrue($this->object->isValid('databases.books.collections.*.documents.prolog.create')); + $this->assertTrue($this->object->isValid('databases.books.collections.*.documents.prolog')); + $this->assertTrue($this->object->isValid('databases.books.collections.*.documents.*.create')); + $this->assertTrue($this->object->isValid('databases.books.collections.*.documents.*')); + $this->assertTrue($this->object->isValid('databases.*.collections.chapters.documents.prolog.create')); + $this->assertTrue($this->object->isValid('databases.*.collections.chapters.documents.prolog')); + $this->assertTrue($this->object->isValid('databases.*.collections.chapters.documents.*.create')); + $this->assertTrue($this->object->isValid('databases.*.collections.chapters.documents.*')); + $this->assertTrue($this->object->isValid('databases.*.collections.*.documents.prolog.create')); + $this->assertTrue($this->object->isValid('databases.*.collections.*.documents.prolog')); + $this->assertTrue($this->object->isValid('databases.*.collections.*.documents.*.create')); + $this->assertTrue($this->object->isValid('databases.*.collections.*.documents.*')); + $this->assertTrue($this->object->isValid('databases.*.collections.*')); + $this->assertTrue($this->object->isValid('databases.*')); + $this->assertTrue($this->object->isValid('databases.books')); + $this->assertTrue($this->object->isValid('databases.books.collections.chapters')); + $this->assertTrue($this->object->isValid('databases.books.collections.*')); + $this->assertTrue($this->object->isValid('buckets.*')); + $this->assertTrue($this->object->isValid('teams.*')); + $this->assertTrue($this->object->isValid('users.*')); + $this->assertTrue($this->object->isValid('teams.*.memberships.*.update.status')); + + /** + * Test for FAILURE + */ + $this->assertFalse($this->object->isValid(false)); + $this->assertFalse($this->object->isValid(null)); + $this->assertFalse($this->object->isValid('')); + $this->assertFalse($this->object->isValid('unknown.*')); + $this->assertFalse($this->object->isValid('collections')); + $this->assertFalse($this->object->isValid('collections.*.unknown')); + $this->assertFalse($this->object->isValid('collections.*.documents.*.unknown')); + $this->assertFalse($this->object->isValid('users.torsten.unknown')); + $this->assertFalse($this->object->isValid('users.torsten.delete.email')); + $this->assertFalse($this->object->isValid('teams.*.memberships.*.update.unknown')); + $this->assertFalse($this->object->isValid('functions.*')); + } +}