-
-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathfetchcode_utils.py
More file actions
35 lines (29 loc) · 1.22 KB
/
fetchcode_utils.py
File metadata and controls
35 lines (29 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# VulnerableCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#
import logging
from traceback import format_exc as traceback_format_exc
from typing import Callable
from typing import Union
from fetchcode.package_versions import SUPPORTED_ECOSYSTEMS as FETCHCODE_SUPPORTED_ECOSYSTEMS
from fetchcode.package_versions import versions
from packageurl import PackageURL
def get_versions(purl: Union[PackageURL, str], logger: Callable = None):
"""Return set of known versions for the given purl."""
if isinstance(purl, str):
purl = PackageURL.from_string(purl)
if purl.type not in FETCHCODE_SUPPORTED_ECOSYSTEMS:
return
try:
return {v.value.lstrip("vV") for v in versions(str(purl))}
except Exception as e:
if logger:
logger(
f"Error while fetching known versions for {purl!s}: {e!r} \n {traceback_format_exc()}",
level=logging.ERROR,
)