From 21f377d7fd0ff6ea51386a7dc94ebfbc54e258d2 Mon Sep 17 00:00:00 2001 From: index-git Date: Wed, 13 Sep 2023 10:00:35 +0200 Subject: [PATCH] Incorporate X-Forwarded-Prefix into url key of PATCH Workspace Layer --- CHANGELOG.md | 2 +- doc/client-proxy.md | 7 +++++++ src/layman/layer/rest_workspace_layer.py | 4 +++- .../x_forwarded_prefix/rest_endpoints_test.py | 14 +++++++------- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 045752178..4c0689117 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ - [#765](https://github.com/LayerManager/layman/issues/765) Remove `authn.txt` files from workspace directories. The same information as in `authn.txt` files is saved in prime DB schema. - [#868](https://github.com/LayerManager/layman/issues/868) Fill table `map_layer` with relations between maps and [internal layers](doc/models.md#internal-map-layer) (layers published on this Layman instance). Relations to [external layers](doc/models.md#internal-map-layer) (layers of other servers) are not imported into the table. ### Changes -- [#868](https://github.com/LayerManager/layman/issues/868) Endpoints [GET Publications](doc/rest.md#get-publications), [GET Layers](doc/rest.md#get-layers), [GET Workspace Layers](doc/rest.md#get-workspace-layers), [GET Maps](doc/rest.md#get-maps), [GET Workspace Maps](doc/rest.md#get-workspace-maps), [GET Workspace Layer](doc/rest.md#get-workspace-layer), [GET Workspace Map](doc/rest.md#get-workspace-map), [POST Workspace Layers](doc/rest.md#post-workspace-layers), [DELETE Workspace Layer](doc/rest.md#delete-workspace-layer), [DELETE Workspace Layers](doc/rest.md#delete-workspace-layers), [DELETE Workspace Map](doc/rest.md#delete-workspace-map), [DELETE Workspace Maps](doc/rest.md#delete-workspace-maps), [POST Workspace Maps](doc/rest.md#post-workspace-maps) and [WMS/WFS endpoints](doc/endpoints.md) respects [HTTP header `X-Forwarded-Prefix`](doc/client-proxy.md#x-forwarded-prefix-http-header) of the request in the response. +- [#868](https://github.com/LayerManager/layman/issues/868) Endpoints [GET Publications](doc/rest.md#get-publications), [GET Layers](doc/rest.md#get-layers), [GET Workspace Layers](doc/rest.md#get-workspace-layers), [GET Maps](doc/rest.md#get-maps), [GET Workspace Maps](doc/rest.md#get-workspace-maps), [GET Workspace Layer](doc/rest.md#get-workspace-layer), [GET Workspace Map](doc/rest.md#get-workspace-map), [POST Workspace Layers](doc/rest.md#post-workspace-layers), [DELETE Workspace Layer](doc/rest.md#delete-workspace-layer), [DELETE Workspace Layers](doc/rest.md#delete-workspace-layers), [DELETE Workspace Map](doc/rest.md#delete-workspace-map), [DELETE Workspace Maps](doc/rest.md#delete-workspace-maps), [POST Workspace Maps](doc/rest.md#post-workspace-maps), [PATCH Workspace Layer](doc/rest.md#patch-workspace-layer) and [WMS/WFS endpoints](doc/endpoints.md) respects [HTTP header `X-Forwarded-Prefix`](doc/client-proxy.md#x-forwarded-prefix-http-header) of the request in the response. - [#868](https://github.com/LayerManager/layman/issues/868) Relations between map and [internal layers](doc/models.md#internal-map-layer) are updated in `map_layer` table when calling [POST Workspace Maps](doc/rest.md#post-workspace-maps), [DELETE Workspace Map](doc/rest.md#delete-workspace-map), and [DELETE Workspace Maps](doc/rest.md#delete-workspace-maps). - [#880](https://github.com/LayerManager/layman/issues/880) Use Docker Compose v2 (`docker compose`) in Makefile without `compatibility` flag and remove `Makefile_docker-compose_v1` file. Docker containers are named according to Docker Compose v2 and may have different name after upgrade. - [#765](https://github.com/LayerManager/layman/issues/765) Stop saving OAuth2 claims in filesystem, use prime DB schema only. diff --git a/doc/client-proxy.md b/doc/client-proxy.md index 18755f331..f26bde5fb 100644 --- a/doc/client-proxy.md +++ b/doc/client-proxy.md @@ -75,6 +75,13 @@ Currently, value of `X-Forwarded-Prefix` affects following URLs: * `url` key * [POST Workspace Maps](rest.md#post-workspace-maps) * `url` key +* [PATCH Workspace Layer](rest.md#patch-workspace-layer) + * `url` key + * `wms`.`url` key + * `wfs`.`url` key + * `style`.`url` key + * `thumbnail`.`url` key + * `metadata`.`comparison_url` key * [OGC endpoints](endpoints.md) * Headers `X-Forwarded-Proto`, `X-Forwarded-Host`, `X-Forwarded-For`, `X-Forwarded-Path`, `Forwarded` and `Host` are ignored * [WMS endpoints](endpoints.md#web-map-service) diff --git a/src/layman/layer/rest_workspace_layer.py b/src/layman/layer/rest_workspace_layer.py index becd8b761..068daf72b 100644 --- a/src/layman/layer/rest_workspace_layer.py +++ b/src/layman/layer/rest_workspace_layer.py @@ -48,6 +48,8 @@ def get(workspace, layername): def patch(workspace, layername): app.logger.info(f"PATCH Layer, actor={g.user}") + x_forwarded_prefix = layman_util.get_x_forwarded_prefix(request.headers) + info = layman_util.get_publication_info(workspace, LAYER_TYPE, layername, context={'keys': ['title', 'name', 'description', 'table_uri', 'geodata_type', 'style_type', 'original_data_source', ]}) @@ -260,7 +262,7 @@ def patch(workspace, layername): ) app.logger.info('PATCH Layer changes done') - info = util.get_complete_layer_info(workspace, layername) + info = util.get_complete_layer_info(workspace, layername, x_forwarded_prefix=x_forwarded_prefix) info.update(layer_result) return jsonify(info), 200 diff --git a/tests/dynamic_data/publications/x_forwarded_prefix/rest_endpoints_test.py b/tests/dynamic_data/publications/x_forwarded_prefix/rest_endpoints_test.py index 2d594a164..f73c236ba 100644 --- a/tests/dynamic_data/publications/x_forwarded_prefix/rest_endpoints_test.py +++ b/tests/dynamic_data/publications/x_forwarded_prefix/rest_endpoints_test.py @@ -37,28 +37,28 @@ def test_publication(self, publication, rest_method): publication_response = response[0] if isinstance(response, list) and len(response) == 1 else response if rest_method == self.patch_publication: # pylint: disable=W0143 exp_resp = { - 'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}', + 'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}', 'thumbnail': { - 'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/rest/workspaces/{publication.workspace}/layers/{publication.name}/thumbnail' + 'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/layers/{publication.name}/thumbnail' }, 'metadata': { - 'comparison_url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/rest/workspaces/{publication.workspace}/layers/{publication.name}/metadata-comparison', + 'comparison_url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/layers/{publication.name}/metadata-comparison', }, 'wms': { - 'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/geoserver/{publication.workspace}_wms/ows', + 'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/geoserver/{publication.workspace}_wms/ows', }, 'sld': { - 'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/rest/workspaces/{publication.workspace}/layers/{publication.name}/style', + 'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/layers/{publication.name}/style', }, 'style': { - 'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/rest/workspaces/{publication.workspace}/layers/{publication.name}/style', + 'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/layers/{publication.name}/style', }, } geodata_type = response['geodata_type'] if geodata_type == settings.GEODATA_TYPE_VECTOR: exp_resp['wfs'] = { - 'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/geoserver/{publication.workspace}/wfs' + 'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/geoserver/{publication.workspace}/wfs' } else: exp_resp = {'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}'}