Esempio n. 1
0
def test_instantiation_hosts_error_on_query():
    '''explicitly doing queries will raise error'''
    tmpDir = mkdtemp(prefix=FSDB_PATH_PREFIX)
    conf = {'ES_INDEXNAME': TEST_ES_INDEX,
            'ES_HOSTS': "127.0.0.1:12345",
            'FSDB_PATH': tmpDir}
    try:
        arc = Archivant(conf)
        arc.get_volume('whatever')
    finally:
        cleanup(tmpDir=tmpDir)
Esempio n. 2
0
    def __init__(self, import_name, conf={}):
        super(LibreantCoreApp, self).__init__(import_name)
        defaults = {
            'PRESET_PATHS': [],  # defaultPreset should be loaded as default?
            'FSDB_PATH': "",
            'SECRET_KEY': 'really insecure, please change me!',
            'ES_HOSTS': None,
            'ES_INDEXNAME': 'libreant',
            'USERS_DATABASE': "",
            'PWD_ROUNDS': None,
            'PWD_SALT_SIZE': None
        }
        defaults.update(conf)
        self.config.update(defaults)

        '''dirty trick: prevent default flask handler to be created
           in flask version > 0.10.1 will be a nicer way to disable default loggers
           tanks to this new code mitsuhiko/flask@84ad89ffa4390d3327b4d35983dbb4d84293b8e2
        '''
        self._logger = getLogger(self.import_name)

        self.archivant = Archivant(conf={k: self.config[k] for k in ('FSDB_PATH', 'ES_HOSTS', 'ES_INDEXNAME')})
        self.presetManager = PresetManager(self.config['PRESET_PATHS'])

        if self.config['USERS_DATABASE']:
            self.usersDB = users.init_db(self.config['USERS_DATABASE'],
                                         pwd_salt_size=self.config['PWD_SALT_SIZE'],
                                         pwd_rounds=self.config['PWD_ROUNDS'])
            users.populate_with_defaults()
        else:
            self.logger.warning("""It has not been set any value for 'USERS_DATABASE', \
all operations about users will be unsupported. Are all admins.""")
            self.usersDB = None
Esempio n. 3
0
def libreant_db(debug, settings, fsdb_path, es_indexname, es_hosts):
    initLoggers(logNames=['config_utils'])
    global conf
    conf = get_def_conf()
    conf.update(load_cfg(settings, debug=debug))
    cliConf = {}
    if debug:
        cliConf['DEBUG'] = True
    if fsdb_path:
        cliConf['FSDB_PATH'] = fsdb_path
    if es_indexname:
        cliConf['ES_INDEXNAME'] = es_indexname
    if es_hosts:
        cliConf['ES_HOSTS'] = es_hosts
    conf.update(cliConf)
    initLoggers(logging.DEBUG if conf.get('DEBUG', False) else logging.INFO)

    try:
        global arc
        arc = Archivant(conf=conf)
    except Exception as e:
        if conf.get('DEBUG', False):
            raise
        else:
            die(str(e))
Esempio n. 4
0
def test_instantiation_no_indexname():
    tmpDir = mkdtemp(prefix=FSDB_PATH_PREFIX)
    conf = {'FSDB_PATH': tmpDir}
    try:
        Archivant(conf)
    finally:
        cleanup(tmpDir=tmpDir)
Esempio n. 5
0
def test_instantiation_hosts_error():
    '''this should not raise errors'''
    tmpDir = mkdtemp(prefix=FSDB_PATH_PREFIX)
    conf = {'ES_INDEXNAME': TEST_ES_INDEX,
            'ES_HOSTS': "127.0.0.1:12345",
            'FSDB_PATH': tmpDir}
    try:
        Archivant(conf)
    finally:
        cleanup(tmpDir=tmpDir)
Esempio n. 6
0
 def setUp(self):
     self.tmpDir = mkdtemp(prefix=self.FSDB_PATH_PREFIX)
     conf = {'ES_INDEXNAME': self.TEST_ES_INDEX, 'FSDB_PATH': self.tmpDir}
     self.arc = Archivant(conf)
Esempio n. 7
0
def test_instantiation_no_fsdb():
    conf = {'ES_INDEXNAME': TEST_ES_INDEX}
    arc = Archivant(conf)
    arc._fsdb
Esempio n. 8
0
def test_instantiation_ok():
    tmpDir = mkdtemp(prefix=FSDB_PATH_PREFIX)
    conf = {'ES_INDEXNAME': TEST_ES_INDEX,
            'FSDB_PATH': tmpDir}
    Archivant(conf)
    cleanup(esIndex=TEST_ES_INDEX, tmpDir=tmpDir)