-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed Webserver.conf + Db.conf to Environment variable + Removed se…
…d / jq use Details of files changed 1. Start scripts .docker/docker_start_script.sh emission/integrationTests/start_integration_tests.sh setup/tests/start_script.sh - Changed seq / jq usage to directly set Environment variable to desired value; no need of saving sample file as actual conf json file. 2. Config.py files emission/core/config.py emission/net/api/config.py emission/net/ext_service/push/config.py - Based this file on emission/analysis/config.py - Added these to read from conf files if present or environment variables instead of sample files. - Default values set are taken from sample files. - check_unset_env_vars() can be used to check whether ALL environment variables are unset. 3. DB, Webapp, Push application usage files emission/core/get_database.py emission/net/api/cfc_webapp.py emission/net/ext_service/push/notify_interface.py - Changed logic to read using the config.py files that read the non-sample actual config files if present or from the Environment variables instead of sample files. 4. Test Files emission/integrationTests/storageTests/TestMongodbAuth.py emission/tests/netTests/TestWebserver.py emission/tests/netTests/TestPush.py - Test files that exercise the functionality of the logic in the files in (3). - Earlier, config files were being replaced with test values and copied over for testing purposes. - Now, switching to using environment variables - call sent to config files in (2) indirectly via application usage files in (3) - Following flow is followed in reading from and restoring original environment variables values setup() - Sets ENV vars by storing original vars if set, then uses test ENV vars as new values TestFunc() - importing modules named in (3) causes values to be read in, which now reads in newer test values since they set the ENV vars in setup() - only those ENV vars in test values are set; unchanged ones left untouched or default values read using os.getenv(var name, default) teardown() - Unset test ENV vars by using del os.environ[var_name] - Restore original values from original dict
- Loading branch information
Mahadik, Mukul Chandrakant
authored and
Mahadik, Mukul Chandrakant
committed
Apr 12, 2024
1 parent
4aeb4a6
commit 2531672
Showing
12 changed files
with
173 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import json | ||
import logging | ||
import os | ||
|
||
def get_config_data_from_env(): | ||
config_data_env = { | ||
"url": os.getenv('DB_HOST', "localhost"), | ||
"result_limit": os.getenv('DB_TS_RESULT_LIMIT', 250000) | ||
} | ||
return config_data_env | ||
|
||
def check_unset_env_vars(): | ||
config_data_env = { | ||
"url": os.getenv('DB_HOST'), | ||
"result_limit": os.getenv('DB_TS_RESULT_LIMIT') | ||
} | ||
return not any(config_data_env.values()) | ||
|
||
def get_config_data(): | ||
try: | ||
config_file = open('conf/storage/db.conf') | ||
ret_val = json.load(config_file) | ||
config_file.close() | ||
except: | ||
# Check if all DB environment variables are not set | ||
# if check_unset_env_vars(): | ||
# print("All DB environment variables are set to None") | ||
logging.debug("storage 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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 check_unset_env_vars(): | ||
config_data_env = { | ||
"static_path": os.getenv('WEB_SERVER_STATIC_PATH'), | ||
"server_host": os.getenv('WEB_SERVER_HOST'), | ||
"server_port": os.getenv('WEB_SERVER_PORT'), | ||
"socket_timeout": os.getenv('WEB_SERVER_TIMEOUT'), | ||
"auth_method": os.getenv('WEB_SERVER_AUTH'), | ||
"aggregate_call_auth": os.getenv('WEB_SERVER_AGGREGATE_CALL_AUTH'), | ||
"not_found_redirect": os.getenv('WEB_SERVER_REDIRECT_URL') | ||
} | ||
return not any(config_data_env.values()) | ||
|
||
def get_config_data(): | ||
try: | ||
config_file = open('conf/storage/db.conf') | ||
ret_val = json.load(config_file) | ||
config_file.close() | ||
except: | ||
# Check if all Webserver environment variables are not set | ||
# 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters