Example #1
0
def init_db(db_conn_str, debug=False):
    """This function is used for init db connection object by conn_str
    including mongodb/mysql/hive.
    """
    db_dict = {}
    if db_conn_str.startswith('mysql://'):
        db_dict['type'] = 'mysql'
        db_orm = ArmoryOrm()
        db_orm.init_conf({'DEBUG': debug, 'db': db_conn_str})
        db_dict['obj'] = db_orm
    elif db_conn_str.startswith('mongodb://'):
        db_dict['type'] = 'mongo'
        # here we construct route name by `host`-`port`-`db`
        # and inspect mongo conn string
        db_route = create_mongo_route(db_conn_str)
        ArmoryMongo.init_conf({db_route: db_conn_str})
        db_dict['obj'] = db_route
    elif db_conn_str.startswith('hive://'):
        db_dict['type'] = 'hive'
        hive_orm = ArmoryHive(db_conn_str)
        hive_orm.hiveOpen()
        db_dict['obj'] = hive_orm
    else:
        # here we can add other db obj later
        db_dict['type'] = 'unknown'
        db_dict['obj'] = None

    return db_dict
Example #2
0
from armory.tank.mongo import ArmoryMongo
from cm_console.settings import MODELS
from cm_console.model.base import ModelBase
from cm_console.api import app

Model_Dict = {}
ArmoryMongo.init_app(app)

for key in MODELS:
    attrs = MODELS[key]
    Model_Dict[key] = type(str(key), (ModelBase,), attrs)
Example #3
0
from armory.tank.mongo import ArmoryMongo
from auth_service.settings import MONGO_CONFIG

ArmoryMongo.init_conf(MONGO_CONFIG)