diff --git a/frontend/amundsen_application/api/__init__.py b/frontend/amundsen_application/api/__init__.py index f0f13cdea2..6c5e44c724 100644 --- a/frontend/amundsen_application/api/__init__.py +++ b/frontend/amundsen_application/api/__init__.py @@ -15,17 +15,22 @@ 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: +def index(path: str, frontend_base: str, config_override_enabled: bool) -> 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..604b14ff32 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/js/config/config-types.ts b/frontend/amundsen_application/static/js/config/config-types.ts index ad002f7eb3..ba4413cda0 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..0c4963bacf 100644 --- a/frontend/amundsen_application/static/js/config/config.ts +++ b/frontend/amundsen_application/static/js/config/config.ts @@ -1,8 +1,15 @@ -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. + +const appConfig: AppConfig = { + ...configDefault, + ...configCustom, + ...(((globalThis as unknown) as AppConfigExternal)?.configExternal || {}), +}; export default appConfig; 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" %}