43
43
from macaron .config .defaults import defaults
44
44
from macaron .config .global_config import global_config
45
45
from macaron .errors import CloneError , RepoCheckOutError
46
- from macaron .repo_finder import to_domain_from_known_purl_types
46
+ from macaron .repo_finder import repo_finder_pypi , to_domain_from_known_purl_types
47
47
from macaron .repo_finder .commit_finder import find_commit , match_tags
48
48
from macaron .repo_finder .repo_finder_base import BaseRepoFinder
49
49
from macaron .repo_finder .repo_finder_deps_dev import DepsDevRepoFinder
66
66
list_remote_references ,
67
67
resolve_local_path ,
68
68
)
69
+ from macaron .slsa_analyzer .specs .package_registry_spec import PackageRegistryInfo
69
70
70
71
logger : logging .Logger = logging .getLogger (__name__ )
71
72
72
73
73
- def find_repo (purl : PackageURL , check_latest_version : bool = True ) -> tuple [str , RepoFinderInfo ]:
74
+ def find_repo (
75
+ purl : PackageURL ,
76
+ check_latest_version : bool = True ,
77
+ package_registries_info : list [PackageRegistryInfo ] | None = None ,
78
+ ) -> tuple [str , RepoFinderInfo ]:
74
79
"""Retrieve the repository URL that matches the given PURL.
75
80
76
81
Parameters
@@ -79,6 +84,9 @@ def find_repo(purl: PackageURL, check_latest_version: bool = True) -> tuple[str,
79
84
The parsed PURL to convert to the repository path.
80
85
check_latest_version: bool
81
86
A flag that determines whether the latest version of the PURL is also checked.
87
+ package_registries_info: list[PackageRegistryInfo] | None
88
+ The list of package registry information if available.
89
+ If no package registries are loaded, this can be set to None.
82
90
83
91
Returns
84
92
-------
@@ -103,6 +111,9 @@ def find_repo(purl: PackageURL, check_latest_version: bool = True) -> tuple[str,
103
111
logger .debug ("Analyzing %s with Repo Finder: %s" , purl , type (repo_finder ))
104
112
found_repo , outcome = repo_finder .find_repo (purl )
105
113
114
+ if not found_repo :
115
+ found_repo , outcome = find_repo_alternative (purl , outcome , package_registries_info )
116
+
106
117
if check_latest_version and not defaults .getboolean ("repofinder" , "try_latest_purl" , fallback = True ):
107
118
check_latest_version = False
108
119
@@ -117,13 +128,49 @@ def find_repo(purl: PackageURL, check_latest_version: bool = True) -> tuple[str,
117
128
return "" , RepoFinderInfo .NO_NEWER_VERSION
118
129
119
130
found_repo , outcome = DepsDevRepoFinder ().find_repo (latest_version_purl )
131
+ if found_repo :
132
+ return found_repo , outcome
133
+
134
+ if not found_repo :
135
+ found_repo , outcome = find_repo_alternative (latest_version_purl , outcome , package_registries_info )
136
+
120
137
if not found_repo :
121
138
logger .debug ("Could not find repo from latest version of PURL: %s" , latest_version_purl )
122
139
return "" , RepoFinderInfo .LATEST_VERSION_INVALID
123
140
124
141
return found_repo , outcome
125
142
126
143
144
+ def find_repo_alternative (
145
+ purl : PackageURL , outcome : RepoFinderInfo , package_registries_info : list [PackageRegistryInfo ] | None = None
146
+ ) -> tuple [str , RepoFinderInfo ]:
147
+ """Use PURL type specific methods to find the repository when the standard methods have failed.
148
+
149
+ Parameters
150
+ ----------
151
+ purl : PackageURL
152
+ The parsed PURL to convert to the repository path.
153
+ outcome: RepoFinderInfo
154
+ A previous outcome to report if this method does nothing.
155
+ package_registries_info: list[PackageRegistryInfo] | None
156
+ The list of package registry information if available.
157
+ If no package registries are loaded, this can be set to None.
158
+
159
+ Returns
160
+ -------
161
+ tuple[str, RepoFinderOutcome] :
162
+ The repository URL for the passed package, if found, and the outcome to report.
163
+ """
164
+ found_repo = ""
165
+ if purl .type == "pypi" :
166
+ found_repo , outcome = repo_finder_pypi .find_repo (purl , package_registries_info )
167
+
168
+ if not found_repo :
169
+ logger .debug ("Could not find repository using type specific (%s) methods for PURL: %s" , purl .type , purl )
170
+
171
+ return found_repo , outcome
172
+
173
+
127
174
def to_repo_path (purl : PackageURL , available_domains : list [str ]) -> str | None :
128
175
"""Return the repository path from the PURL string.
129
176
0 commit comments