From 56613e1cb24a8a730ba273e111118b8753d74114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Wed, 27 Nov 2024 15:08:33 +0100 Subject: [PATCH 1/2] Fix OGC API features --- ci/mapserver.conf | 15 ---- ci/test-app | 1 - ci/vars.yaml | 4 +- ...fecfe_update_the_ogc_server_for_ogc_api.py | 71 +++++++++++++++++++ commons/c2cgeoportal_commons/models/main.py | 4 +- geoportal/c2cgeoportal_geoportal/__init__.py | 16 ----- .../docker-compose.override.sample.yaml | 5 ++ .../{{cookiecutter.project}}/env.default | 2 +- .../geoportal/vars.yaml | 2 +- .../mapserver/mapserver.conf | 3 +- .../mapserver/mapserver.map.tmpl | 2 +- .../tests/test_app.py | 8 +-- .../geoportal/CONST_vars.yaml | 4 +- .../scripts/create_demo_theme.py | 7 +- .../views/mapserverproxy.py | 4 -- 15 files changed, 94 insertions(+), 54 deletions(-) delete mode 100644 ci/mapserver.conf create mode 100644 commons/c2cgeoportal_commons/alembic/main/2e57710fecfe_update_the_ogc_server_for_ogc_api.py diff --git a/ci/mapserver.conf b/ci/mapserver.conf deleted file mode 100644 index e60d9b3e91..0000000000 --- a/ci/mapserver.conf +++ /dev/null @@ -1,15 +0,0 @@ -# Documentation: https://mapserver.org/mapfile/config.html - -CONFIG - - ENV - END - - # - # Map aliases - # - MAPS - mapserver "/etc/mapserver/mapserver.map" - END - -END diff --git a/ci/test-app b/ci/test-app index f3cf887b94..04bbaa35c7 100755 --- a/ci/test-app +++ b/ci/test-app @@ -13,7 +13,6 @@ touch "${HOME}/workspace/testgeomapfishapp/qgisserver/project.qgs.raster" cp ci/tileindex/* "${HOME}/workspace/testgeomapfishapp/mapserver/" cp -r ci/test-app-db "${HOME}/workspace/testgeomapfishapp/ci/" cp -r ci/test-external-db "${HOME}/workspace/testgeomapfishapp/ci/" -cp ci/mapserver.conf "${HOME}/workspace/testgeomapfishapp/mapserver/" cd "${HOME}/workspace/testgeomapfishapp/" diff --git a/ci/vars.yaml b/ci/vars.yaml index 4aef129413..6c7c67da16 100644 --- a/ci/vars.yaml +++ b/ci/vars.yaml @@ -11,7 +11,7 @@ vars: type: canvas layout: desktop - main_ogc_server: mapserver + main_ogc_server: MapServer dbsessions: ci_test: @@ -25,7 +25,7 @@ vars: type: table: main.test - checker_ogc_server: mapserver + checker_ogc_server: MapServer checker: fulltextsearch: disable: true diff --git a/commons/c2cgeoportal_commons/alembic/main/2e57710fecfe_update_the_ogc_server_for_ogc_api.py b/commons/c2cgeoportal_commons/alembic/main/2e57710fecfe_update_the_ogc_server_for_ogc_api.py new file mode 100644 index 0000000000..09c6b88da8 --- /dev/null +++ b/commons/c2cgeoportal_commons/alembic/main/2e57710fecfe_update_the_ogc_server_for_ogc_api.py @@ -0,0 +1,71 @@ +# Copyright (c) 2024, Camptocamp SA +# All rights reserved. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: + +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# The views and conclusions contained in the software and documentation are those +# of the authors and should not be interpreted as representing official policies, +# either expressed or implied, of the FreeBSD Project. + +# pylint: disable=invalid-name + +""" +Update the OGC server for OGC API. + +Revision ID: 2e57710fecfe +Revises: a4558f032d7d +Create Date: 2024-11-27 12:47:20.234376 +""" + +from alembic import op +from c2c.template.config import config + +# revision identifiers, used by Alembic. +revision = "2e57710fecfe" +down_revision = "a4558f032d7d" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + """Upgrade.""" + schema = config["schema"] + + # Instructions + + # default 'image/jpeg', 'image/png' + op.execute(f"UPDATE {schema}.ogc_server SET name = 'MapServer' WHERE name = 'source for image/png'") + op.execute(f"UPDATE {schema}.ogc_server SET name = 'MapServer_JPEG' WHERE name = 'source for image/jpeg'") + op.execute( + f"UPDATE {schema}.ogc_server SET url = 'config://mapserver/mapserv_proxy/MapServer?MAP=MapServer' WHERE url = 'config://mapserver'" + ) + + +def downgrade() -> None: + """Downgrade.""" + schema = config["schema"] + + # Instructions + op.execute(f"UPDATE {schema}.ogc_server SET name = 'source for image/png' WHERE name = 'MapServer'") + op.execute(f"UPDATE {schema}.ogc_server SET name = 'source for image/jpeg' WHERE name = 'MapServer_JPEG'") + op.execute( + f"UPDATE {schema}.ogc_server SET url = 'config://mapserver' WHERE url = 'config://mapserver/mapserv_proxy/MapServer?MAP=MapServer'" + ) diff --git a/commons/c2cgeoportal_commons/models/main.py b/commons/c2cgeoportal_commons/models/main.py index 0ad033a1dd..ffc87dd9f4 100644 --- a/commons/c2cgeoportal_commons/models/main.py +++ b/commons/c2cgeoportal_commons/models/main.py @@ -747,7 +747,9 @@ class OGCServer(Base): # type: ignore info={ "colanderalchemy": { "title": _("Name"), - "description": _("The name of the OGC Server"), + "description": _( + "The name of the OGC Server, should contains only no unaccentuated letters, numbers and _" + ), } }, ) diff --git a/geoportal/c2cgeoportal_geoportal/__init__.py b/geoportal/c2cgeoportal_geoportal/__init__.py index fa3d824f07..2e38add0fe 100644 --- a/geoportal/c2cgeoportal_geoportal/__init__.py +++ b/geoportal/c2cgeoportal_geoportal/__init__.py @@ -661,22 +661,6 @@ def handle(event: InvalidateCacheEvent) -> None: pregenerator=C2CPregenerator(role=True), request_method="POST", ) - # The two next views are used to serve the application on the URL /mapserv_proxy/ - # instead of /mapserv_proxy?ogcserver=, required for QGIS server landing page - config.add_route( - "mapserverproxy_get_path", - "/mapserv_proxy/{ogcserver}/*path", - mapserverproxy=True, - pregenerator=C2CPregenerator(role=True), - request_method="GET", - ) - config.add_route( - "mapserverproxy_post_path", - "/mapserv_proxy/{ogcserver}/*path", - mapserverproxy=True, - pregenerator=C2CPregenerator(role=True), - request_method="POST", - ) # OGC Api routes config.add_route( "mapserverproxy_ogcapi_mapserver", diff --git a/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/docker-compose.override.sample.yaml b/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/docker-compose.override.sample.yaml index d69e0d8cc1..c5650e2592 100644 --- a/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/docker-compose.override.sample.yaml +++ b/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/docker-compose.override.sample.yaml @@ -36,6 +36,11 @@ services: # environment: # - LOG_LEVEL=DEBUG + mapserver: + environment: + - MS_DEBUGLEVEL=5 + - MAPSERVER_CATCH_SEGV=1 + # qgisserver: # # volumes: # # - './../c2cgeoportal/docker/qgisserver/geomapfish_qgisserver/:/var/www/plugins/geomapfish_qgisserver/' diff --git a/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/env.default b/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/env.default index 69c9f0635f..80528bd7dc 100644 --- a/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/env.default +++ b/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/env.default @@ -46,7 +46,7 @@ TILECLOUDCHAIN_INTERNAL_PORT=8080 # For internal print MAPSERVER_URL=http://mapserver:8080/ TINYOWS_URL=http://tinyows:8080/ -QGISSERVER_URL=http://qgisserver:8080/mapserv_proxy +QGISSERVER_URL=http://qgisserver:8080/ QGIS_VERSION=3.34-gdal3.8 POSTGRES_TAG=13-postgis-3 diff --git a/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/geoportal/vars.yaml b/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/geoportal/vars.yaml index d6b2de1592..6eefd30f75 100644 --- a/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/geoportal/vars.yaml +++ b/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/geoportal/vars.yaml @@ -13,7 +13,7 @@ vars: # - vars.interfaces_config.default.constants.gmfVectorTilesOptions.tileGrid.origin srid: &srid {{cookiecutter.srid}} - main_ogc_server: source for image/png + main_ogc_server: MapServer alternate_projections: &alternate_projections - EPSG:4326 diff --git a/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/mapserver/mapserver.conf b/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/mapserver/mapserver.conf index 61302736ff..e2e40b4500 100644 --- a/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/mapserver/mapserver.conf +++ b/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/mapserver/mapserver.conf @@ -3,13 +3,14 @@ CONFIG ENV - MS_MAPFILE "/etc/mapserver/mapserver.map" + MS_MAP_PATTERN "^[a-zA-Z0-9_]+" END # # Map aliases # MAPS + MapServer "/etc/mapserver/mapserver.map" END END diff --git a/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/mapserver/mapserver.map.tmpl b/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/mapserver/mapserver.map.tmpl index 042270edc9..c632df76e8 100644 --- a/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/mapserver/mapserver.map.tmpl +++ b/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/mapserver/mapserver.map.tmpl @@ -68,7 +68,7 @@ MAP METADATA "wms_title" "changeme" "wms_abstract" "changeme" - "ows_onlineresource" "${VISIBLE_WEB_PROTOCOL}://${VISIBLE_WEB_HOST}${VISIBLE_ENTRY_POINT}mapserv_proxy?ogcserver=source%20for%20image%2Fpng" + "ows_onlineresource" "${VISIBLE_WEB_PROTOCOL}://${VISIBLE_WEB_HOST}${VISIBLE_ENTRY_POINT}mapserv_proxy?ogcserver=MapServer" "wms_srs" "EPSG:{{cookiecutter.srid}}" "wms_enable_request" "*" "wfs_enable_request" "!*" diff --git a/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/tests/test_app.py b/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/tests/test_app.py index 012b3baf3c..03829dfe2b 100644 --- a/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/tests/test_app.py +++ b/geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter.project}}/tests/test_app.py @@ -18,13 +18,13 @@ ("https://front/admin/layertree", {}, 10), ("https://front/admin/layertree/children", {}, 10), ( - "http://mapserver:8080/mapserv_proxy/mapserver", + "http://mapserver:8080/mapserv_proxy/MapServer", {"SERVICE": "WMS", "REQUEST": "GetCapabilities"}, 60, ), ( "https://front/mapserv_proxy", - {"ogcserver": "mapserver", "SERVICE": "WMS", "REQUEST": "GetCapabilities"}, + {"ogcserver": "MapServer", "SERVICE": "WMS", "REQUEST": "GetCapabilities"}, 60, ), # ( @@ -39,12 +39,12 @@ # ), # OGC API - Features # ( - # "http://mapserver:8080/mapserv_proxy/mapserver/ogcapi/collections/osm_protected/items", + # "http://mapserver:8080/mapserv_proxy/MapServer/ogcapi/collections/osm_protected/items", # {"bbox": "6.0,46.0,7.0,47.0", "limit": "100"}, # 60, # ), # ( - # "https://front/mapserv_proxy/mapserver/mapserver/ogcapi/collections/osm_open/items", + # "https://front/mapserv_proxy/MapServer/ogcapi/collections/osm_open/items", # {"bbox": "6.0,46.0,7.0,47.0", "limit": "100"}, # 60, # ), diff --git a/geoportal/c2cgeoportal_geoportal/scaffolds/update/{{cookiecutter.project}}/geoportal/CONST_vars.yaml b/geoportal/c2cgeoportal_geoportal/scaffolds/update/{{cookiecutter.project}}/geoportal/CONST_vars.yaml index 04ac052ca7..412393c7ae 100644 --- a/geoportal/c2cgeoportal_geoportal/scaffolds/update/{{cookiecutter.project}}/geoportal/CONST_vars.yaml +++ b/geoportal/c2cgeoportal_geoportal/scaffolds/update/{{cookiecutter.project}}/geoportal/CONST_vars.yaml @@ -2,7 +2,7 @@ vars: # The package name package: '{{cookiecutter.package}}' - main_ogc_server: source for image/png + main_ogc_server: MapServer srid: EPSG:-1 @@ -1206,7 +1206,7 @@ vars: - '{VISIBLE_WEB_PROTOCOL}://{VISIBLE_WEB_HOST}' # Checker configuration - checker_ogc_server: source for image/png + checker_ogc_server: MapServer checker: forward_host: False base_internal_url: http://localhost:8080 diff --git a/geoportal/c2cgeoportal_geoportal/scripts/create_demo_theme.py b/geoportal/c2cgeoportal_geoportal/scripts/create_demo_theme.py index 5ba752f3d9..e3b1744366 100644 --- a/geoportal/c2cgeoportal_geoportal/scripts/create_demo_theme.py +++ b/geoportal/c2cgeoportal_geoportal/scripts/create_demo_theme.py @@ -30,7 +30,6 @@ import logging import transaction - from c2cgeoportal_geoportal.scripts import fill_arguments, get_appsettings, get_session _LOG = logging.getLogger(__name__) @@ -55,12 +54,10 @@ def main() -> None: ) interfaces = session.query(Interface).all() - ogc_jpeg = session.query(OGCServer).filter(OGCServer.name == "source for image/jpeg").one() + ogc_jpeg = session.query(OGCServer).filter(OGCServer.name == "MapServer_JPEG").one() session.delete(ogc_jpeg) - ogc_server_mapserver = session.query(OGCServer).filter(OGCServer.name == "source for image/png").one() - ogc_server_mapserver.name = "mapserver" - ogc_server_mapserver.url = "config://mapserver/mapserv_proxy/mapserver?map=mapserver" + ogc_server_mapserver = session.query(OGCServer).filter(OGCServer.name == "MapServer").one() layer_borders = LayerWMS("Borders", "borders") layer_borders.interfaces = interfaces diff --git a/geoportal/c2cgeoportal_geoportal/views/mapserverproxy.py b/geoportal/c2cgeoportal_geoportal/views/mapserverproxy.py index 2c39401565..474530112f 100644 --- a/geoportal/c2cgeoportal_geoportal/views/mapserverproxy.py +++ b/geoportal/c2cgeoportal_geoportal/views/mapserverproxy.py @@ -58,8 +58,6 @@ def __init__(self, request: Request) -> None: @view_config(route_name="mapserverproxy") # type: ignore @view_config(route_name="mapserverproxy_post") # type: ignore - @view_config(route_name="mapserverproxy_get_path") # type: ignore - @view_config(route_name="mapserverproxy_post_path") # type: ignore def proxy(self) -> Response: if self.user is None and "authentication_required" in self.request.params: _LOG.debug("proxy() detected authentication_required") @@ -186,8 +184,6 @@ def proxy_ogcapi(self, subpath: str) -> Response: _url = self._get_wfs_url(errors) if _url is not None: _url.path = "/".join([_url.path.rstrip("/"), subpath, *self.request.matchdict["path"]]) - _LOG.warning("URL: %s", _url) - _LOG.warning(self.request.matchdict) if _url is None: _LOG.error("Error getting the URL:\n%s", "\n".join(errors)) From ce931b365537b99d2e1df94dc86d02f0c8b4b6b1 Mon Sep 17 00:00:00 2001 From: "geo-ghci-int[bot]" <146321879+geo-ghci-int[bot]@users.noreply.github.com> Date: Thu, 28 Nov 2024 11:05:24 +0000 Subject: [PATCH 2/2] Apply pre-commit fix From the artifact of the previous workflow run --- geoportal/c2cgeoportal_geoportal/scripts/create_demo_theme.py | 1 + 1 file changed, 1 insertion(+) diff --git a/geoportal/c2cgeoportal_geoportal/scripts/create_demo_theme.py b/geoportal/c2cgeoportal_geoportal/scripts/create_demo_theme.py index e3b1744366..c9765c36fd 100644 --- a/geoportal/c2cgeoportal_geoportal/scripts/create_demo_theme.py +++ b/geoportal/c2cgeoportal_geoportal/scripts/create_demo_theme.py @@ -30,6 +30,7 @@ import logging import transaction + from c2cgeoportal_geoportal.scripts import fill_arguments, get_appsettings, get_session _LOG = logging.getLogger(__name__)