Skip to content

Commit

Permalink
Rename x_forwarded_prefix to x_forwarded_items
Browse files Browse the repository at this point in the history
Not in tests
  • Loading branch information
jirik committed Sep 25, 2023
1 parent e26b895 commit 5e3245a
Show file tree
Hide file tree
Showing 24 changed files with 89 additions and 83 deletions.
4 changes: 2 additions & 2 deletions src/layman/common/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def get_integer_from_param(request_args, param_name, negative=True, zero=True, p
return result


def get_publications(publication_type, actor, request_args=None, workspace=None, *, x_forwarded_prefix=None):
def get_publications(publication_type, actor, request_args=None, workspace=None, *, x_forwarded_items=None):
request_args = request_args or {}
known_order_by_values = [consts.ORDER_BY_TITLE, consts.ORDER_BY_FULL_TEXT, consts.ORDER_BY_LAST_CHANGE,
consts.ORDER_BY_BBOX, ]
Expand Down Expand Up @@ -251,7 +251,7 @@ def get_publications(publication_type, actor, request_args=None, workspace=None,
'workspace': res_workspace,
'publication_type': info['type'].split('.')[1],
'title': info.get("title"),
'url': layman_util.get_workspace_publication_url(info['type'], res_workspace, name, x_forwarded_prefix=x_forwarded_prefix),
'url': layman_util.get_workspace_publication_url(info['type'], res_workspace, name, x_forwarded_items=x_forwarded_items),
'uuid': info["uuid"],
'access_rights': info['access_rights'],
'updated_at': info['updated_at'].isoformat(),
Expand Down
4 changes: 2 additions & 2 deletions src/layman/geoserver_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ def proxy(subpath):
'Host',
]:
headers_req.pop(header, None)
x_forwarded_prefix = layman_util.get_x_forwarded_items(request.headers)
headers_req['X-Forwarded-Path'] = x_forwarded_prefix or ''
x_forwarded_items = layman_util.get_x_forwarded_items(request.headers)
headers_req['X-Forwarded-Path'] = x_forwarded_items.prefix or ''

# ensure layer attributes in case of WFS-T
app.logger.info(f"{request.method} GeoServer proxy, headers_req={headers_req}, url={url}")
Expand Down
4 changes: 2 additions & 2 deletions src/layman/layer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,5 @@ def get_layer_info_keys(*, geodata_type, original_data_source):
NO_STYLE_DEF = STYLE_TYPES_DEF[0]


def get_workspace_publication_url(workspace, publication_name, *, x_forwarded_prefix=None):
return url_for('rest_workspace_layer.get', layername=publication_name, workspace=workspace, x_forwarded_prefix=x_forwarded_prefix)
def get_workspace_publication_url(workspace, publication_name, *, x_forwarded_items=None):
return url_for('rest_workspace_layer.get', layername=publication_name, workspace=workspace, x_forwarded_items=x_forwarded_items)
4 changes: 2 additions & 2 deletions src/layman/layer/filesystem/thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def ensure_layer_thumbnail_dir(workspace, layername):
return thumbnail_dir


def get_layer_info(workspace, layername, *, x_forwarded_prefix=None):
def get_layer_info(workspace, layername, *, x_forwarded_items=None):
thumbnail_path = get_layer_thumbnail_path(workspace, layername)
if os.path.exists(thumbnail_path):
return {
'thumbnail': {
'url': url_for('rest_workspace_layer_thumbnail.get', workspace=workspace,
layername=layername,
x_forwarded_prefix=x_forwarded_prefix),
x_forwarded_items=x_forwarded_items),
'path': os.path.relpath(thumbnail_path, common_util.get_workspace_dir(workspace))
},
'_thumbnail': {
Expand Down
4 changes: 2 additions & 2 deletions src/layman/layer/geoserver/sld.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def delete_layer(workspace, layername):
return result


def get_layer_info(workspace, layername, *, x_forwarded_prefix=None):
def get_layer_info(workspace, layername, *, x_forwarded_items=None):
response = get_style_response(workspace, layername, gs_util.headers_sld['1.0.0'], settings.LAYMAN_GS_AUTH)
if response and response.status_code == 200:
url = url_for('rest_workspace_layer_style.get', workspace=workspace, layername=layername, x_forwarded_prefix=x_forwarded_prefix)
url = url_for('rest_workspace_layer_style.get', workspace=workspace, layername=layername, x_forwarded_items=x_forwarded_items)
info = {
'style': {
'url': url,
Expand Down
12 changes: 7 additions & 5 deletions src/layman/layer/geoserver/wfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from layman.layer.util import is_layer_chain_ready
from layman import util as layman_util
from layman.layer import LAYER_TYPE
from layman.util import XForwardedClass
import requests_util.retry
from .util import get_gs_proxy_server_url, get_external_db_store_name
from . import wms
Expand Down Expand Up @@ -58,9 +59,10 @@ def delete_layer(workspace, layername):
return {}


def get_wfs_url(workspace, external_url=False, *, x_forwarded_prefix=None):
assert external_url or not x_forwarded_prefix
x_forwarded_prefix = x_forwarded_prefix or ''
def get_wfs_url(workspace, external_url=False, *, x_forwarded_items=None):
x_forwarded_items = x_forwarded_items or XForwardedClass()
assert external_url or not x_forwarded_items
x_forwarded_prefix = x_forwarded_items.prefix or ''
base_url = urljoin(get_gs_proxy_server_url(), x_forwarded_prefix) + settings.LAYMAN_GS_PATH if external_url else settings.LAYMAN_GS_URL
return urljoin(base_url, workspace + '/wfs')

Expand Down Expand Up @@ -125,11 +127,11 @@ def clear_cache(workspace):
mem_redis.delete(key)


def get_layer_info(workspace, layername, *, x_forwarded_prefix=None):
def get_layer_info(workspace, layername, *, x_forwarded_items=None):
wfs = get_wfs_proxy(workspace)
if wfs is None:
return {}
wfs_proxy_url = get_wfs_url(workspace, external_url=True, x_forwarded_prefix=x_forwarded_prefix)
wfs_proxy_url = get_wfs_url(workspace, external_url=True, x_forwarded_items=x_forwarded_items)

wfs_layername = f"{workspace}:{layername}"
if wfs_layername not in wfs.contents:
Expand Down
12 changes: 7 additions & 5 deletions src/layman/layer/geoserver/wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from layman.layer.util import is_layer_chain_ready
from layman.layer import LAYER_TYPE
from layman.layer.filesystem import gdal
from layman.util import XForwardedClass
import requests_util.retry
from .util import get_gs_proxy_server_url, get_external_db_store_name

Expand Down Expand Up @@ -82,9 +83,10 @@ def delete_layer(workspace, layername):
return {}


def get_wms_url(workspace, external_url=False, *, x_forwarded_prefix=None):
assert external_url or not x_forwarded_prefix
x_forwarded_prefix = x_forwarded_prefix or ''
def get_wms_url(workspace, external_url=False, *, x_forwarded_items=None):
x_forwarded_items = x_forwarded_items or XForwardedClass()
assert external_url or not x_forwarded_items
x_forwarded_prefix = x_forwarded_items.prefix or ''
geoserver_workspace = get_geoserver_workspace(workspace)
base_url = urljoin(get_gs_proxy_server_url(), x_forwarded_prefix) + settings.LAYMAN_GS_PATH if external_url else settings.LAYMAN_GS_URL
return urljoin(base_url, geoserver_workspace + '/ows')
Expand Down Expand Up @@ -170,11 +172,11 @@ def get_timeregex_props(workspace, layername):
return result


def get_layer_info(workspace, layername, *, x_forwarded_prefix=None):
def get_layer_info(workspace, layername, *, x_forwarded_items=None):
wms = get_wms_proxy(workspace)
if wms is None:
return {}
wms_proxy_url = get_wms_url(workspace, external_url=True, x_forwarded_prefix=x_forwarded_prefix)
wms_proxy_url = get_wms_url(workspace, external_url=True, x_forwarded_items=x_forwarded_items)

if layername not in wms.contents:
return {}
Expand Down
4 changes: 2 additions & 2 deletions src/layman/layer/micka/csw.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
post_layer = empty_method


def get_layer_info(workspace, layername, *, x_forwarded_prefix=None):
def get_layer_info(workspace, layername, *, x_forwarded_items=None):
uuid = get_layer_uuid(workspace, layername)
try:
csw = common_util.create_csw()
Expand All @@ -51,7 +51,7 @@ def get_layer_info(workspace, layername, *, x_forwarded_prefix=None):
'csw_url': settings.CSW_PROXY_URL,
'record_url': common_util.get_metadata_url(uuid, url_type=common_util.RecordUrlType.BASIC),
'comparison_url': url_for('rest_workspace_layer_metadata_comparison.get', workspace=workspace, layername=layername,
x_forwarded_prefix=x_forwarded_prefix),
x_forwarded_items=x_forwarded_items),
}
}
return {}
Expand Down
4 changes: 2 additions & 2 deletions src/layman/layer/qgis/wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
get_publication_uuid = empty_method_returns_none


def get_layer_info(workspace, layername, *, x_forwarded_prefix=None):
def get_layer_info(workspace, layername, *, x_forwarded_items=None):
input_file_dir = qgis.get_layer_dir(workspace, layername)
result = {}
if os.path.exists(input_file_dir):
url = layman_util.url_for('rest_workspace_layer_style.get', workspace=workspace, layername=layername, x_forwarded_prefix=x_forwarded_prefix)
url = layman_util.url_for('rest_workspace_layer_style.get', workspace=workspace, layername=layername, x_forwarded_items=x_forwarded_items)
result = {
'name': layername,
'style': {
Expand Down
4 changes: 2 additions & 2 deletions src/layman/layer/rest_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ def get():
app.logger.info(f"GET Layers, actor={g.user}")

actor = get_authn_username()
x_forwarded_prefix = layman_util.get_x_forwarded_items(request.headers)
return rest_common.get_publications(LAYER_TYPE, actor, request_args=request.args, x_forwarded_prefix=x_forwarded_prefix)
x_forwarded_items = layman_util.get_x_forwarded_items(request.headers)
return rest_common.get_publications(LAYER_TYPE, actor, request_args=request.args, x_forwarded_items=x_forwarded_items)
12 changes: 6 additions & 6 deletions src/layman/layer/rest_workspace_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def get(workspace, layername):
# pylint: disable=unused-argument
app.logger.info(f"GET Layer, actor={g.user}")

x_forwarded_prefix = layman_util.get_x_forwarded_items(request.headers)
info = util.get_complete_layer_info(workspace, layername, x_forwarded_prefix=x_forwarded_prefix)
x_forwarded_items = layman_util.get_x_forwarded_items(request.headers)
info = util.get_complete_layer_info(workspace, layername, x_forwarded_items=x_forwarded_items)

return jsonify(info), 200

Expand All @@ -48,7 +48,7 @@ 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_items(request.headers)
x_forwarded_items = layman_util.get_x_forwarded_items(request.headers)

info = layman_util.get_publication_info(workspace, LAYER_TYPE, layername,
context={'keys': ['title', 'name', 'description', 'table_uri', 'geodata_type', 'style_type',
Expand Down Expand Up @@ -262,7 +262,7 @@ def patch(workspace, layername):
)

app.logger.info('PATCH Layer changes done')
info = util.get_complete_layer_info(workspace, layername, x_forwarded_prefix=x_forwarded_prefix)
info = util.get_complete_layer_info(workspace, layername, x_forwarded_items=x_forwarded_items)
info.update(layer_result)

return jsonify(info), 200
Expand All @@ -272,9 +272,9 @@ def patch(workspace, layername):
@util.lock_decorator
def delete_layer(workspace, layername):
app.logger.info(f"DELETE Layer, actor={g.user}")
x_forwarded_prefix = layman_util.get_x_forwarded_items(request.headers)
x_forwarded_items = layman_util.get_x_forwarded_items(request.headers)

info = util.get_complete_layer_info(workspace, layername, x_forwarded_prefix=x_forwarded_prefix)
info = util.get_complete_layer_info(workspace, layername, x_forwarded_items=x_forwarded_items)

util.abort_layer_chain(workspace, layername)

Expand Down
12 changes: 6 additions & 6 deletions src/layman/layer/rest_workspace_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ def get(workspace):
app.logger.info(f"GET Layers, actor={g.user}")

actor = get_authn_username()
x_forwarded_prefix = layman_util.get_x_forwarded_items(request.headers)
return rest_common.get_publications(LAYER_TYPE, actor, request_args=request.args, workspace=workspace, x_forwarded_prefix=x_forwarded_prefix)
x_forwarded_items = layman_util.get_x_forwarded_items(request.headers)
return rest_common.get_publications(LAYER_TYPE, actor, request_args=request.args, workspace=workspace, x_forwarded_items=x_forwarded_items)


@bp.route(f"/{LAYER_REST_PATH_NAME}", methods=['POST'])
def post(workspace):
app.logger.info(f"POST Layers, actor={g.user}")

x_forwarded_prefix = layman_util.get_x_forwarded_items(request.headers)
x_forwarded_items = layman_util.get_x_forwarded_items(request.headers)

# FILE
sent_file_streams = []
Expand Down Expand Up @@ -195,7 +195,7 @@ def post(workspace):
task_options,
)

layerurl = url_for('rest_workspace_layer.get', layername=layername, workspace=workspace, x_forwarded_prefix=x_forwarded_prefix)
layerurl = url_for('rest_workspace_layer.get', layername=layername, workspace=workspace, x_forwarded_items=x_forwarded_items)

layer_result = {
'name': layername,
Expand Down Expand Up @@ -253,7 +253,7 @@ def post(workspace):
def delete(workspace):
app.logger.info(f"DELETE Layers, actor={g.user}")

x_forwarded_prefix = layman_util.get_x_forwarded_items(request.headers)
x_forwarded_items = layman_util.get_x_forwarded_items(request.headers)
infos = layman_util.delete_publications(workspace,
LAYER_TYPE,
util.is_layer_chain_ready,
Expand All @@ -262,6 +262,6 @@ def delete(workspace):
request.method,
'rest_workspace_layer.get',
'layername',
x_forwarded_prefix=x_forwarded_prefix,
x_forwarded_items=x_forwarded_items,
)
return infos, 200
6 changes: 3 additions & 3 deletions src/layman/layer/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def clear_publication_info(layer_info, file_type):
return clear_info


def get_complete_layer_info(workspace, layername, *, x_forwarded_prefix=None):
partial_info = get_layer_info(workspace, layername, context={'x_forwarded_prefix': x_forwarded_prefix})
def get_complete_layer_info(workspace, layername, *, x_forwarded_items=None):
partial_info = get_layer_info(workspace, layername, context={'x_forwarded_items': x_forwarded_items})

if not any(partial_info):
raise LaymanError(15, {'layername': layername})
Expand All @@ -100,7 +100,7 @@ def get_complete_layer_info(workspace, layername, *, x_forwarded_prefix=None):

complete_info.update({
'name': layername,
'url': url_for('rest_workspace_layer.get', layername=layername, workspace=workspace, x_forwarded_prefix=x_forwarded_prefix),
'url': url_for('rest_workspace_layer.get', layername=layername, workspace=workspace, x_forwarded_items=x_forwarded_items),
'title': layername,
'description': '',
})
Expand Down
4 changes: 2 additions & 2 deletions src/layman/map/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ def get_map_info_keys():
}


def get_workspace_publication_url(workspace, publication_name, *, x_forwarded_prefix=None):
return url_for('rest_workspace_map.get', mapname=publication_name, workspace=workspace, x_forwarded_prefix=x_forwarded_prefix)
def get_workspace_publication_url(workspace, publication_name, *, x_forwarded_items=None):
return url_for('rest_workspace_map.get', mapname=publication_name, workspace=workspace, x_forwarded_items=x_forwarded_items)
4 changes: 2 additions & 2 deletions src/layman/map/filesystem/input_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_map_file(workspace, mapname):
return mapfile_path


def get_map_info(workspace, mapname, *, x_forwarded_prefix=None):
def get_map_info(workspace, mapname, *, x_forwarded_items=None):
map_file_path = get_map_file(workspace, mapname)
result = {}
if os.path.exists(map_file_path):
Expand All @@ -46,7 +46,7 @@ def get_map_info(workspace, mapname, *, x_forwarded_prefix=None):
result = {
'file': {
'path': map_file_path,
'url': url_for('rest_workspace_map_file.get', mapname=mapname, workspace=workspace, x_forwarded_prefix=x_forwarded_prefix),
'url': url_for('rest_workspace_map_file.get', mapname=mapname, workspace=workspace, x_forwarded_items=x_forwarded_items),
},
'_file': {
'url': url_for('rest_workspace_map_file.get', mapname=mapname, workspace=workspace, internal=True),
Expand Down
4 changes: 2 additions & 2 deletions src/layman/map/filesystem/thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ def ensure_map_thumbnail_dir(workspace, mapname):
return thumbnail_dir


def get_map_info(workspace, mapname, *, x_forwarded_prefix=None):
def get_map_info(workspace, mapname, *, x_forwarded_items=None):
thumbnail_path = get_map_thumbnail_path(workspace, mapname)
if os.path.exists(thumbnail_path):
return {
'thumbnail': {
'url': url_for('rest_workspace_map_thumbnail.get', workspace=workspace,
mapname=mapname, x_forwarded_prefix=x_forwarded_prefix),
mapname=mapname, x_forwarded_items=x_forwarded_items),
'path': os.path.relpath(thumbnail_path, common_util.get_workspace_dir(workspace))
},
'_thumbnail': {
Expand Down
4 changes: 2 additions & 2 deletions src/layman/map/micka/csw.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
post_map = empty_method


def get_map_info(workspace, mapname, *, x_forwarded_prefix=None):
def get_map_info(workspace, mapname, *, x_forwarded_items=None):
uuid = get_map_uuid(workspace, mapname)
try:
csw = common_util.create_csw()
Expand All @@ -45,7 +45,7 @@ def get_map_info(workspace, mapname, *, x_forwarded_prefix=None):
'csw_url': settings.CSW_PROXY_URL,
'record_url': common_util.get_metadata_url(uuid, url_type=common_util.RecordUrlType.BASIC),
'comparison_url': url_for('rest_workspace_map_metadata_comparison.get', workspace=workspace, mapname=mapname,
x_forwarded_prefix=x_forwarded_prefix),
x_forwarded_items=x_forwarded_items),
}
}
return {}
Expand Down
4 changes: 2 additions & 2 deletions src/layman/map/rest_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ def get():
app.logger.info(f"GET Maps, actor={g.user}")

actor = get_authn_username()
x_forwarded_prefix = layman_util.get_x_forwarded_items(request.headers)
return rest_common.get_publications(MAP_TYPE, actor, request_args=request.args, x_forwarded_prefix=x_forwarded_prefix)
x_forwarded_items = layman_util.get_x_forwarded_items(request.headers)
return rest_common.get_publications(MAP_TYPE, actor, request_args=request.args, x_forwarded_items=x_forwarded_items)
12 changes: 6 additions & 6 deletions src/layman/map/rest_workspace_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def get(workspace, mapname):
# pylint: disable=unused-argument
app.logger.info(f"GET Map, actor={g.user}")

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

return jsonify(info), 200

Expand All @@ -46,7 +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_items(request.headers)
x_forwarded_items = layman_util.get_x_forwarded_items(request.headers)
info = util.get_complete_map_info(workspace, mapname)

# FILE
Expand Down Expand Up @@ -107,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, x_forwarded_prefix=x_forwarded_prefix)
info = util.get_complete_map_info(workspace, mapname, x_forwarded_items=x_forwarded_items)

return jsonify(info), 200

Expand All @@ -116,10 +116,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_items(request.headers)
x_forwarded_items = layman_util.get_x_forwarded_items(request.headers)

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

util.abort_map_chain(workspace, mapname)

Expand Down
Loading

0 comments on commit 5e3245a

Please sign in to comment.