Esempio n. 1
0
def _validate_logging_config(config):
    """
    Validate the logging config before setting up a logger.
    """
    mandatory_keys = ['log_to', 'log_level', 'format']
    missing_keys = [key for key in mandatory_keys if key not in config]

    if missing_keys:
        raise ConfigError('Missing mandatory logging parameters: %r' %
                          ','.join(missing_keys))

    if config['log_to'] not in ('file', 'console'):
        raise ConfigError('logging.log_to=%r, expected one of file/console' %
                          config['log_to'])

    if config['log_to'] == 'file':
        mandatory_keys = ['log_dir', 'max_size', 'max_backups']
        missing_keys = []
        for key in mandatory_keys:
            if key not in config:
                missing_keys.append(key)

        if missing_keys:
            raise ConfigError(
                'When log_to=file, the following parameters are required: %r' %
                ','.join(missing_keys))
Esempio n. 2
0
    def __init__(self, config):
        super(S3Resolver, self).__init__(config)

        if 'cache_root' in self.config:
            self.cache_root = self.config['cache_root']
        else:
            message = 'Configuration error: Missing setting for cache_root.'
            logger.error(message)
            raise ConfigError(message)

        if 'source_root' in self.config:
            self.source_root = self.config['source_root']
        else:
            message = 'Configuration error: Missing setting for source_root.'
            logger.error(message)
            raise ConfigError(message)

        urlparts = urlparse(self.source_root)
        self.s3_bucket = urlparts.netloc
        self.prefix = urlparts.path

        if not urlparts.scheme == 's3':
            message = 'Configuration error: source_root is not an s3:// url.'
            logger.error(message)
            raise ConfigError(message)
Esempio n. 3
0
def _validate_color_profile_conversion_config(config):
    """
    Validate the config for setting up color profile conversion.
    """
    if not config.get('map_profile_to_srgb', False):
        return

    if config['map_profile_to_srgb'] and not config.get('srgb_profile_fp'):
        raise ConfigError(
            'When map_profile_to_srgb=True, you need to give the path to '
            'an sRGB color profile in the srgb_profile_fp setting.')

    if config['map_profile_to_srgb'] and not has_imagecms:
        raise ConfigError(
            'When map_profile_to_srgb=True, you need to install Pillow with '
            'LittleCMS support.  See http://www.littlecms.com/ for instructions.'
        )
Esempio n. 4
0
def get_debug_config(debug_jp2_transformer):
    # change a few things, read the config and set up logging
    project_dp = path.dirname(path.dirname(path.realpath(__file__)))
    config_file_path = path.join(project_dp, 'etc', 'loris2.conf')

    config = read_config(config_file_path)

    config['logging']['log_to'] = 'console'
    config['logging']['log_level'] = 'DEBUG'

    # override some stuff to look at relative or tmp directories.
    config['loris.Loris']['www_dp'] = path.join(project_dp, 'www')
    config['loris.Loris']['tmp_dp'] = '/tmp/loris/tmp'
    config['loris.Loris']['enable_caching'] = True
    config['img.ImageCache']['cache_dp'] = '/tmp/loris/cache/img'
    config['img_info.InfoCache']['cache_dp'] = '/tmp/loris/cache/info'
    config['resolver']['impl'] = 'loris.resolver.SimpleFSResolver'
    config['resolver']['src_img_root'] = path.join(project_dp, 'tests', 'img')
    config['transforms']['target_formats'] = [
        'jpg', 'png', 'gif', 'webp', 'tif'
    ]

    if debug_jp2_transformer == 'opj':
        from loris.transforms import OPJ_JP2Transformer
        config['transforms']['jp2']['impl'] = 'OPJ_JP2Transformer'
        opj_decompress = OPJ_JP2Transformer.local_opj_decompress_path()
        config['transforms']['jp2']['opj_decompress'] = path.join(
            project_dp, opj_decompress)
        libopenjp2_dir = OPJ_JP2Transformer.local_libopenjp2_dir()
        config['transforms']['jp2']['opj_libs'] = path.join(
            project_dp, libopenjp2_dir)
    elif debug_jp2_transformer == 'kdu':
        from loris.transforms import KakaduJP2Transformer
        config['transforms']['jp2']['impl'] = 'KakaduJP2Transformer'
        kdu_expand = KakaduJP2Transformer.local_kdu_expand_path()
        config['transforms']['jp2']['kdu_expand'] = path.join(
            project_dp, kdu_expand)
        libkdu_dir = KakaduJP2Transformer.local_libkdu_dir()
        config['transforms']['jp2']['kdu_libs'] = path.join(
            project_dp, libkdu_dir)
    else:
        raise ConfigError('Unrecognized debug JP2 transformer: %r' %
                          debug_jp2_transformer)

    config['authorizer'] = {'impl': 'loris.authorizer.RulesAuthorizer'}
    config['authorizer'][
        'cookie_secret'] = "4rakTQJDyhaYgoew802q78pNnsXR7ClvbYtAF1YC87o="
    config['authorizer'][
        'token_secret'] = "hyQijpEEe9z1OB9NOkHvmSA4lC1B4lu1n80bKNx0Uz0="
    config['authorizer']['roles_key'] = 'roles'
    config['authorizer']['id_key'] = 'sub'

    return config
