Skip to content

Commit

Permalink
review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mishaschwartz committed Dec 10, 2024
1 parent 2c78cf5 commit f4ee09a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/services.rst
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ by the below configuration.
API entrypoint and `Tomcat` service running it. If this feature is not needed, it can be disabled by setting the
parameter to ``null``.

.. versionchanged:: 4.1.2
.. versionchanged:: 4.2.0
``prefixes`` can now contain a ``/`` character. This allows `ServiceTHREDDS`_ to properly handle `THREDDS`_ services
that have multiple path parts. For example, starting with `THREDDS`_ version 5, the ``ncss`` service contains two
sub-services which are accessed using the path prefixes ``ncss/grid`` and ``ncss/point``.
Expand Down
13 changes: 7 additions & 6 deletions magpie/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,14 +1385,15 @@ def get_path_parts(self):
def _get_path_prefix_permission(self, path_parts):
# type: (List[str]) -> Tuple[Optional[Str], PermissionRequested]
cfg = self.get_config()
# first to favor BROWSE over READ prefix conflicts
for prefixes, permission in ((cfg["metadata_type"]["prefixes"], Permission.BROWSE),
(cfg["data_type"]["prefixes"], Permission.READ)):
for prefix in prefixes:
if not path_parts and prefix is None:
return prefix, permission
if prefix is not None:
path_prefix = "/".join(path_parts[:prefix.count("/") + 1])
if self.is_match(path_prefix, prefix) is not None:
for pattern_prefix in prefixes:
if not path_parts and pattern_prefix is None:
return pattern_prefix, permission
if pattern_prefix is not None:
path_prefix = "/".join(path_parts[:pattern_prefix.count("/") + 1])
if self.is_match(path_prefix, pattern_prefix) is not None:
return path_prefix, permission
return None, None

Expand Down
2 changes: 1 addition & 1 deletion tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def test_ServiceTHREDDS_custom_config(self):

# using unknown prefixes, otherwise allowed file should always be denied
# purposely take normally allowed THREDDS prefixes, validate active config
unknown_prefixes = ["ncml", "dap4", "ncss/point"]
unknown_prefixes = ["ncml", "dap4", "ncss/point", "ncss", "grid"]
allowed_resources = [dir_name, "{}/{}".format(dir_name, file_name), "{}/{}".format(dir_name, file_html_name)]
for prefix in unknown_prefixes:
for target in allowed_resources:
Expand Down

0 comments on commit f4ee09a

Please sign in to comment.