Exemplo n.º 1
0
    def load_and_validate_config_files(self):
        config_files = [
            self.get_server_config_path(),
            self.get_version_path(),
            self.get_hosts_config_path(),
            self.get_host_access_control_config_path(),
            get_irods_environment_path()
        ]
        if os.path.exists(self.get_database_config_path()):
            config_files.append(self.get_database_config_path())

        config_dicts = dict([(path, load_json_config_file(path))
                             for path in config_files])

        try:
            server_config_dict = config_dicts[self.get_server_config_path()]
            base_uri = server_config_dict['schema_validation_base_uri']
        except KeyError:
            base_uri = None
            if self.verbose:
                print('{0} did not contain \'{1}\''.format(
                    self.get_server_config_path(),
                    'schema_validation_base_uri'),
                      file=sys.stderr)

        try:
            version_dict = config_dicts[self.get_version_path()]
            uri_version = version_dict['configuration_schema_version']
        except KeyError:
            uri_version = None
            if self.verbose:
                print('{0} did not contain \'{1}\''.format(
                    self.get_version_path(), 'configuration_schema_version'),
                      file=sys.stderr)

        if base_uri and uri_version:
            validation_uri_prefix = '/'.join(
                [base_uri, 'v{0}'.format(uri_version)])

            for path, json_dict in config_dicts.items():
                schema_uri = '/'.join(
                    [validation_uri_prefix,
                     os.path.basename(path)])
                try:
                    validate_json.validate_dict(json_dict,
                                                schema_uri,
                                                name=path,
                                                verbose=self.verbose)
                except validate_json.ValidationWarning as e:
                    if self.verbose:
                        print(e, file=sys.stderr)
                except validate_json.ValidationError as e:
                    irods_six.reraise(IrodsControllerError, e,
                                      sys.exc_info()[2])
        elif self.verbose:
            print('Preflight Check problem:',
                  'JSON Configuration Validation failed.',
                  sep='\n\t',
                  file=sys.stderr)
        return config_dicts
Exemplo n.º 2
0
    def load_and_validate_config_files(self):
        config_files = [
                self.get_server_config_path(),
                self.get_version_path(),
                self.get_hosts_config_path(),
                self.get_host_access_control_config_path(),
                get_irods_environment_path()]
        if os.path.exists(self.get_database_config_path()):
            config_files.append(self.get_database_config_path())

        config_dicts = dict([(path, load_json_config_file(path)) for path in config_files])

        try :
            server_config_dict = config_dicts[self.get_server_config_path()]
            base_uri = server_config_dict['schema_validation_base_uri']
        except KeyError:
            base_uri = None
            if self.verbose:
                print(  '{0} did not contain \'{1}\''.format(
                    self.get_server_config_path(),
                    'schema_validation_base_uri'),
                    file=sys.stderr)

        try :
            version_dict = config_dicts[self.get_version_path()]
            uri_version = version_dict['configuration_schema_version']
        except KeyError:
            uri_version = None
            if self.verbose:
                print(  '{0} did not contain \'{1}\''.format(
                    self.get_version_path(),
                    'configuration_schema_version'),
                    file=sys.stderr)

        if base_uri and uri_version:
            validation_uri_prefix = '/'.join([
                    base_uri,
                    'v{0}'.format(uri_version)])

            for path, json_dict in config_dicts.items():
                schema_uri = '/'.join([
                    validation_uri_prefix,
                    os.path.basename(path)])
                try :
                    validate_json.validate_dict(
                            json_dict,
                            schema_uri,
                            name=path,
                            verbose=self.verbose)
                except validate_json.ValidationWarning as e:
                    if self.verbose:
                        print(e, file=sys.stderr)
                except validate_json.ValidationError as e:
                    irods_six.reraise(IrodsControllerError, e, sys.exc_info()[2])
        elif self.verbose:
            print(  'Preflight Check problem:',
                    'JSON Configuration Validation failed.',
                    sep='\n\t', file=sys.stderr)
        return config_dicts
