Beispiel #1
0
 def test_use_hardlinks_config(self):
     """
     Test that hardlinks are disabled by default and can be overridden.
     """
     BiomajConfig.load_config(self.utils.global_properties,
                              allow_user_config=False)
     # Must be disabled in local.properties
     config = BiomajConfig('local')
     self.assertFalse(config.get_bool("use_hardlinks"))
     # Must be enabled for hardlinks.properties (override)
     config = BiomajConfig('hardlinks')
     self.assertTrue(config.get_bool("use_hardlinks"))
     # Reload file with use_hardlinks=1
     BiomajConfig.load_config(self.utils.global_properties_hl,
                              allow_user_config=False)
     config = BiomajConfig('local')
     self.assertTrue(config.get_bool("use_hardlinks"))
Beispiel #2
0
def biomaj_daemon():
    '''
    Execute a command request (bank update, removal, ...)
    '''
    apikey = request.headers.get('Authorization')
    token = None

    if apikey:
        bearer = apikey.split()
        if bearer[0] == 'APIKEY':
            token = bearer[1]
    try:
        params = request.get_json()
        options = params['options']
        options_object = Options(options)
        options_object.token = token
        options_object.user = None
        options_object.redis_host = config['redis']['host']
        options_object.redis_port = config['redis']['port']
        options_object.redis_db = config['redis']['db']
        options_object.redis_prefix = config['redis']['prefix']

        user = None
        if token:
            proxy = Utils.get_service_endpoint(config, 'user')
            r = requests.get(proxy + '/api/user/info/apikey/' + token)
            if not r.status_code == 200:
                abort(404, {'message': 'Invalid API Key or connection issue'})
            user = r.json()['user']
            if user:
                options_object.user = user['id']

        if options_object.maintenance in ['on', 'off']:
            if not options_object.user or 'admin' not in config[
                    'biomaj'] or options_object.user not in config['biomaj'][
                        'admin']:
                abort(401, {
                    'message':
                    'This action requires authentication with api key'
                })

        if options_object.bank:
            bmaj_options = BmajOptions(options_object)
            BiomajConfig(options_object.bank, bmaj_options)

            if not options_object.search and not options_object.show and not options_object.check and not options_object.status:
                if not user:
                    abort(
                        401, {
                            'message':
                            'This action requires authentication with api key'
                        })

        (res, msg) = biomaj_client_action(options_object, config)
    except Exception as e:
        logging.exception(e)
        return jsonify({'status': False, 'msg': str(e)})
    return jsonify({'status': res, 'msg': msg})
Beispiel #3
0
 def tearDown(self):
     # Delete lock files
     for bank_name in self.BANKS:
         config = BiomajConfig(bank_name)
         data_dir = config.get('data.dir')
         lock_file = os.path.join(data_dir, 'local.lock')
         if os.path.exists(lock_file):
             os.remove(lock_file)
     self.utils.clean()
Beispiel #4
0
 def test_properties_override(self):
     BiomajConfig.load_config(self.utils.global_properties,
                              allow_user_config=False)
     config = BiomajConfig('local')
     ldap_host = config.get('ldap.host')
     self.assertTrue(ldap_host == 'localhost')
     os.environ['BIOMAJ_LDAP_HOST'] = 'someserver'
     ldap_host = config.get('ldap.host')
     self.assertTrue(ldap_host == 'someserver')
Beispiel #5
0
 def test_check_method(self):
     """Check .name, .exe and .args are well check during bank configuration
     checking"""
     BiomajConfig.load_config(self.utils.global_properties)
     for conf in [
             'noname', 'noexe', 'noargs', 'prenoname', 'prenoexe',
             'prenoargs', 'rmnoname', 'rmnoexe', 'rmnoargs'
     ]:
         config = BiomajConfig(conf)
         self.assertFalse(config.check())
Beispiel #6
0
 def setUp(self):
     self.utils = UtilsForTest()
     BiomajConfig.load_config(self.utils.global_properties,
                              allow_user_config=False)
     self.config = BiomajConfig('testhttp')
     self.http_parse = HTTPParse(
         self.config.get('http.parse.dir.line'),
         self.config.get('http.parse.file.line'),
         int(self.config.get('http.group.dir.name')),
         int(self.config.get('http.group.dir.date')),
         int(self.config.get('http.group.file.name')),
         int(self.config.get('http.group.file.date')),
         self.config.get('http.group.file.date_format', None),
         int(self.config.get('http.group.file.size')))
Beispiel #7
0
    def setUp(self):
        self.utils = UtilsForTest()
        curdir = os.path.dirname(os.path.realpath(__file__))
        BiomajConfig.load_config(self.utils.global_properties,
                                 allow_user_config=False)

        # Delete all banks
        b = Bank('alu')
        b.banks.remove({})

        self.config = BiomajConfig('alu')
        data_dir = self.config.get('data.dir')
        lock_file = os.path.join(data_dir, 'alu.lock')
        if os.path.exists(lock_file):
            os.remove(lock_file)
Beispiel #8
0
    def setUp(self):
        self.utils = UtilsForTest()
        BiomajConfig.load_config(self.utils.global_properties,
                                 allow_user_config=False)

        # Clean banks used in tests
        for bank_name in self.BANKS:
            # Delete all releases
            b = Bank(bank_name)
            b.banks.remove({})
            # Delete lock files
            config = BiomajConfig(bank_name)
            data_dir = config.get('data.dir')
            lock_file = os.path.join(data_dir, 'local.lock')
            if os.path.exists(lock_file):
                os.remove(lock_file)
Beispiel #9
0
def biomaj_daemon():
    '''
    List users
    '''
    apikey = request.headers.get('Authorization')
    token = None

    if apikey:
        bearer = apikey.split()
        if bearer[0] == 'APIKEY':
            token = bearer[1]
    try:
        params = request.get_json()
        options = params['options']
        options_object = Options(options)
        options_object.token = token
        options_object.user = None
        options_object.redis_host = config['redis']['host']
        options_object.redis_port = config['redis']['port']
        options_object.redis_db = config['redis']['db']
        options_object.redis_prefix = config['redis']['prefix']

        user = None
        if token:
            r = requests.get(config['web']['local_endpoint'] + '/api/user/info/apikey/' + token)
            if not r.status_code == 200:
                abort(404, {'message': 'Invalid API Key or connection issue'})
            user = r.json()['user']
            if user:
                options_object.user = user['id']

        if options_object.bank:
            bmaj_options = BmajOptions(options_object)
            BiomajConfig(options_object.bank, bmaj_options)

            if not options_object.search and not options_object.show and not options_object.check and not options_object.status:
                if not user:
                    abort(403, {'message': 'This action requires authentication with api key'})

        (res, msg) = biomaj_client_action(options_object)
    except Exception as e:
        logging.exception(e)
        return jsonify({'status': False, 'msg': str(e)})
    return jsonify({'status': res, 'msg': msg})
Beispiel #10
0
    def setUp(self):
        BmajIndex.es = None
        self.utils = UtilsForTest()
        curdir = os.path.dirname(os.path.realpath(__file__))
        BiomajConfig.load_config(self.utils.global_properties,
                                 allow_user_config=False)
        if BmajIndex.do_index == False:
            self.skipTest(
                "Skipping indexing tests due to elasticsearch not available")
        # Delete all banks
        b = Bank('local')
        b.banks.remove({})
        BmajIndex.delete_all_bank('local')

        self.config = BiomajConfig('local')
        data_dir = self.config.get('data.dir')
        lock_file = os.path.join(data_dir, 'local.lock')
        if os.path.exists(lock_file):
            os.remove(lock_file)