Skip to content

Commit

Permalink
Incorporate X-Forwarded-Prefix into url key of PATCH Workspace Map
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git authored and jirik committed Sep 13, 2023
1 parent fdc4b0f commit 0b2cfc0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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), [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) 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), [PATCH Workspace Map](doc/rest.md#patch-workspace-map) 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.
Expand Down
5 changes: 5 additions & 0 deletions doc/client-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ Currently, value of `X-Forwarded-Prefix` affects following URLs:
* `style`.`url` key
* `thumbnail`.`url` key
* `metadata`.`comparison_url` key
* [PATCH Workspace Map](rest.md#patch-workspace-map)
* `url` key
* `file`.`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)
Expand Down
3 changes: 2 additions & 1 deletion src/layman/map/rest_workspace_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def get(workspace, mapname):
def patch(workspace, mapname):
app.logger.info(f"PATCH Map, actor={g.user}")

x_forwarded_prefix = layman_util.get_x_forwarded_prefix(request.headers)
info = util.get_complete_map_info(workspace, mapname)

# FILE
Expand Down Expand Up @@ -106,7 +107,7 @@ def patch(workspace, mapname):
'layman.map.filesystem.input_file' if file_changed else None
)

info = util.get_complete_map_info(workspace, mapname)
info = util.get_complete_map_info(workspace, mapname, x_forwarded_prefix=x_forwarded_prefix)

return jsonify(info), 200

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from tests import EnumTestTypes, Publication
from tests.dynamic_data import base_test, base_test_classes
from tests.dynamic_data.publications import common_publications
from test_tools import assert_util
from test_tools import assert_util, process_client

pytest_generate_tests = base_test.pytest_generate_tests

Expand All @@ -26,40 +26,52 @@ class TestPublication(base_test.TestSingleRestPublication):
publ_def.type,
None),
type=EnumTestTypes.MANDATORY,
specific_types={
(base_test_classes.RestMethodAll.PATCH, PublicationTypes.MAP): EnumTestTypes.IGNORE,
}
)]

def test_publication(self, publication, rest_method):
proxy_prefix = '/layman-proxy'
response = rest_method(publication, args={'headers': {'X-Forwarded-Prefix': proxy_prefix}})
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}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{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}{proxy_prefix}/rest/workspaces/{publication.workspace}/layers/{publication.name}/metadata-comparison',
},
'wms': {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/geoserver/{publication.workspace}_wms/ows',
},
'sld': {
'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}{proxy_prefix}/rest/workspaces/{publication.workspace}/layers/{publication.name}/style',
},
}
if publication.type == process_client.LAYER_TYPE:
exp_resp = {
'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}{proxy_prefix}/rest/workspaces/{publication.workspace}/layers/{publication.name}/thumbnail'
},
'metadata': {
'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}{proxy_prefix}/geoserver/{publication.workspace}_wms/ows',
},
'sld': {
'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}{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}{proxy_prefix}/geoserver/{publication.workspace}/wfs'
geodata_type = response['geodata_type']
if geodata_type == settings.GEODATA_TYPE_VECTOR:
exp_resp['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}',
'thumbnail': {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}/thumbnail'
},
'file': {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}/file'
},
'metadata': {
'comparison_url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}/metadata-comparison',
},
}

else:
exp_resp = {'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}'}

Expand Down

0 comments on commit 0b2cfc0

Please sign in to comment.