Exemplo n.º 3
0
    def load_and_validate_config_files(self,
                                       execution_environment=None,
                                       insert_behavior=True):
        l = logging.getLogger(__name__)
        config_files = [
            self.get_server_config_path(),
            self.get_version_path(),
            self.get_hosts_config_path(),
            self.get_host_access_control_config_path()
        ]
        if os.path.exists(self.get_database_config_path()):
            config_files.append(self.get_database_config_path())
        else:
            l.debug('The database config file, \'%s\', does not exist.',
                    self.get_database_config_path())

        config_dicts = {}
        for path in config_files:
            l.debug('Loading %s into dictionary', path)
            config_dicts[path] = load_json_config_file(path)

        if execution_environment is not None and 'IRODS_ENVIRONMENT_FILE' in execution_environment:
            irods_environment_path = execution_environment[
                'IRODS_ENVIRONMENT_FILE']
        elif insert_behavior and 'environment_variables' in config_dicts[
                self.get_server_config_path(
                )] and 'IRODS_ENVIRONMENT_FILE' in config_dicts[
                    self.get_server_config_path()]['environment_variables']:
            irods_environment_path = config_dicts[self.get_server_config_path(
            )]['environment_variables']['IRODS_ENVIRONMENT_FILE']
        else:
            irods_environment_path = get_irods_environment_path()

        l.debug('Loading %s into dictionary', irods_environment_path)
        config_dicts[irods_environment_path] = load_json_config_file(
            irods_environment_path)

        l.debug('Attempting to construct schema URI...')
        try:
            server_config_dict = config_dicts[self.get_server_config_path()]
            key = 'schema_validation_base_uri'
            base_uri = server_config_dict[key]
        except KeyError:
            base_uri = None
            l.warning('%s did not contain \'%s\'',
                      self.get_server_config_path(), key)

        try:
            version_dict = config_dicts[self.get_version_path()]
            key = 'configuration_schema_version'
            uri_version = version_dict[key]
        except KeyError:
            uri_version = None
            l.warning('%s did not contain \'%s\'', self.get_version_path(),
                      key)

        if base_uri and uri_version:
            validation_uri_prefix = '/'.join(
                [base_uri, 'v{0}'.format(uri_version)])
            l.debug('Successfully constructed schema URI.')

            for path in config_files:
                json_dict = config_dicts[path]
                schema_uri = '/'.join(
                    [validation_uri_prefix,
                     os.path.basename(path)])
                l.debug('Attempting to validate %s against %s', path,
                        schema_uri)
                try:
                    validate_json.validate_dict(json_dict,
                                                schema_uri,
                                                name=path)
                except validate_json.ValidationWarning as e:
                    l.warning('Error encountered in validate_json',
                              exc_info=True)
                except validate_json.ValidationError as e:
                    irods_six.reraise(IrodsControllerError, e,
                                      sys.exc_info()[2])

            json_dict = config_dicts[irods_environment_path]
            schema_uri = '/'.join([
                validation_uri_prefix,
                os.path.basename(get_irods_environment_path())
            ])
            l.debug('Attempting to validate %s against %s',
                    irods_environment_path, schema_uri)
            try:
                validate_json.validate_dict(json_dict,
                                            schema_uri,
                                            name=irods_environment_path)
            except validate_json.ValidationWarning as e:
                l.warning('Error encountered in validate_json', exc_info=True)
            except validate_json.ValidationError as e:
                irods_six.reraise(IrodsControllerError, e, sys.exc_info()[2])

        else:
            l.debug('Failed to construct schema URI')
            l.warning('%s\n%s', 'Preflight Check problem:',
                      indent('JSON Configuration Validation failed.'))
        return config_dicts
Exemplo n.º 4
0
    def load_and_validate_config_files(self, execution_environment=None, insert_behavior=True):
        l = logging.getLogger(__name__)
        config_files = [
                self.get_server_config_path(),
                self.get_version_path(),
                self.get_hosts_config_path(),
                self.get_host_access_control_config_path()]
        if os.path.exists(self.get_database_config_path()):
            config_files.append(self.get_database_config_path())
        else:
            l.debug('The database config file, \'%s\', does not exist.', self.get_database_config_path())

        config_dicts = {}
        for path in config_files:
            l.debug('Loading %s into dictionary', path)
            config_dicts[path] = load_json_config_file(path)

        if execution_environment is not None and 'IRODS_ENVIRONMENT_FILE' in execution_environment:
            irods_environment_path = execution_environment['IRODS_ENVIRONMENT_FILE']
        elif insert_behavior and 'environment_variables' in config_dicts[self.get_server_config_path()] and 'IRODS_ENVIRONMENT_FILE' in config_dicts[self.get_server_config_path()]['environment_variables']:
            irods_environment_path = config_dicts[self.get_server_config_path()]['environment_variables']['IRODS_ENVIRONMENT_FILE']
        else:
            irods_environment_path = get_irods_environment_path()

        l.debug('Loading %s into dictionary', irods_environment_path)
        config_dicts[irods_environment_path] = load_json_config_file(irods_environment_path)

        l.debug('Attempting to construct schema URI...')
        try :
            server_config_dict = config_dicts[self.get_server_config_path()]
            key = 'schema_validation_base_uri'
            base_uri = server_config_dict[key]
        except KeyError:
            base_uri = None
            l.warning('%s did not contain \'%s\'',
                self.get_server_config_path(), key)

        try :
            version_dict = config_dicts[self.get_version_path()]
            key = 'configuration_schema_version'
            uri_version = version_dict[key]
        except KeyError:
            uri_version = None
            l.warning('%s did not contain \'%s\'',
                self.get_version_path(), key)

        if base_uri and uri_version:
            validation_uri_prefix = '/'.join([
                    base_uri,
                    'v{0}'.format(uri_version)])
            l.debug('Successfully constructed schema URI.')

            for path in config_files:
                json_dict = config_dicts[path]
                schema_uri = '/'.join([
                    validation_uri_prefix,
                    os.path.basename(path)])
                l.debug('Attempting to validate %s against %s', path, schema_uri)
                try :
                    validate_json.validate_dict(
                            json_dict,
                            schema_uri,
                            name=path)
                except validate_json.ValidationWarning as e:
                    l.warning('Error encountered in validate_json', exc_info=True)
                except validate_json.ValidationError as e:
                    irods_six.reraise(IrodsControllerError, e, sys.exc_info()[2])

            json_dict = config_dicts[irods_environment_path]
            schema_uri = '/'.join([
                validation_uri_prefix,
                os.path.basename(get_irods_environment_path())])
            l.debug('Attempting to validate %s against %s', irods_environment_path, schema_uri)
            try :
                validate_json.validate_dict(
                        json_dict,
                        schema_uri,
                        name=irods_environment_path)
            except validate_json.ValidationWarning as e:
                l.warning('Error encountered in validate_json', exc_info=True)
            except validate_json.ValidationError as e:
                irods_six.reraise(IrodsControllerError, e, sys.exc_info()[2])

        else:
            l.debug('Failed to construct schema URI')
            l.warning('%s\n%s',
                'Preflight Check problem:',
                indent('JSON Configuration Validation failed.'))
        return config_dicts