From ad24ac329d881b9143a320e4a9ab356fde466f7d Mon Sep 17 00:00:00 2001 From: rajasekhar reddy Date: Thu, 21 Apr 2022 17:00:57 +0530 Subject: [PATCH 1/5] Apply App config with out rebuild the application Signed-off-by: rajasekhar reddy --- .../static/js/config/config-types.ts | 9 +++++++++ .../amundsen_application/static/js/config/config.ts | 11 +++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/frontend/amundsen_application/static/js/config/config-types.ts b/frontend/amundsen_application/static/js/config/config-types.ts index ad002f7eb3..b983bf3dd7 100644 --- a/frontend/amundsen_application/static/js/config/config-types.ts +++ b/frontend/amundsen_application/static/js/config/config-types.ts @@ -39,6 +39,15 @@ export interface AppConfig { productTour: ToursConfig; } +/** + * configExternal - If you choose to override one of the configs, you must provide the full type definition + * for configExternal + */ + + export interface AppConfigExternal { + configExternal: AppConfig; + } + export interface AppConfigCustom { analytics?: AnalyticsConfig; badges?: BadgeConfig; diff --git a/frontend/amundsen_application/static/js/config/config.ts b/frontend/amundsen_application/static/js/config/config.ts index 9b820032cf..ef335e8c87 100644 --- a/frontend/amundsen_application/static/js/config/config.ts +++ b/frontend/amundsen_application/static/js/config/config.ts @@ -1,8 +1,11 @@ -import { AppConfig } from './config-types'; +import { AppConfig, AppConfigExternal } from './config-types'; import configDefault from './config-default'; import configCustom from './config-custom'; -// This is not a shallow merge. Any defined members of customConfig will override configDefault. -const appConfig: AppConfig = { ...configDefault, ...configCustom }; +// This is not a shallow merge. In two steps we are overriding the application config +// Step 1: Any defined members of customConfig will override configDefault. +// Step 2: Any defined members of configExternal will override the configDefault and configCustom. -export default appConfig; +const appConfig: AppConfig = { ...configDefault, ...configCustom, ...(((globalThis as unknown) as AppConfigExternal)?.configExternal || {}) }; + +export default appConfig; \ No newline at end of file From dde040820e2949e1bcc5fa5e9822b90bd58abd52 Mon Sep 17 00:00:00 2001 From: Aneesh Joseph Date: Thu, 28 Apr 2022 07:28:41 +0530 Subject: [PATCH 2/5] use config override if JS_CONFIG_OVERRIDE_ENABLED is set Signed-off-by: Aneesh Joseph --- frontend/amundsen_application/api/__init__.py | 7 +++++-- frontend/amundsen_application/config.py | 6 ++++++ frontend/amundsen_application/static/templates/index.html | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/frontend/amundsen_application/api/__init__.py b/frontend/amundsen_application/api/__init__.py index f0f13cdea2..67859cd440 100644 --- a/frontend/amundsen_application/api/__init__.py +++ b/frontend/amundsen_application/api/__init__.py @@ -15,17 +15,20 @@ def init_routes(app: Flask) -> None: frontend_base = app.config.get('FRONTEND_BASE') + config_override_enabled = app.config.get('JS_CONFIG_OVERRIDE_ENABLED') app.add_url_rule('/healthcheck', 'healthcheck', healthcheck) app.add_url_rule('/opensearch.xml', 'opensearch.xml', opensearch, defaults={'frontend_base': frontend_base}) app.add_url_rule('/', 'index', index, defaults={'path': '', + 'config_override_enabled': config_override_enabled, 'frontend_base': frontend_base}) # also functions as catch_all - app.add_url_rule('/', 'index', index, defaults={'frontend_base': frontend_base}) # catch_all + app.add_url_rule('/', 'index', index, defaults={'frontend_base': frontend_base, + 'config_override_enabled': config_override_enabled}) # catch_all def index(path: str, frontend_base: str) -> Any: try: - return render_template("index.html", env=ENVIRONMENT, frontend_base=frontend_base) # pragma: no cover + return render_template("index.html", env=ENVIRONMENT, frontend_base=frontend_base, config_override_enabled=config_override_enabled) # pragma: no cover except jinja2.exceptions.TemplateNotFound as e: LOGGER.error("index.html template not found, have you built the front-end JS (npm run build in static/?") raise e diff --git a/frontend/amundsen_application/config.py b/frontend/amundsen_application/config.py index 13bf82fa4e..0716080b9d 100644 --- a/frontend/amundsen_application/config.py +++ b/frontend/amundsen_application/config.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 import os +import distutils.util from typing import Callable, Dict, List, Optional, Set # noqa: F401 from amundsen_application.models.user import User @@ -57,6 +58,9 @@ class Config: # Frontend Application FRONTEND_BASE = '' + # JS config override for frontend app + JS_CONFIG_OVERRIDE_ENABLED=False + # Search Service SEARCHSERVICE_REQUEST_CLIENT = None SEARCHSERVICE_REQUEST_HEADERS = None @@ -156,6 +160,8 @@ class LocalConfig(Config): # If installing using the Docker bootstrap, this should be modified to the docker host ip. LOCAL_HOST = '0.0.0.0' + JS_CONFIG_OVERRIDE_ENABLED = distutils.util.strtobool(os.environ.get('JS_CONFIG_OVERRIDE_ENABLED','False')) + FRONTEND_BASE = os.environ.get('FRONTEND_BASE', 'http://{LOCAL_HOST}:{PORT}'.format( LOCAL_HOST=LOCAL_HOST, diff --git a/frontend/amundsen_application/static/templates/index.html b/frontend/amundsen_application/static/templates/index.html index 7eadb05585..903bf9dd4e 100644 --- a/frontend/amundsen_application/static/templates/index.html +++ b/frontend/amundsen_application/static/templates/index.html @@ -10,6 +10,9 @@ Amundsen - Data Discovery Portal + {% if config_override_enabled %} + + {% endif %} {% if env == "development" %} {% include 'fragments/icons-dev.html' %} {% elif env == "staging" %} From 64e8682153a59e521044ba6d1f584188e607e0bc Mon Sep 17 00:00:00 2001 From: rajasekhar reddy Date: Fri, 6 May 2022 10:24:36 +0530 Subject: [PATCH 3/5] Fixed lint errors Signed-off-by: rajasekhar reddy --- .../amundsen_application/static/js/config/config.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frontend/amundsen_application/static/js/config/config.ts b/frontend/amundsen_application/static/js/config/config.ts index ef335e8c87..0c4963bacf 100644 --- a/frontend/amundsen_application/static/js/config/config.ts +++ b/frontend/amundsen_application/static/js/config/config.ts @@ -2,10 +2,14 @@ import { AppConfig, AppConfigExternal } from './config-types'; import configDefault from './config-default'; import configCustom from './config-custom'; -// This is not a shallow merge. In two steps we are overriding the application config +// This is not a shallow merge. In two steps we are overriding the application config // Step 1: Any defined members of customConfig will override configDefault. // Step 2: Any defined members of configExternal will override the configDefault and configCustom. -const appConfig: AppConfig = { ...configDefault, ...configCustom, ...(((globalThis as unknown) as AppConfigExternal)?.configExternal || {}) }; +const appConfig: AppConfig = { + ...configDefault, + ...configCustom, + ...(((globalThis as unknown) as AppConfigExternal)?.configExternal || {}), +}; -export default appConfig; \ No newline at end of file +export default appConfig; From e8ce53957e47783613a56e8c71064f127566c65d Mon Sep 17 00:00:00 2001 From: Aneesh Joseph Date: Fri, 6 May 2022 11:56:13 +0530 Subject: [PATCH 4/5] fix lint errors Signed-off-by: Aneesh Joseph --- frontend/amundsen_application/api/__init__.py | 10 ++++++---- frontend/amundsen_application/config.py | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/frontend/amundsen_application/api/__init__.py b/frontend/amundsen_application/api/__init__.py index 67859cd440..6c5e44c724 100644 --- a/frontend/amundsen_application/api/__init__.py +++ b/frontend/amundsen_application/api/__init__.py @@ -22,13 +22,15 @@ def init_routes(app: Flask) -> None: app.add_url_rule('/', 'index', index, defaults={'path': '', 'config_override_enabled': config_override_enabled, 'frontend_base': frontend_base}) # also functions as catch_all - app.add_url_rule('/', 'index', index, defaults={'frontend_base': frontend_base, - 'config_override_enabled': config_override_enabled}) # catch_all + app.add_url_rule('/', 'index', index, + defaults={'frontend_base': frontend_base, + 'config_override_enabled': config_override_enabled}) # catch_all -def index(path: str, frontend_base: str) -> Any: +def index(path: str, frontend_base: str, config_override_enabled: bool) -> Any: try: - return render_template("index.html", env=ENVIRONMENT, frontend_base=frontend_base, config_override_enabled=config_override_enabled) # pragma: no cover + return render_template("index.html", env=ENVIRONMENT, frontend_base=frontend_base, + config_override_enabled=config_override_enabled) # pragma: no cover except jinja2.exceptions.TemplateNotFound as e: LOGGER.error("index.html template not found, have you built the front-end JS (npm run build in static/?") raise e diff --git a/frontend/amundsen_application/config.py b/frontend/amundsen_application/config.py index 0716080b9d..604b14ff32 100644 --- a/frontend/amundsen_application/config.py +++ b/frontend/amundsen_application/config.py @@ -59,7 +59,7 @@ class Config: FRONTEND_BASE = '' # JS config override for frontend app - JS_CONFIG_OVERRIDE_ENABLED=False + JS_CONFIG_OVERRIDE_ENABLED = False # Search Service SEARCHSERVICE_REQUEST_CLIENT = None @@ -160,7 +160,7 @@ class LocalConfig(Config): # If installing using the Docker bootstrap, this should be modified to the docker host ip. LOCAL_HOST = '0.0.0.0' - JS_CONFIG_OVERRIDE_ENABLED = distutils.util.strtobool(os.environ.get('JS_CONFIG_OVERRIDE_ENABLED','False')) + JS_CONFIG_OVERRIDE_ENABLED = distutils.util.strtobool(os.environ.get('JS_CONFIG_OVERRIDE_ENABLED', 'False')) FRONTEND_BASE = os.environ.get('FRONTEND_BASE', 'http://{LOCAL_HOST}:{PORT}'.format( From 274b40ed5e7e76dc4f0ebdc07d5698ebed093e46 Mon Sep 17 00:00:00 2001 From: rajasekhar reddy Date: Tue, 10 May 2022 10:09:07 +0530 Subject: [PATCH 5/5] Resolved lint errors Signed-off-by: rajasekhar reddy --- .../amundsen_application/static/js/config/config-types.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/amundsen_application/static/js/config/config-types.ts b/frontend/amundsen_application/static/js/config/config-types.ts index b983bf3dd7..ba4413cda0 100644 --- a/frontend/amundsen_application/static/js/config/config-types.ts +++ b/frontend/amundsen_application/static/js/config/config-types.ts @@ -44,9 +44,9 @@ export interface AppConfig { * for configExternal */ - export interface AppConfigExternal { - configExternal: AppConfig; - } +export interface AppConfigExternal { + configExternal: AppConfig; +} export interface AppConfigCustom { analytics?: AnalyticsConfig;