Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

868 Incorporate X-Forwarded-Prefix into DELETE Workspace Map(s) #912

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- [#765](https://github.com/LayerManager/layman/issues/765) Fix `issuer_id` value in `users` table that was broken since v1.21.0.
- [#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.
### 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) and [DELETE Workspace Layers](doc/rest.md#delete-workspace-layers) 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) and [DELETE Workspace Maps](doc/rest.md#delete-workspace-maps) respects [HTTP header `X-Forwarded-Prefix`](doc/client-proxy.md#x-forwarded-prefix-http-header) of the request in the response.
- [#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.
- [#893](https://github.com/LayerManager/layman/issues/893) It is possible to specify logging level by new environment variable [LAYMAN_LOGLEVEL](doc/env-settings.md#LAYMAN_LOGLEVEL). Default level is `INFO`.
Expand Down
4 changes: 4 additions & 0 deletions doc/client-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ Currently, value of `X-Forwarded-Prefix` affects following URLs:
* `url` key
* [DELETE Workspace Layers](rest.md#delete-workspace-layers)
* `url` key
* [DELETE Workspace Map](rest.md#delete-workspace-map)
* `url` key
* [DELETE Workspace Maps](rest.md#delete-workspace-maps)
* `url` key
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 @@ -115,9 +115,10 @@ def patch(workspace, mapname):
@util.lock_decorator
def delete_map(workspace, mapname):
app.logger.info(f"DELETE Map, actor={g.user}")
x_forwarded_prefix = layman_util.get_x_forwarded_prefix(request.headers)

# raise exception if map does not exist
info = util.get_complete_map_info(workspace, mapname)
info = util.get_complete_map_info(workspace, mapname, x_forwarded_prefix=x_forwarded_prefix)

util.abort_map_chain(workspace, mapname)

Expand Down
2 changes: 2 additions & 0 deletions src/layman/map/rest_workspace_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def post(workspace):
def delete(workspace):
app.logger.info(f"DELETE Maps, actor={g.user}")

x_forwarded_prefix = layman_util.get_x_forwarded_prefix(request.headers)
infos = layman_util.delete_publications(workspace,
MAP_TYPE,
util.is_map_chain_ready,
Expand All @@ -142,6 +143,7 @@ def delete(workspace):
request.method,
'rest_workspace_map.get',
'mapname',
x_forwarded_prefix=x_forwarded_prefix,
)

return infos, 200
23 changes: 19 additions & 4 deletions tests/dynamic_data/publications/x_forwarded_prefix_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from test_tools import process_client
from tests import EnumTestTypes
from tests.dynamic_data import base_test, base_test_classes
from tests.dynamic_data.publications import common_publications
from ... import Publication

pytest_generate_tests = base_test.pytest_generate_tests

Expand All @@ -12,15 +14,28 @@ class RestMethodLocal(base_test_classes.RestMethodBase):
MULTI_DELETE = ('delete_workspace_publications', 'multi_delete')


class PublicationTypes(base_test_classes.PublicationByDefinitionBase):
LAYER = (common_publications.LAYER_VECTOR_SLD, 'layer')
MAP = (common_publications.MAP_EMPTY, 'map')


class TestPublication(base_test.TestSingleRestPublication):
workspace = 'x_forwarded_prefix_post_workspace'
publication_type = None

rest_parametrization = [
RestMethodLocal
RestMethodLocal,
PublicationTypes,
]

test_cases = [base_test.TestCaseType(key='layer',
publication_type=process_client.LAYER_TYPE,
test_cases = [base_test.TestCaseType(key='proxy_test',
publication=lambda publ_def, cls: Publication(cls.workspace,
publ_def.type,
None),
type=EnumTestTypes.MANDATORY,
specific_types={
(PublicationTypes.MAP, RestMethodLocal.POST): EnumTestTypes.IGNORE,
},
)]

@classmethod
Expand All @@ -36,4 +51,4 @@ def test_publication(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
assert publication_response['url'] == f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/layers/{publication.name}'
assert publication_response['url'] == f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}'
Loading