From 4271e34b399940854544ad410cf7b432412c5f61 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 17 Nov 2022 07:44:54 +0000 Subject: [PATCH] feat: review comments --- app/controllers/api/storage.php | 12 ++++++++- app/init.php | 2 +- app/views/install/compose.phtml | 44 ++------------------------------- app/workers/builds.php | 11 ++++++++- 4 files changed, 24 insertions(+), 45 deletions(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 8134c1d419..8dbdcb28c6 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -494,7 +494,17 @@ App::post('/v1/storage/buckets/:bucketId/files') } if ($chunksUploaded === $chunks) { - if (App::getEnv('_APP_STORAGE_ANTIVIRUS') === 'enabled' && $bucket->getAttribute('antivirus', true) && $fileSize <= APP_LIMIT_ANTIVIRUS && App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL) === Storage::DEVICE_LOCAL) { // TODO : fetch from DSN + + $connection = App::getEnv('_APP_CONNECTIONS_STORAGE', ''); + $device = STORAGE_DEVICE_LOCAL; + try { + $dsn = new DSN($connection); + $device = $dsn->getScheme(); + } catch (\Exception $e) { + $device = STORAGE_DEVICE_LOCAL; + } + + if (App::getEnv('_APP_STORAGE_ANTIVIRUS') === 'enabled' && $bucket->getAttribute('antivirus', true) && $fileSize <= APP_LIMIT_ANTIVIRUS && $device === STORAGE_DEVICE_LOCAL) { $antivirus = new Network( App::getEnv('_APP_STORAGE_ANTIVIRUS_HOST', 'clamav'), (int) App::getEnv('_APP_STORAGE_ANTIVIRUS_PORT', 3310) diff --git a/app/init.php b/app/init.php index 03e5e6de75..305f1009d3 100644 --- a/app/init.php +++ b/app/init.php @@ -1123,7 +1123,7 @@ function getDevice($root): Device $bucket = $dsn->getPath(); $region = $dsn->getParam('region'); } catch (\Exception $e) { - Console::error($e->getMessage() . 'Invalid DSN. Defaulting to Local storage.'); + Console::eor($e->getMessage() . 'Invalid DSN. Defaulting to Local storage.'); $device = STORAGE_DEVICE_LOCAL; } diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index bfd1ab1dbe..37cc2beec0 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -120,27 +120,7 @@ services: - _APP_STORAGE_ANTIVIRUS - _APP_STORAGE_ANTIVIRUS_HOST - _APP_STORAGE_ANTIVIRUS_PORT - - _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 + - _APP_CONNECTIONS_STORAGE - _APP_FUNCTIONS_SIZE_LIMIT - _APP_FUNCTIONS_TIMEOUT - _APP_FUNCTIONS_BUILD_TIMEOUT @@ -284,27 +264,7 @@ services: - _APP_REDIS_PORT - _APP_REDIS_USER - _APP_REDIS_PASS - - _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 + - _APP_CONNECTIONS_STORAGE - _APP_LOGGING_PROVIDER - _APP_LOGGING_CONFIG - _APP_EXECUTOR_SECRET diff --git a/app/workers/builds.php b/app/workers/builds.php index bd7b627065..cb553652d8 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -79,6 +79,15 @@ class BuildsV1 extends Worker throw new Exception('Runtime "' . $function->getAttribute('runtime', '') . '" is not supported'); } + $connection = App::getEnv('_APP_CONNECTIONS_STORAGE', ''); + $device = STORAGE_DEVICE_LOCAL; + try { + $dsn = new DSN($connection); + $device = $dsn->getScheme(); + } catch (\Exception $e) { + $device = STORAGE_DEVICE_LOCAL; + } + $buildId = $deployment->getAttribute('buildId', ''); $startTime = DateTime::now(); if (empty($buildId)) { @@ -92,7 +101,7 @@ class BuildsV1 extends Worker 'outputPath' => '', 'runtime' => $function->getAttribute('runtime'), 'source' => $deployment->getAttribute('path'), - 'sourceType' => App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL), // TODO : fetch from DSN + 'sourceType' => $device, 'stdout' => '', 'stderr' => '', 'endTime' => null,