Add get_env_or_secret(env, secret) so that it returns docker swarm secret when specified.

Related-FIELD: FIELD-5385
Change-Id: If6a97f26204ca3c758ece38651a08653e51df471
diff --git a/sf_notifier/helpers.py b/sf_notifier/helpers.py
index 4dc4048..7e2b1c8 100644
--- a/sf_notifier/helpers.py
+++ b/sf_notifier/helpers.py
@@ -76,3 +76,17 @@
     if isinstance(name, str):
         return name.lower() == 'true'
     return name is True
+
+def get_env_or_secret(env, secret):
+    # returns the value of the env var if present,
+    # otherwise docker swarm secret if present,
+    # null when neither of the two present.
+    value = os.getenv(env, 'null')
+    if value != 'null':
+        return value
+    fpath = f'/run/secrets/{secret}'
+    exist = os.path.exists(fpath)
+    if exist:
+        with open(fpath) as file:
+            value = file.read().rstrip('\n')
+    return value
diff --git a/sf_notifier/settings/development.py b/sf_notifier/settings/development.py
index 1569fe3..0efb7e3 100644
--- a/sf_notifier/settings/development.py
+++ b/sf_notifier/settings/development.py
@@ -1,6 +1,6 @@
 import os
 
-from ..helpers import is_true
+from ..helpers import is_true, get_env_or_secret
 
 
 VERSION = 'development'
@@ -34,10 +34,10 @@
 SF_CONFIG = {
     # Salesforce login params
     'AUTH_URL': os.environ.get('SFDC_AUTH_URL', 'null'),
-    'USERNAME': os.environ.get('SFDC_USERNAME', 'null'),
-    'PASSWORD': os.environ.get('SFDC_PASSWORD', 'null'),
+    'USERNAME': get_env_or_secret('SFDC_USERNAME', 'sfdc_username'),
+    'PASSWORD': get_env_or_secret('SFDC_PASSWORD', 'sfdc_password'),
     'ORGANIZATION_ID': os.environ.get('SFDC_ORGANIZATION_ID', 'null'),
-    'ENVIRONMENT_ID': os.environ.get('SFDC_ENVIRONMENT_ID', 'null'),
+    'ENVIRONMENT_ID': get_env_or_secret('SFDC_ENVIRONMENT_ID', 'sfdc_environment_id'),
     'SANDBOX_ENABLED': is_true(os.environ.get(
         'SFDC_SANDBOX_ENABLED', 'False')),
     # sf-notifier specific params
diff --git a/sf_notifier/settings/production.py b/sf_notifier/settings/production.py
index 6458662..054d433 100644
--- a/sf_notifier/settings/production.py
+++ b/sf_notifier/settings/production.py
@@ -1,6 +1,6 @@
 import os
 
-from ..helpers import is_true
+from ..helpers import is_true, get_env_or_secret
 
 
 VERSION = 'production'
@@ -45,10 +45,10 @@
 SF_CONFIG = {
     # Salesforce login params
     'AUTH_URL': os.environ.get('SFDC_AUTH_URL', 'null'),
-    'USERNAME': os.environ.get('SFDC_USERNAME', 'null'),
-    'PASSWORD': os.environ.get('SFDC_PASSWORD', 'null'),
+    'USERNAME': get_env_or_secret('SFDC_USERNAME', 'sfdc_username'),
+    'PASSWORD': get_env_or_secret('SFDC_PASSWORD', 'sfdc_password'),
     'ORGANIZATION_ID': os.environ.get('SFDC_ORGANIZATION_ID', 'null'),
-    'ENVIRONMENT_ID': os.environ.get('SFDC_ENVIRONMENT_ID', 'null'),
+    'ENVIRONMENT_ID': get_env_or_secret('SFDC_ENVIRONMENT_ID', 'sfdc_environment_id'),
     'SANDBOX_ENABLED': is_true(os.environ.get(
         'SFDC_SANDBOX_ENABLED', 'False')),
     # sf-notifier specific params