Skip to content

Commit 6898f09

Browse files
committed
Ingest npm data through github api
Signed-off-by: Tushar Goel <[email protected]>
1 parent 465a171 commit 6898f09

File tree

5 files changed

+10362
-4
lines changed

5 files changed

+10362
-4
lines changed

vulnerabilities/importers/github.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
"COMPOSER": "composer",
115115
"PIP": "pypi",
116116
"RUBYGEMS": "gem",
117+
"NPM": "npm",
117118
# "GO": "golang",
118119
}
119120

@@ -123,7 +124,7 @@
123124

124125
# TODO: We will try to gather more info from GH API
125126
# Check https://github.com/nexB/vulnerablecode/issues/645
126-
# set of all possible values of first '%s' = {'MAVEN','COMPOSER', 'NUGET', 'RUBYGEMS', 'PYPI'}
127+
# set of all possible values of first '%s' = {'MAVEN','COMPOSER', 'NUGET', 'RUBYGEMS', 'PYPI', 'NPM'}
127128
# second '%s' is interesting, it will have the value '' for the first request,
128129
GRAPHQL_QUERY_TEMPLATE = """
129130
query{
@@ -208,7 +209,7 @@ def get_purl(pkg_type: str, github_name: str) -> Optional[PackageURL]:
208209
vendor, _, name = github_name.partition("/")
209210
return PackageURL(type=pkg_type, namespace=vendor, name=name)
210211

211-
if pkg_type in ("nuget", "pypi", "gem", "golang"):
212+
if pkg_type in ("nuget", "pypi", "gem", "golang", "npm"):
212213
return PackageURL(type=pkg_type, name=github_name)
213214

214215
logger.error(f"get_purl: Unknown package type {pkg_type}")

vulnerabilities/package_managers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ class NpmVersionAPI(VersionAPI):
266266
package_type = "npm"
267267

268268
def fetch(self, pkg):
269-
url = f"https://registry.npmjs.org/{pkg}"
269+
lower_pkg = pkg.lower()
270+
url = f"https://registry.npmjs.org/{lower_pkg}"
270271
response = get_response(url=url, content_type="json")
271272
if not response:
272273
logger.error(f"Failed to fetch {url}")

0 commit comments

Comments
 (0)