File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #
2+ # Copyright (c) nexB Inc. and others. All rights reserved.
3+ # VulnerableCode is a trademark of nexB Inc.
4+ # SPDX-License-Identifier: Apache-2.0
5+ # See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+ # See https://github.com/nexB/vulnerablecode for support or download.
7+ # See https://aboutcode.org for more information about nexB OSS projects.
8+ #
Original file line number Diff line number Diff line change 1+ #
2+ # Copyright (c) nexB Inc. and others. All rights reserved.
3+ # VulnerableCode is a trademark of nexB Inc.
4+ # SPDX-License-Identifier: Apache-2.0
5+ # See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+ # See https://github.com/nexB/vulnerablecode for support or download.
7+ # See https://aboutcode.org for more information about nexB OSS projects.
8+ #
9+
10+ from urllib .parse import urljoin
11+
12+ import requests
13+
14+
15+ def get_closest_nuget_package_name (query ):
16+ """
17+ Return case-sensitive NuGet package name using
18+ SearchQueryService provided by NuGet
19+ """
20+ url_nuget_service = "https://api.nuget.org/v3/index.json"
21+ url_nuget_search = ""
22+
23+ api_resources = requests .get (url_nuget_service ).json ()
24+ for resource in api_resources .get ("resources" ) or []:
25+ if resource .get ("@type" ) == "SearchQueryService" :
26+ url_nuget_search = resource ["@id" ]
27+ break
28+
29+ if url_nuget_search :
30+ url_query = urljoin (url_nuget_search , f"?q={ query } " )
31+ query_response = requests .get (url_query ).json ()
32+ if query_response .get ("data" ):
33+ return query_response ["data" ][0 ]["id" ]
You can’t perform that action at this time.
0 commit comments