Skip to content

Commit

Permalink
Remove postgres cache handler
Browse files Browse the repository at this point in the history
    * Use generic Qgis storage instead
    * Remove broken validators
  • Loading branch information
dmarteau committed Aug 21, 2024
1 parent 8ef806e commit 7efd933
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 534 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Remove deprecated store apis:
- `/store/`
- `/ows/store/`
* Remove postgres cache handler in favor of generic Qgis storage

## 1.8.7 - 2024-07-15

Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ typing:
client-test:
cd tests/clienttests && pytest -v $(PYTEST_ADDOPTS)

scan:
@bandit -c pyproject.toml -r pyqgiswps

3 changes: 3 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ RUN mkdir -p /opt/local/ \
COPY docker/docker-entrypoint.sh /
RUN chmod 0755 /docker-entrypoint.sh

# Expose to all interfaces in container
ENV QGSWPS_SERVER_INTERFACES=0.0.0.0

EXPOSE 8080

ENTRYPOINT ["/docker-entrypoint.sh"]
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ include = [
"pyqgisservercontrib.*",
]

[tool.bandit]
skips = ["B410", "B320", "B403", "B301"]
2 changes: 1 addition & 1 deletion pyqgiswps/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def load_configuration():
CONFIG.set('server', 'encoding', 'utf-8')
CONFIG.set('server', 'language', 'en-US')
CONFIG.set('server', 'port', getenv('QGSWPS_SERVER_HTTP_PORT', '8080'))
CONFIG.set('server', 'interfaces', getenv('QGSWPS_SERVER_INTERFACES', '0.0.0.0'))
CONFIG.set('server', 'interfaces', getenv('QGSWPS_SERVER_INTERFACES', '127.0.0.1'))
# Select if output files are returned by reference or in response body
CONFIG.set('server', 'outputfile_as_reference', getenv('QGSWPS_SERVER_OUTPUTFILE_AS_REFERENCE', 'yes'))
# Max input file fetched as remote reference
Expand Down
3 changes: 2 additions & 1 deletion pyqgiswps/executors/processfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from ..config import confservice
from ..exceptions import ProcessException
from ..poolserver.server import create_poolserver
from ..utils.conditions import assert_precondition
from ..utils.plugins import WPSServerInterfaceImpl
from ..utils.qgis import setup_qgis_paths, start_qgis_application
from .logstore import logstore
Expand Down Expand Up @@ -141,7 +142,7 @@ def initialize(self, load_qgis_processing: bool = False) -> Optional[List[WPSPro
Should be called once
"""
assert not self._initialized
assert_precondition(not self._initialized)

self._config = confservice['processing']

Expand Down
10 changes: 8 additions & 2 deletions pyqgiswps/inout/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@

from pyqgiswps.exceptions import InvalidParameterValue
from pyqgiswps.inout.formats import Format
from pyqgiswps.inout.literaltypes import LITERAL_DATA_TYPES, convert, is_anyvalue, to_json_serializable
from pyqgiswps.inout.literaltypes import (
LITERAL_DATA_TYPES,
convert,
is_anyvalue,
to_json_serializable,
)
from pyqgiswps.inout.uoms import UOM
from pyqgiswps.utils.conditions import assert_precondition
from pyqgiswps.validator import get_validator
from pyqgiswps.validator.base import emptyvalidator
from pyqgiswps.validator.literalvalidator import validate_allowed_values, validate_anyvalue
Expand Down Expand Up @@ -189,7 +195,7 @@ class BasicLiteral:
"""

def __init__(self, data_type, uoms=None):
assert data_type in LITERAL_DATA_TYPES, f"data type {data_type} no supported"
assert_precondition(data_type in LITERAL_DATA_TYPES, f"data type {data_type} no supported")
self.data_type = data_type
# current uom
self.supported_uoms = uoms
Expand Down
4 changes: 3 additions & 1 deletion pyqgiswps/poolserver/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

import os

from tempfile import gettempdir

_pid = os.getpid()


def _get_ipc(name: str) -> str:
ipc_path = f'/tmp/qgswps/{name}_{_pid}'
ipc_path = f'{gettempdir()}/qgswps/{name}_{_pid}'
os.makedirs(os.path.dirname(ipc_path), exist_ok=True)
return f'ipc://{ipc_path}'

Expand Down
2 changes: 1 addition & 1 deletion pyqgiswps/qgscache/cachemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def get_project_factory(self, key: str) -> Callable:

# Retrieve the protocol-handler
try:
store = componentmanager.get_service('@3liz.org/cache/protocol-handler;1?scheme=%s' % scheme)
store = componentmanager.get_service(f'@3liz.org/cache/protocol-handler;1?scheme={scheme}')
except componentmanager.FactoryNotFoundError:
LOGGER.warning("No protocol handler found for %s: using Qgis storage handler", scheme)
# Fallback to Qgis storage handler
Expand Down
1 change: 0 additions & 1 deletion pyqgiswps/qgscache/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@


from .file_handler import * # noqa: F403
from .postgres_handler import * # noqa: F403

__all__ = []
110 changes: 0 additions & 110 deletions pyqgiswps/qgscache/handlers/postgres_handler.py

This file was deleted.

12 changes: 12 additions & 0 deletions pyqgiswps/qgscache/handlers/storagehandlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Copyright 2020 3liz
# Author David Marteau
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

""" Qgis storage protocol handler
Register storage handlers as protocol handler
"""
26 changes: 13 additions & 13 deletions pyqgiswps/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,44 +237,44 @@ def options(self, headers: Optional[Dict] = None, path: str = '/ows/') -> WpsTes


def assert_response_accepted(resp):
assert resp.status_code == 200, "resp.status_code = %s" % resp.status_code
assert resp.headers['Content-Type'] == 'text/xml;charset=utf-8'
assert resp.status_code == 200, f"resp.status_code = {resp.status_code}" # nosec
assert resp.headers['Content-Type'] == 'text/xml;charset=utf-8' # nosec
success = resp.xpath_text(
'/wps:ExecuteResponse'
'/wps:Status'
'/wps:ProcessAccepted',
)
assert success is not None
assert success is not None # nosec
# TODO: assert status URL is present


def assert_process_started(resp):
assert resp.status_code == 200, "resp.status_code = %s" % resp.status_code
assert resp.headers['Content-Type'] == 'text/xml;charset=utf-8'
assert resp.status_code == 200, f"resp.status_code = {resp.status_code}" # nosec
assert resp.headers['Content-Type'] == 'text/xml;charset=utf-8' # nosec
success = resp.xpath_text(
'/wps:ExecuteResponse'
'/wps:Status'
'ProcessStarted',
)
# Is it still like this in PyWPS-4 ?
assert success.split[0] == "processstarted"
assert success.split[0] == "processstarted" # nosec


def assert_response_success(resp):
assert resp.status_code == 200, "resp.status_code = %s" % resp.status_code
assert resp.headers['Content-Type'] == 'text/xml;charset=utf-8'
assert resp.status_code == 200, f"resp.status_code = {resp.status_code}" # nosec
assert resp.headers['Content-Type'] == 'text/xml;charset=utf-8' # nosec
success = resp.xpath('/wps:ExecuteResponse/wps:Status/wps:ProcessSucceeded')
assert len(success) == 1
assert len(success) == 1 # nosec


def assert_pyqgiswps_version(resp):
# get first child of root element
root_firstchild = resp.xpath('/*')[0].getprevious()
assert isinstance(root_firstchild, lxml.etree._Comment)
assert isinstance(root_firstchild, lxml.etree._Comment) # nosec
tokens = root_firstchild.text.split()
assert len(tokens) == 2
assert tokens[0] == 'py-qgis-wps'
assert tokens[1] == __version__
assert len(tokens) == 2 # nosec
assert tokens[0] == 'py-qgis-wps' # nosec
assert tokens[1] == __version__ # nosec


#
Expand Down
4 changes: 3 additions & 1 deletion pyqgiswps/utils/lru.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"""
from collections import OrderedDict

from .conditions import assert_precondition


class lrucache():

Expand Down Expand Up @@ -104,7 +106,7 @@ def size(self, size=None):
:param int size: maximum number of elements in the cache
"""
if size is not None:
assert size > 0
assert_precondition(size > 0)
if size < self._capacity:
d = self._table
# Remove extra items
Expand Down
11 changes: 5 additions & 6 deletions pyqgiswps/validator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@
import logging

from pyqgiswps.validator.base import emptyvalidator
from pyqgiswps.validator.complexvalidator import validategeojson, validategeotiff, validategml, validateshapefile

LOGGER = logging.getLogger('SRVLOG')

_VALIDATORS = {
'application/vnd.geo+json': validategeojson,
'application/json': validategeojson,
'application/x-zipped-shp': validateshapefile,
'application/gml+xml': validategml,
'image/tiff; subtype=geotiff': validategeotiff,
'application/vnd.geo+json': emptyvalidator,
'application/json': emptyvalidator,
'application/x-zipped-shp': emptyvalidator,
'application/gml+xml': emptyvalidator,
'image/tiff; subtype=geotiff': emptyvalidator,
'application/xogc-wcs': emptyvalidator,
'application/x-ogc-wcs; version=1.0.0': emptyvalidator,
'application/x-ogc-wcs; version=1.1.0': emptyvalidator,
Expand Down
Loading

0 comments on commit 7efd933

Please sign in to comment.