InQuest / omnibus

The OSINT Omnibus (beta release)
MIT License
316 stars 69 forks source link

Add lib/constants.py #22

Open deadbits opened 5 years ago

deadbits commented 5 years ago

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.

import os
import subprocess

__app_stage = 'beta'
__app_major = '1.0'

__cwd = os.path.abspath(os.path.dirname(__file__))

root_path = os.path.abspath(os.path.join(__cwd, '..'))
api_conf = os.path.join(root_path, 'etc/apikeys.json')
app_conf = os.path.join(root_path, 'etc/omnibus.conf')

rev_hash = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
rev_count = subprocess.check_output(["git", "rev-list", "HEAD", "--count"])

build_version = 'v%s.%s-%s_%s' % (__app_major, rev_count.strip(), rev_hash.strip(), __app_stage)
app_version = 'v%s.%s_%s' % (__app_major, rev_count.strip(), __app_stage)

example output from my current local repo:

build: v1.0.125-e73bcf8_beta
app: v1.0.125_beta

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)