@@ -955,48 +955,29 @@ def to_dict(self) -> Dict[str, Any]:
955955 res_dict ["path_hash_prefixes" ] = self .path_hash_prefixes
956956 return res_dict
957957
958- def visit_child_role (self , target_filepath : str ) -> str :
959- """Determines whether the given 'target_filepath' is an
960- allowed path of DelegatedRole"""
958+ def is_in_trusted_paths (self , target_filepath : str ) -> bool :
959+ """Determines whether the given 'target_filepath'
960+ is in one of the trusted paths of DelegatedRole"""
961961
962962 if self .path_hash_prefixes is not None :
963963 target_filepath_hash = _get_filepath_hash (target_filepath )
964964 for path_hash_prefix in self .path_hash_prefixes :
965- if not target_filepath_hash .startswith (path_hash_prefix ):
966- continue
967-
968- return self .name
965+ if target_filepath_hash .startswith (path_hash_prefix ):
966+ return True
969967
970968 elif self .paths is not None :
971- for path in self .paths :
972- # A child role path may be an explicit path or glob pattern (Unix
973- # shell-style wildcards). The child role 'child_role_name' is
974- # returned if 'target_filepath' is equal to or matches
975- # 'child_role_path'. Explicit filepaths are also considered
976- # matches. A repo maintainer might delegate a glob pattern with a
977- # leading path separator, while the client requests a matching
978- # target without a leading path separator - make sure to strip any
979- # leading path separators so that a match is made.
969+ for pathpattern in self .paths :
970+ # A delegated role path may be an explicit path or glob
971+ # pattern (Unix shell-style wildcards). Explicit filepaths
972+ # are also considered matches. Make sure to strip any leading
973+ # path separators so that a match is made.
980974 # Example: "foo.tgz" should match with "/*.tgz".
981975 if fnmatch .fnmatch (
982- target_filepath .lstrip (os .sep ), path .lstrip (os .sep )
976+ target_filepath .lstrip (os .sep ), pathpattern .lstrip (os .sep )
983977 ):
978+ return True
984979
985- return self .name
986-
987- continue
988-
989- else :
990- # 'role_name' should have been validated when it was downloaded.
991- # The 'paths' or 'path_hash_prefixes' fields should not be missing,
992- # so we raise a format error here in case they are both missing.
993- raise exceptions .FormatError (
994- repr (self .name ) + " "
995- 'has neither a "paths" nor "path_hash_prefixes". At least'
996- " one of these attributes must be present."
997- )
998-
999- return None
980+ return False
1000981
1001982
1002983def _get_filepath_hash (target_filepath , hash_function = "sha256" ):
0 commit comments