예제 #1
0
def create_pool(crypto_manager, engine_params):
    from zato.common.util import get_engine_url

    engine_params = copy.deepcopy(engine_params)
    if engine_params['engine'] != 'sqlite':
        engine_params['password'] = str(crypto_manager.decrypt(engine_params['password']))
        engine_params['extra']['pool_size'] = engine_params.pop('pool_size')

    engine = create_engine(get_engine_url(engine_params), **engine_params['extra'])
    engine.execute(ping_queries[engine_params['engine']])

    Session = sessionmaker()
    Session.configure(bind=engine)
    session = Session()

    return session
예제 #2
0
파일: sql.py 프로젝트: viatoriche/zato
    def __init__(self, name, config, config_no_sensitive):
        self.logger = getLogger(self.__class__.__name__)

        self.name = name
        self.config = config
        self.engine_name = config["engine"]  # self.engine.name is 'mysql' while 'self.engine_name' is mysql+pymysql

        # Safe for printing out to logs, any sensitive data has been shadowed
        self.config_no_sensitive = config_no_sensitive

        _extra = {}

        # MySQL only
        if self.engine_name.startswith("mysql"):
            _extra["pool_recycle"] = 600

        # Postgres-only
        elif self.engine_name.startswith("postgres"):
            _extra["connect_args"] = {"application_name": get_component_name()}

        extra = self.config.get("extra")  # Optional, hence .get
        _extra.update(parse_extra_into_dict(extra))

        # SQLite has no pools
        if self.engine_name != "sqlite":
            _extra["pool_size"] = int(config.get("pool_size", 1))
            if _extra["pool_size"] == 0:
                _extra["poolclass"] = NullPool

        engine_url = get_engine_url(config)
        self.engine = create_engine(engine_url, **_extra)

        event.listen(self.engine, "checkin", self.on_checkin)
        event.listen(self.engine, "checkout", self.on_checkout)
        event.listen(self.engine, "connect", self.on_connect)
        event.listen(self.engine, "first_connect", self.on_first_connect)
예제 #3
0
    db_data['db_type'] = db_type

    # Crypto
    ssl_key_file = os.path.abspath(os.path.join(config_dir, SSL_KEY_FILE))
    ssl_cert_file = os.path.abspath(os.path.join(config_dir, SSL_CERT_FILE))
    ssl_ca_certs = os.path.abspath(os.path.join(config_dir, SSL_CA_CERTS))

    # ODB SQLAlchemy setup
    SASession = scoped_session(sessionmaker())

    kwargs = {}

    if db_data['db_type'] == 'mysql':
        kwargs['pool_recycle'] = 600

    engine = create_engine(get_engine_url(db_data), **kwargs)
    SASession.configure(bind=engine)

    # Settings DB
    _settings_db_path = os.path.join(config_dir, 'config', 'repo',
                                     'settings.db')
    _settings_db_session = scoped_session(sessionmaker())
    _settings_db_engine = create_engine(
        'sqlite:///{}'.format(_settings_db_path))
    _settings_db_session.configure(bind=_settings_db_engine)

    settings_db = SettingsDB(_settings_db_path, _settings_db_session)

else:
    ADMIN_INVOKE_NAME = 'dummy'
    ADMIN_INVOKE_PASSWORD = '******'
예제 #4
0
 def _get_engine(self, args):
     connect_args = {
         'application_name': util.get_component_name('enmasse')
     } if args.odb_type == 'postgresql' else {}
     return sqlalchemy.create_engine(get_engine_url(args),
                                     connect_args=connect_args)
예제 #5
0
        'ENGINE'] = 'django.db.backends.' + django_sqlalchemy_engine[db_type]

    for name in ('ENGINE', 'NAME', 'USER', 'PASSWORD', 'HOST', 'PORT'):
        globals()['DATABASE_{}'.format(name)] = DATABASES['default'][name]

    db_data['db_type'] = db_type

    # Crypto
    ssl_key_file = os.path.abspath(os.path.join(config_dir, SSL_KEY_FILE))
    ssl_cert_file = os.path.abspath(os.path.join(config_dir, SSL_CERT_FILE))
    ssl_ca_certs = os.path.abspath(os.path.join(config_dir, SSL_CA_CERTS))

    # SQLAlchemy setup
    SASession = scoped_session(sessionmaker())
    engine = create_engine(
        get_engine_url(db_data),
        **{'pool_recycle': 600} if db_data['db_type'] == 'mysql' else {})
    SASession.configure(bind=engine)

    TEMPLATE_DEBUG = True
else:
    ADMIN_INVOKE_NAME = 'dummy'
    ADMIN_INVOKE_PASSWORD = '******'
    DATABASES = {}
    DATABASES['default'] = {}
    DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'

    ssl_key_file = 'dummy'
    ssl_cert_file = 'dummy'
    ssl_ca_certs = 'dummy'
