Creating a constants.py file to contain path to root dir, API keys file, app configuration file, app version info.
Found this snippet from the threatshell project by @tstallings at Salesforce and it's a great way to track versioning if users will be filing tickets. I modified the output a bit for build_version and app_version for our needs.
Users could reference the app_version provided and we'll know exactly what they are on for debugging.
Inside omnibus-cli.py and common.py, we'd then just do:
from constants import api_conf
from constants import app_conf
from constants import build_version
from constants import app_version
as needed for printing the current build_version, initializing DB classes with the config files, etc
Example of updated common.py
from constants import api_conf
from constants import app_conf
...
def get_option(section, name):
config = ConfigParser.ConfigParser()
if not os.path.exists(app_conf):
error('configuration file %s does not exist!' % app_conf)
return None
config.read(app_conf)
answer = None
try:
answer = config.get(section, name)
except:
pass
return answer
def get_apikey(service):
""" Read API key config file and return API key by service name """
if os.path.exists(api_conf):
api_keys = load_json(api_conf)
if service in api_keys.keys():
return api_keys[service]
else:
error('cannot find API keys file: %s' % api_conf)
Creating a constants.py file to contain path to root dir, API keys file, app configuration file, app version info.
Found this snippet from the threatshell project by @tstallings at Salesforce and it's a great way to track versioning if users will be filing tickets. I modified the output a bit for build_version and app_version for our needs. Users could reference the app_version provided and we'll know exactly what they are on for debugging.
example output from my current local repo:
Inside omnibus-cli.py and common.py, we'd then just do:
as needed for printing the current build_version, initializing DB classes with the config files, etc
Example of updated common.py