Skip to content

Commit 9420157

Browse files
committed
Ingest npm data through github api
Signed-off-by: Tushar Goel <[email protected]>
1 parent 5dabfc9 commit 9420157

File tree

8 files changed

+10367
-7
lines changed

8 files changed

+10367
-7
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Version v31.1.0
1010
- We are now handling purl fragments in package search. For example:
1111
you can now serch using queries in the UI like this : `[email protected]`,
1212
`cherrypy` or `pkg:pypi`.
13+
- We are now ingesting npm advisories data through GitHub API.
1314

1415

1516
Version v31.0.0

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ MarkupSafe==2.1.1
5454
matplotlib-inline==0.1.3
5555
multidict==6.0.2
5656
mypy-extensions==0.4.3
57-
packageurl-python==0.10.3
57+
packageurl-python==0.10.5rc1
5858
packaging==21.3
5959
paramiko==2.10.3
6060
parso==0.8.3

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ install_requires =
6969
coreapi>=2.3.3
7070

7171
#essentials
72-
packageurl-python>=0.9.4
72+
packageurl-python>=0.10.4
7373
univers>=30.9.0
7474
license-expression>=21.6.14
7575

vulnerabilities/importers/github.py

Lines changed: 5 additions & 3 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

@@ -122,8 +123,9 @@
122123
}
123124

124125
# TODO: We will try to gather more info from GH API
126+
# Check https://github.com/nexB/vulnerablecode/issues/1039#issuecomment-1366458885
125127
# Check https://github.com/nexB/vulnerablecode/issues/645
126-
# set of all possible values of first '%s' = {'MAVEN','COMPOSER', 'NUGET', 'RUBYGEMS', 'PYPI'}
128+
# set of all possible values of first '%s' = {'MAVEN','COMPOSER', 'NUGET', 'RUBYGEMS', 'PYPI', 'NPM'}
127129
# second '%s' is interesting, it will have the value '' for the first request,
128130
GRAPHQL_QUERY_TEMPLATE = """
129131
query{
@@ -202,13 +204,13 @@ def get_purl(pkg_type: str, github_name: str) -> Optional[PackageURL]:
202204
ns, _, name = github_name.partition(":")
203205
return PackageURL(type=pkg_type, namespace=ns, name=name)
204206

205-
if pkg_type == "composer":
207+
if pkg_type in ("composer", "npm"):
206208
if "/" not in github_name:
207209
return PackageURL(type=pkg_type, name=github_name)
208210
vendor, _, name = github_name.partition("/")
209211
return PackageURL(type=pkg_type, namespace=vendor, name=name)
210212

211-
if pkg_type in ("nuget", "pypi", "gem", "golang"):
213+
if pkg_type in ("nuget", "pypi", "gem", "golang", "npm"):
212214
return PackageURL(type=pkg_type, name=github_name)
213215

214216
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)