@@ -1033,48 +1033,29 @@ def to_dict(self) -> Dict[str, Any]:
10331033 res_dict ["path_hash_prefixes" ] = self .path_hash_prefixes
10341034 return res_dict
10351035
1036- def visit_child_role (self , target_filepath : str ) -> str :
1037- """Determines whether the given 'target_filepath' is an
1038- allowed path of DelegatedRole"""
1036+ def is_in_trusted_paths (self , target_filepath : str ) -> bool :
1037+ """Determines whether the given 'target_filepath'
1038+ is in one of the trusted paths of DelegatedRole"""
10391039
10401040 if self .path_hash_prefixes is not None :
10411041 target_filepath_hash = _get_filepath_hash (target_filepath )
10421042 for path_hash_prefix in self .path_hash_prefixes :
1043- if not target_filepath_hash .startswith (path_hash_prefix ):
1044- continue
1045-
1046- return self .name
1043+ if target_filepath_hash .startswith (path_hash_prefix ):
1044+ return True
10471045
10481046 elif self .paths is not None :
1049- for path in self .paths :
1050- # A child role path may be an explicit path or glob pattern (Unix
1051- # shell-style wildcards). The child role 'child_role_name' is
1052- # returned if 'target_filepath' is equal to or matches
1053- # 'child_role_path'. Explicit filepaths are also considered
1054- # matches. A repo maintainer might delegate a glob pattern with a
1055- # leading path separator, while the client requests a matching
1056- # target without a leading path separator - make sure to strip any
1057- # leading path separators so that a match is made.
1047+ for pathpattern in self .paths :
1048+ # A delegated role path may be an explicit path or glob
1049+ # pattern (Unix shell-style wildcards). Explicit filepaths
1050+ # are also considered matches. Make sure to strip any leading
1051+ # path separators so that a match is made.
10581052 # Example: "foo.tgz" should match with "/*.tgz".
10591053 if fnmatch .fnmatch (
1060- target_filepath .lstrip (os .sep ), path .lstrip (os .sep )
1054+ target_filepath .lstrip (os .sep ), pathpattern .lstrip (os .sep )
10611055 ):
1056+ return True
10621057
1063- return self .name
1064-
1065- continue
1066-
1067- else :
1068- # 'role_name' should have been validated when it was downloaded.
1069- # The 'paths' or 'path_hash_prefixes' fields should not be missing,
1070- # so we raise a format error here in case they are both missing.
1071- raise exceptions .FormatError (
1072- repr (self .name ) + " "
1073- 'has neither a "paths" nor "path_hash_prefixes". At least'
1074- " one of these attributes must be present."
1075- )
1076-
1077- return None
1058+ return False
10781059
10791060
10801061def _get_filepath_hash (target_filepath , hash_function = "sha256" ):
0 commit comments