From 1d6dace9f46f7085839fb5bfd658c781a3be23c4 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 22 Mar 2022 13:14:13 +0100 Subject: [PATCH] implement admin config checking --- admin/.env.dist | 2 ++ admin/.env.template | 2 ++ admin/src/config/index.js | 25 ++++++++++++++++++++++--- admin/vue.config.js | 7 ++++--- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/admin/.env.dist b/admin/.env.dist index 66c84dda8..d7044669a 100644 --- a/admin/.env.dist +++ b/admin/.env.dist @@ -1,3 +1,5 @@ +CONFIG_VERSION=v1.2022-03-18 + GRAPHQL_URI=http://localhost:4000/graphql WALLET_AUTH_URL=http://localhost/authenticate?token={token} WALLET_URL=http://localhost/login diff --git a/admin/.env.template b/admin/.env.template index a965b1bb1..488c9aba4 100644 --- a/admin/.env.template +++ b/admin/.env.template @@ -1,3 +1,5 @@ +CONFIG_VERSION=$ADMIN_CONFIG_VERSION + GRAPHQL_URI=$GRAPHQL_URI WALLET_AUTH_URL=$WALLET_AUTH_URL WALLET_URL=$WALLET_URL diff --git a/admin/src/config/index.js b/admin/src/config/index.js index f7d361c12..03700b4fa 100644 --- a/admin/src/config/index.js +++ b/admin/src/config/index.js @@ -4,11 +4,20 @@ // Load Package Details for some default values const pkg = require('../../package') +const constants = { + CONFIG_VERSION: { + DEFAULT: 'DEFAULT', + EXPECTED: 'v1.2022-03-18', + CURRENT: '', + }, +} + const version = { APP_VERSION: pkg.version, BUILD_COMMIT: process.env.BUILD_COMMIT || null, // self reference of `version.BUILD_COMMIT` is not possible at this point, hence the duplicate code BUILD_COMMIT_SHORT: (process.env.BUILD_COMMIT || '0000000').substr(0, 7), + PORT: process.env.PORT || 8080, } const environment = { @@ -27,14 +36,24 @@ const debug = { DEBUG_DISABLE_AUTH: process.env.DEBUG_DISABLE_AUTH === 'true' || false, } -const options = {} +// Check config version +constants.CONFIG_VERSION.CURRENT = process.env.CONFIG_VERSION || constants.CONFIG_VERSION.DEFAULT +if ( + ![constants.CONFIG_VERSION.EXPECTED, constants.CONFIG_VERSION.DEFAULT].includes( + constants.CONFIG_VERSION.CURRENT, + ) +) { + throw new Error( + `Fatal: Config Version incorrect - expected "${constants.CONFIG_VERSION.EXPECTED}" or "${constants.CONFIG_VERSION.DEFAULT}", but found "${constants.CONFIG_VERSION.CURRENT}"`, + ) +} const CONFIG = { + ...constants, ...version, ...environment, ...endpoints, - ...options, ...debug, } -export default CONFIG +module.exports = CONFIG diff --git a/admin/vue.config.js b/admin/vue.config.js index 4492312a0..8cc1e4b89 100644 --- a/admin/vue.config.js +++ b/admin/vue.config.js @@ -2,11 +2,12 @@ const path = require('path') const webpack = require('webpack') const Dotenv = require('dotenv-webpack') const StatsPlugin = require('stats-webpack-plugin') +const CONFIG = require('./src/config') // vue.config.js module.exports = { devServer: { - port: process.env.PORT || 8080, + port: CONFIG.PORT, }, pluginOptions: { i18n: { @@ -34,7 +35,7 @@ module.exports = { // 'process.env.DOCKER_WORKDIR': JSON.stringify(process.env.DOCKER_WORKDIR), // 'process.env.BUILD_DATE': JSON.stringify(process.env.BUILD_DATE), // 'process.env.BUILD_VERSION': JSON.stringify(process.env.BUILD_VERSION), - 'process.env.BUILD_COMMIT': JSON.stringify(process.env.BUILD_COMMIT), + 'process.env.BUILD_COMMIT': JSON.stringify(CONFIG.BUILD_COMMIT), // 'process.env.PORT': JSON.stringify(process.env.PORT), }), // generate webpack stats to allow analysis of the bundlesize @@ -46,7 +47,7 @@ module.exports = { }, css: { // Enable CSS source maps. - sourceMap: process.env.NODE_ENV !== 'production', + sourceMap: CONFIG.NODE_ENV !== 'production', }, outputDir: path.resolve(__dirname, './dist'), }