From ed81ff126338a3ea445b46445e6bd43d30904053 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 8 Sep 2022 07:19:14 +0000 Subject: [PATCH] regions using config instead --- .env | 3 --- Dockerfile | 5 +---- app/config/regions.php | 18 ++++++++++++++++++ app/controllers/api/projects.php | 2 +- app/controllers/web/console.php | 4 +--- app/http.php | 2 +- app/init.php | 1 + app/views/console/comps/header.phtml | 8 ++------ docker-compose.yml | 3 --- 9 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 app/config/regions.php diff --git a/.env b/.env index d23704bef8..227ea10676 100644 --- a/.env +++ b/.env @@ -81,9 +81,6 @@ _APP_USAGE_DATABASE_INTERVAL=15 _APP_USAGE_STATS=enabled _APP_LOGGING_PROVIDER= _APP_LOGGING_CONFIG= -_APP_REGION_DEFAULT=default -_APP_REGIONS=default,nyc,frank -_APP_REGIONS_DISABLED=nyc DOCKERHUB_PULL_USERNAME= DOCKERHUB_PULL_PASSWORD= DOCKERHUB_PULL_EMAIL= \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 339c80e063..a7cae38502 100755 --- a/Dockerfile +++ b/Dockerfile @@ -255,10 +255,7 @@ ENV _APP_SERVER=swoole \ _APP_MAINTENANCE_RETENTION_ABUSE=86400 \ _APP_MAINTENANCE_INTERVAL=86400 \ _APP_LOGGING_PROVIDER= \ - _APP_LOGGING_CONFIG= \ - _APP_REGIONS=default \ - _APP_REGION_DEFAULT=default \ - _APP_REGIONS_DISABLED= + _APP_LOGGING_CONFIG= RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone diff --git a/app/config/regions.php b/app/config/regions.php new file mode 100644 index 0000000000..03608332c0 --- /dev/null +++ b/app/config/regions.php @@ -0,0 +1,18 @@ + [ + 'name' => 'Default', + 'default' => true, + 'disabled' => false, + ], + 'fra001' => [ + 'name' => 'Frankfurt', + 'default' => false, + 'disabled' => false, + ], + 'nyc001' => [ + 'name' => 'New York', + 'default' => false, + 'disabled' => true, + ], +]; diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index eeab749bb2..5574a4e684 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -58,7 +58,7 @@ App::post('/v1/projects') ->param('projectId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string "unique()" to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', null, new Text(128), 'Project name. Max length: 128 chars.') ->param('teamId', '', new UID(), 'Team unique ID.') - ->param('region', '', new Whitelist(explode(',', App::getEnv('_APP_REGIONS', ''))), 'Project Region.', true) + ->param('region', '', new Whitelist(array_keys(array_filter(Config::getParam('regions'), fn($config) => !$config['disabled']))), 'Project Region.', true) ->param('description', '', new Text(256), 'Project description. Max length: 256 chars.', true) ->param('logo', '', new Text(1024), 'Project logo.', true) ->param('url', '', new URL(), 'Project URL.', true) diff --git a/app/controllers/web/console.php b/app/controllers/web/console.php index cb876d24c8..88354502b1 100644 --- a/app/controllers/web/console.php +++ b/app/controllers/web/console.php @@ -29,9 +29,7 @@ App::shutdown() $footer = new View(__DIR__ . '/../../views/console/comps/footer.phtml'); $header - ->setParam('regions', explode(',', App::getEnv('_APP_REGIONS', ''))) - ->setParam('disabledRegions', explode(',', App::getEnv('_APP_REGIONS_DISABLED', ''))) - ->setParam('defaultRegion', App::getEnv('_APP_REGION_DEFAULT', 'default')) + ->setParam('regions', Config::getParam('regions', [])) ; $footer diff --git a/app/http.php b/app/http.php index b37bd28abd..b19b2193d5 100644 --- a/app/http.php +++ b/app/http.php @@ -27,7 +27,7 @@ $http = new Server("0.0.0.0", App::getEnv('PORT', 80)); $payloadSize = 6 * (1024 * 1024); // 6MB $workerNumber = swoole_cpu_num() * intval(App::getEnv('_APP_WORKER_PER_CORE', 6)); -var_dump(explode(',', App::getEnv('_APP_REGIONS', ''))); +var_dump(App::getEnv('_APP_REGION_DEFAULT', '')); $http ->set([ 'worker_num' => $workerNumber, diff --git a/app/init.php b/app/init.php index 89d33616f8..9063091f35 100644 --- a/app/init.php +++ b/app/init.php @@ -188,6 +188,7 @@ 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 Config::load('variables', __DIR__ . '/config/variables.php'); // List of env variables +Config::load('regions', __DIR__ . '/config/regions.php'); // List of available regions Config::load('avatar-browsers', __DIR__ . '/config/avatars/browsers.php'); Config::load('avatar-credit-cards', __DIR__ . '/config/avatars/credit-cards.php'); Config::load('avatar-flags', __DIR__ . '/config/avatars/flags.php'); diff --git a/app/views/console/comps/header.phtml b/app/views/console/comps/header.phtml index 530e46eacd..a41f536904 100644 --- a/app/views/console/comps/header.phtml +++ b/app/views/console/comps/header.phtml @@ -1,7 +1,5 @@ getParam('regions', []); -$disabledRegions = $this->getParam('disabledRegions', []); -$defaultRegion = $this->getParam('defaultRegion', []); ?>