From 168ef10b7f29084f3a90ec497493130227d3ed8f Mon Sep 17 00:00:00 2001 From: Shankari Date: Sat, 10 Aug 2024 15:58:22 -0700 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=20Move=20the=20api=20conf?= =?UTF-8?q?iguration=20into=20the=20backwards=20compat=20as=20well?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consistent with https://github.com/e-mission/e-mission-server/pull/961#issuecomment-2282206511 and 7f1be920098f644d863536a5e810343f2634fc28 (which was the original example for the database) --- emission/net/api/cfc_webapp.py | 29 +++++++++++++++------------ emission/net/api/config.py | 36 ---------------------------------- 2 files changed, 16 insertions(+), 49 deletions(-) delete mode 100644 emission/net/api/config.py diff --git a/emission/net/api/cfc_webapp.py b/emission/net/api/cfc_webapp.py index 4cde31550..9e2eb68fa 100644 --- a/emission/net/api/cfc_webapp.py +++ b/emission/net/api/cfc_webapp.py @@ -51,17 +51,22 @@ import emission.storage.timeseries.cache_series as esdc import emission.core.timer as ect import emission.core.get_database as edb -import emission.net.api.config as enac +import emission.core.backwards_compat_config as ecbc STUDY_CONFIG = os.getenv('STUDY_CONFIG', "stage-program") -enac.reload_config() -static_path = enac.get_config()["static_path"] -server_host = enac.get_config()["server_host"] -server_port = enac.get_config()["server_port"] -socket_timeout = enac.get_config()["socket_timeout"] -auth_method = enac.get_config()["auth_method"] -aggregate_call_auth = enac.get_config()["aggregate_call_auth"] -not_found_redirect = enac.get_config()["not_found_redirect"] + +# Constants that we don't read from the configuration +WEBSERVER_STATIC_PATH="webapp/www" +WEBSERVER_HOST="0.0.0.0" + +config = ecbc.get_config('conf/net/api/webserver.conf', + {"WEBSERVER_PORT": "server.port", "WEBSERVER_TIMEOUT": "server.timeout", + "WEBSERVER_AUTH": "server.auth", "WEBSERVER_AGGREGATE_CALL_AUTH": "server.aggregate_call_auth"}) +server_port = config.get("WEBSERVER_PORT", 8080) +socket_timeout = config.get("WEBSERVER_TIMEOUT", 3600) +auth_method = config.get("WEBSERVER_AUTH", "skip") +aggregate_call_auth = config.get("WEBSERVER_AGGREGATE_CALL_AUTH", "no_auth") +not_found_redirect = config.get("WEBSERVER_NOT_FOUND_REDIRECT", "https://nrel.gov/openpath") BaseRequest.MEMFILE_MAX = 1024 * 1024 * 1024 # Allow the request size to be 1G # to accomodate large section sizes @@ -79,7 +84,7 @@ #Simple path that serves up a static landing page with javascript in it @route('/') def index(): - return static_file("index.html", static_path) + return static_file("index.html", WEBSERVER_STATIC_PATH) # Backward compat to handle older clients # Remove in 2023 after everybody has upgraded @@ -548,6 +553,4 @@ def resolve_auth(auth_method): else: # Non SSL option for testing on localhost print("Running with HTTPS turned OFF - use a reverse proxy on production") - run(host=server_host, port=server_port, server='cheroot', debug=True) - - # run(host="0.0.0.0", port=server_port, server='cherrypy', debug=True) + run(host=WEBSERVER_HOST, port=server_port, server='cheroot', debug=True) diff --git a/emission/net/api/config.py b/emission/net/api/config.py deleted file mode 100644 index e8cbd6392..000000000 --- a/emission/net/api/config.py +++ /dev/null @@ -1,36 +0,0 @@ -import json -import logging -import os - -def get_config_data_from_env(): - config_data_env = { - "static_path": os.getenv('WEB_SERVER_STATIC_PATH', "webapp/www/"), - "server_host": os.getenv('WEB_SERVER_HOST', "0.0.0.0"), - "server_port": os.getenv('WEB_SERVER_PORT', "8080"), - "socket_timeout": os.getenv('WEB_SERVER_TIMEOUT', "3600"), - "auth_method": os.getenv('WEB_SERVER_AUTH', "skip"), - "aggregate_call_auth": os.getenv('WEB_SERVER_AGGREGATE_CALL_AUTH', "no_auth"), - "not_found_redirect": os.getenv('WEB_SERVER_REDIRECT_URL', "https://www.nrel.gov/transportation/openpath.html") - } - return config_data_env - - -def get_config_data(): - try: - config_file = open('conf/net/api/webserver.conf') - ret_val = json.load(config_file) - config_file.close() - except: - # if check_unset_env_vars(): - logging.debug("webserver not configured, falling back to sample, default configuration") - ret_val = get_config_data_from_env() - return ret_val - -config_data = get_config_data() - -def get_config(): - return config_data - -def reload_config(): - global config_data - config_data = get_config_data()