Skip to content

Commit

Permalink
Deprecate DelegatedRole.is_delegated_path()
Browse files Browse the repository at this point in the history
Deprecate DelegatedRole.is_delegated_path() in favor of
DelegatedRole.find_delegations() which will not only check if the
given targetpath is one of the paths DelegatedRole is trusted to
provide, but it will also return the role name.
This is especially useful when using succinct hash delegations.

Signed-off-by: Martin Vrachev <[email protected]>
  • Loading branch information
MVrachev committed Apr 15, 2022
1 parent 220e11c commit f0e4410
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tuf/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io
import logging
import tempfile
import warnings
from datetime import datetime
from typing import (
IO,
Expand Down Expand Up @@ -1522,7 +1523,9 @@ def find_delegation(self, target_filepath: str) -> Optional[str]:
return None

def is_delegated_path(self, target_filepath: str) -> bool:
"""Determines whether the given ``target_filepath`` is in one of
"""This method is depricated, use find_delegation instead!
Determines whether the given ``target_filepath`` is in one of
the paths that ``DelegatedRole`` is trusted to provide.
The ``target_filepath`` and the ``DelegatedRole`` paths are expected to be
Expand All @@ -1536,6 +1539,9 @@ def is_delegated_path(self, target_filepath: str) -> bool:
targets URL.
"""

msg = "is_delegated_path is depricated, use find_delegation instead!"
warnings.warn(msg, DeprecationWarning)

if self.path_hash_prefixes is not None:
# Calculate the hash of the filepath
# to determine in which bin to find the target.
Expand All @@ -1554,6 +1560,10 @@ def is_delegated_path(self, target_filepath: str) -> bool:
if self._is_target_in_pathpattern(target_filepath, pathpattern):
return True

elif self.succinct_hash_info is not None:
# All targetpaths have a bin and are considered as trusted.
return True

return False


Expand Down

0 comments on commit f0e4410

Please sign in to comment.