Esempio n. 5
0
    def __init__(self, config):
        super().__init__(config)

        self.source_prefix = self.config.get('source_prefix', '')

        self.source_suffix = self.config.get('source_suffix', '')

        self.default_format = self.config.get('default_format', None)

        self.head_resolvable = self.config.get('head_resolvable', False)

        self.uri_resolvable = self.config.get('uri_resolvable', False)

        self.user = self.config.get('user', None)

        self.pw = self.config.get('pw', None)

        self.cert = self.config.get('cert', None)

        self.key = self.config.get('key', None)

        self.ssl_check = self.config.get('ssl_check', True)

        self._ident_regex_checker = IdentRegexChecker(
            ident_regex=self.config.get('ident_regex'))

        if 'cache_root' in self.config:
            self.cache_root = self.config['cache_root']
        else:
            message = 'Configuration incomplete and cannot resolve. Missing setting for cache_root.'
            raise ConfigError(message)

        if not self.uri_resolvable and self.source_prefix == '':
            message = 'Configuration incomplete and cannot resolve. Must either set uri_resolvable' \
                      ' or source_prefix settings.'
            raise ConfigError(message)
Esempio n. 6
0
    def __init__(self, app_configs={}):
        '''The WSGI Application.
        Args:
            app_configs ({}):
                A dictionary of dictionaries that represents the loris.conf
                file.
        '''
        self.app_configs = app_configs
        self.logger = configure_logging(app_configs['logging'])
        self.logger.debug('Loris initialized with these settings:')
        [
            self.logger.debug('%s.%s=%s', key, sub_key,
                              self.app_configs[key][sub_key])
            for key in self.app_configs for sub_key in self.app_configs[key]
        ]

        # make the loris.Loris configs attrs for easier access
        _loris_config = self.app_configs['loris.Loris']
        self.tmp_dp = _loris_config['tmp_dp']

        try:
            mkdir_p(self.tmp_dp)
        except Exception as exc:
            raise ConfigError("Error creating tmp_dp %s: %r" %
                              (self.tmp_dp, exc))

        self.www_dp = _loris_config['www_dp']
        self.enable_caching = _loris_config['enable_caching']
        self.redirect_canonical_image_request = _loris_config[
            'redirect_canonical_image_request']
        self.redirect_id_slash_to_info = _loris_config[
            'redirect_id_slash_to_info']
        self.proxy_path = _loris_config.get('proxy_path', None)
        self.cors_regex = _loris_config.get('cors_regex', None)
        if self.cors_regex:
            self.cors_regex = re.compile(self.cors_regex)

        self.transformers = self._load_transformers()
        self.resolver = self._load_resolver()
        self.authorizer = self._load_authorizer()
        self.max_size_above_full = _loris_config.get('max_size_above_full',
                                                     200)

        if self.enable_caching:
            self.info_cache = InfoCache(
                self.app_configs['img_info.InfoCache']['cache_dp'])
            cache_dp = self.app_configs['img.ImageCache']['cache_dp']
            self.img_cache = img.ImageCache(cache_dp)
Esempio n. 7
0
    def __init__(self, config):
        self.config = config
        if config:
            # check for previous settings
            if "use_extra_info" in self.config and "use_auth_rules" in self.config:
                raise ConfigError(
                    "You cannot set both use_extra_info and use_auth_rules. Please remove use_extra_info from your config."
                )

            if "use_extra_info" in self.config:
                warnings.warn(
                    "The use_extra_info field has been renamed to use_auth_rules and will be removed in a future version. Please update your config.",
                    DeprecationWarning)
                self.config["use_auth_rules"] = self.config["use_extra_info"]

            self.auth_rules_ext = self.config.get('auth_rules_ext',
                                                  'rules.json')
            self.use_auth_rules = self.config.get('use_auth_rules', False)