예제 #6
0
    db_data['db_type'] = db_type

    # Crypto
    ssl_key_file = os.path.abspath(os.path.join(config_dir, SSL_KEY_FILE))
    ssl_cert_file = os.path.abspath(os.path.join(config_dir, SSL_CERT_FILE))
    ssl_ca_certs = os.path.abspath(os.path.join(config_dir, SSL_CA_CERTS))

    # SQLAlchemy setup
    SASession = scoped_session(sessionmaker())

    kwargs = {}

    if db_data['db_type'] == 'mysql':
        kwargs['pool_recycle'] = 600

    engine = create_engine(get_engine_url(db_data), **kwargs)
    SASession.configure(bind=engine)

else:
    ADMIN_INVOKE_NAME = 'dummy'
    ADMIN_INVOKE_PASSWORD = '******'
    DATABASES = {}
    DATABASES['default'] = {}
    DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'

    ssl_key_file = 'dummy'
    ssl_cert_file = 'dummy'
    ssl_ca_certs = 'dummy'

    os.environ['DJANGO_SETTINGS_MODULE'] = 'zato.admin.settings'
예제 #7
0
파일: __init__.py 프로젝트: catroot/zato
 def _get_engine(self, args):
     connect_args = {'application_name':util.get_component_name('enmasse')} if args.odb_type == 'postgresql' else {}
     return sqlalchemy.create_engine(get_engine_url(args), connect_args=connect_args)
예제 #8
0
 def _get_engine(self, args):
     connect_args = {"application_name": util.get_component_name("enmasse")} if args.odb_type == "postgresql" else {}
     return sqlalchemy.create_engine(get_engine_url(args), connect_args=connect_args)
예제 #9
0
    db_data = DATABASES['default']
    db_data['ENGINE'] = 'django.db.backends.' + django_sqlalchemy_engine[db_type]
    
    for name in('ENGINE', 'NAME', 'USER', 'PASSWORD', 'HOST', 'PORT'):
        globals()['DATABASE_{}'.format(name)] = DATABASES['default'][name]

    db_data['db_type'] = db_type

    # Crypto
    ssl_key_file = os.path.abspath(os.path.join(config_dir, SSL_KEY_FILE))
    ssl_cert_file = os.path.abspath(os.path.join(config_dir, SSL_CERT_FILE))
    ssl_ca_certs = os.path.abspath(os.path.join(config_dir, SSL_CA_CERTS))

    # SQLAlchemy setup
    SASession = scoped_session(sessionmaker())
    engine = create_engine(get_engine_url(db_data), **{'pool_recycle':600} if db_data['db_type'] == 'mysql' else {})
    SASession.configure(bind=engine)
    
    TEMPLATE_DEBUG = True
else:
    ADMIN_INVOKE_NAME = 'dummy'
    ADMIN_INVOKE_PASSWORD = '******'
    DATABASES = {}
    DATABASES['default'] = {}
    DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'
    
    ssl_key_file = 'dummy'
    ssl_cert_file = 'dummy'
    ssl_ca_certs = 'dummy'
    
    os.environ['DJANGO_SETTINGS_MODULE'] = 'zato.admin.settings'
예제 #10
0
파일: settings.py 프로젝트: junneyang/zato
    db_data = DATABASES['default']
    db_data['ENGINE'] = 'django.db.backends.' + django_sqlalchemy_engine[db_type]

    for name in('ENGINE', 'NAME', 'USER', 'PASSWORD', 'HOST', 'PORT'):
        globals()['DATABASE_{}'.format(name)] = DATABASES['default'][name]

    db_data['db_type'] = db_type

    # Crypto
    ssl_key_file = os.path.abspath(os.path.join(config_dir, SSL_KEY_FILE))
    ssl_cert_file = os.path.abspath(os.path.join(config_dir, SSL_CERT_FILE))
    ssl_ca_certs = os.path.abspath(os.path.join(config_dir, SSL_CA_CERTS))

    # SQLAlchemy setup
    SASession = scoped_session(sessionmaker())
    engine = create_engine(get_engine_url(db_data), **{'pool_recycle':600} if db_data['db_type'] == 'mysql' else {})
    SASession.configure(bind=engine)

    TEMPLATE_DEBUG = True
else:
    ADMIN_INVOKE_NAME = 'dummy'
    ADMIN_INVOKE_PASSWORD = '******'
    DATABASES = {}
    DATABASES['default'] = {}
    DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'

    ssl_key_file = 'dummy'
    ssl_cert_file = 'dummy'
    ssl_ca_certs = 'dummy'

    os.environ['DJANGO_SETTINGS_MODULE'] = 'zato.admin.settings'