import os
import sys
import json

from pymongo import MongoClient

MAIN_OS_VARIABLE = json.loads(os.environ.get('config'))
if MAIN_OS_VARIABLE is None:
	sys.stderr.write("Configuration not found...")
	sys.stderr.write("Exiting....")
	sys.exit(1)

MONGO_URI = MAIN_OS_VARIABLE.get('MONGO_URI')
MONGO_SERVICE_DB = MAIN_OS_VARIABLE.get('MONGO_DB')
MONGO_SERVICE_COLL = MAIN_OS_VARIABLE.get('MONGO_COLL')
PASS_KEY = MAIN_OS_VARIABLE.get('PASS_KEY')

MONGO_DB_OBJ = MongoClient(MONGO_URI)[MONGO_SERVICE_DB]

MONGO_DB_CONF_OBJ = MongoClient(MONGO_URI)["project_326__configuration"]

HOST_CONFIG = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'hostConfig'}).get('config')
APP_MONGO_COLLECTION = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'appMongoConfig'}).get('config')
