Skip to content

Commit

Permalink
Add warning for missing necessary Environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
thealphadollar committed May 16, 2018
1 parent a70b67e commit a7e4cf4
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions nephos/load_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def _correct_log_file_path(self, handler_name):
def _config_update(self):
"""
Overrides/Updates data present in the configuration files
Environment variables used:
CRED_MAIL:
type: str
Expand Down Expand Up @@ -160,8 +161,8 @@ def _config_update(self):
},
'email':
{
'credentials': (os.getenv('CRED_EMAIL'), os.getenv('CRED_PASS')),
'mailhost': (os.getenv('MAIL_HOST'), os.getenv('MAIL_PORT')),
'credentials': (get_env_var('CRED_EMAIL'), get_env_var('CRED_PASS')),
'mailhost': (get_env_var('MAIL_HOST'), get_env_var('MAIL_PORT')),
'secure': ()
}
}
Expand All @@ -180,3 +181,26 @@ def _config_update(self):

config_list = [nephos_config_update, recorder_config_update, preprocess_config_update, uploader_config_update]
return config_list


def get_env_var(name):
"""
Gets environment variable from the OS
Issues a warning if the environment variable is not fount.
Parameters
----------
name
type:str
name of the environment variable
Returns
-------
type: depends on environment variable
data of the environment variable
"""
env_value = os.getenv(name)
if len(name) == 0:
print("Warning: Environment variable {env_name} not set! Some functions might not work properly!")
return env_value

0 comments on commit a7e4cf4

Please sign in to comment.