Esempio n. 1
0
def load_access_policies() -> Optional[Mapping[str, List[ServerFilter]]]:
    """ Create filter list
    """
    if not confservice.getboolean('server', 'enable_filters'):
        return None

    confservice.set('server', 'access_policy_version', '2')

    import pyqgisservercontrib.core.componentmanager as cm

    collection = []
    cm.register_entrypoints('qgssrv_contrib_access_policy', collection)

    if not collection:
        return None

    # Retrieve filters
    filters = {"": []}
    for filt in collection:
        uri = filt.uri or ""
        fls = filters.get(uri, [])
        fls.append(filt)
        filters[uri] = fls
    # Sort filters
    for flist in filters.values():
        flist.sort(key=lambda f: f.pri, reverse=True)
    return filters
Esempio n. 2
0
def load_filters(
        base_uri: str,
        appfilters: List[ServerFilter] = None
) -> Mapping[str, List[ServerFilter]]:
    """ Load filters and return a Mapping
    """
    import pyqgisservercontrib.core.componentmanager as cm

    filters = {base_uri: []}

    def _add_filter(afilter):
        uri = os.path.join(base_uri, afilter.uri)
        fls = filters.get(uri, [])
        fls.append(afilter)
        filters[uri] = fls

    if appfilters:
        for flt in appfilters:
            _add_filter(flt)

    collection = []
    cm.register_entrypoints('qgssrv_contrib_access_policy',
                            collection,
                            wpspolicy=True)

    for flt in collection:
        _add_filter(flt)

    # Sort filters
    for flist in filters.values():
        flist.sort(key=lambda f: f.pri, reverse=True)
    return filters
Esempio n. 3
0
def load_access_policies(base_uri: str) -> Mapping[str, List[ServerFilter]]:
    """ Create filter list
    """
    import pyqgisservercontrib.core.componentmanager as cm

    collection = []
    cm.register_entrypoints('qgssrv_contrib_access_policy', collection)

    # Retrieve collection
    filters = {base_uri: []}
    for filt in collection:
        uri = os.path.join(base_uri, filt.uri)
        fls = filters.get(uri, [])
        fls.append(filt)
        filters[uri] = fls
    # Sort filters
    for flist in filters.values():
        flist.sort(key=lambda f: f.pri, reverse=True)
    return filters
Esempio n. 4
0
    def __init__(self) -> None:
        """ Initialize cache

            :param size: size of the lru cache
        """
        cnf = confservice['projects.cache']

        size = cnf.getint('size')

        self._create_project = QgsProject
        self._cache = lrucache(size)
        self._strict_check = cnf.getboolean('strict_check')
        self._aliases = {}
        self._default_scheme = cnf.get('default_handler',fallback='file')

        # Set the base url for file protocol
        self._aliases['file'] = 'file:///%s/' % cnf.get('rootdir').strip('/')

        # Load protocol handlers
        componentmanager.register_entrypoints('qgssrv_contrib_protocol_handler')
Esempio n. 5
0
    def __init__(self) -> None:
        """ Initialize cache

            :param size: size of the lru cache
        """
        cnf = confservice['projects.cache']

        size = cnf.getint('size')

        self._create_project = QgsProject
        self._lru_cache = lrucache(size)
        self._static_cache = OrderedDict()
        self._strict_check = cnf.getboolean('strict_check')
        self._trust_layer_metadata = cnf.getboolean('trust_layer_metadata')
        self._disable_getprint = cnf.getboolean('disable_getprint')
        self._disable_owsurls = cnf.getboolean('disable_owsurls',
                                               fallback=False)
        self._aliases = {}
        self._default_scheme = cnf.get('default_handler')
        self._observers = []

        allowed_schemes = cnf.get('allow_storage_schemes')
        if allowed_schemes != '*':
            allowed_schemes = [s.strip() for s in allowed_schemes.split(',')]
        self._allowed_schemes = allowed_schemes

        # Set the base url for file protocol
        self._aliases['file'] = 'file:///%s/' % cnf.get('rootdir').strip('/')

        if self._disable_getprint:
            LOGGER.info("** Cache: Getprint disabled")

        if self._trust_layer_metadata:
            LOGGER.info("** Cache: Trust Layer Metadata on")

        # Load protocol handlers
        componentmanager.register_entrypoints(
            'qgssrv_contrib_protocol_handler')