Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions vulnerabilities/package_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ def get(self, package_name: str) -> Set[str]:
return self.cache.get(package_name, set())


def client_session():
return ClientSession(raise_for_status=True, trust_env=True)


class LaunchpadVersionAPI(VersionAPI):

package_type = "deb"

async def load_api(self, pkg_set):
async with ClientSession(raise_for_status=True) as session:
async with client_session() as session:
await asyncio.gather(
*[self.set_api(pkg, session) for pkg in pkg_set if pkg not in self.cache]
)
Expand Down Expand Up @@ -82,7 +86,7 @@ class PypiVersionAPI(VersionAPI):
package_type = "pypi"

async def load_api(self, pkg_set):
async with ClientSession(raise_for_status=True) as session:
async with client_session() as session:
await asyncio.gather(
*[self.fetch(pkg, session) for pkg in pkg_set if pkg not in self.cache]
)
Expand All @@ -106,7 +110,7 @@ class CratesVersionAPI(VersionAPI):
package_type = "cargo"

async def load_api(self, pkg_set):
async with ClientSession(raise_for_status=True) as session:
async with client_session() as session:
await asyncio.gather(
*[self.fetch(pkg, session) for pkg in pkg_set if pkg not in self.cache]
)
Expand All @@ -127,7 +131,7 @@ class RubyVersionAPI(VersionAPI):
package_type = "gem"

async def load_api(self, pkg_set):
async with ClientSession(raise_for_status=True) as session:
async with client_session() as session:
await asyncio.gather(
*[self.fetch(pkg, session) for pkg in pkg_set if pkg not in self.cache]
)
Expand All @@ -151,7 +155,7 @@ class NpmVersionAPI(VersionAPI):
package_type = "npm"

async def load_api(self, pkg_set):
async with ClientSession(raise_for_status=True) as session:
async with client_session() as session:
await asyncio.gather(
*[self.fetch(pkg, session) for pkg in pkg_set if pkg not in self.cache]
)
Expand Down Expand Up @@ -211,7 +215,7 @@ class MavenVersionAPI(VersionAPI):
package_type = "maven"

async def load_api(self, pkg_set):
async with ClientSession(raise_for_status=True) as session:
async with client_session() as session:
await asyncio.gather(
*[self.fetch(pkg, session) for pkg in pkg_set if pkg not in self.cache]
)
Expand Down Expand Up @@ -267,7 +271,7 @@ class NugetVersionAPI(VersionAPI):
package_type = "nuget"

async def load_api(self, pkg_set):
async with ClientSession(raise_for_status=True) as session:
async with client_session() as session:
await asyncio.gather(
*[self.fetch(pkg, session) for pkg in pkg_set if pkg not in self.cache]
)
Expand Down Expand Up @@ -305,7 +309,7 @@ class ComposerVersionAPI(VersionAPI):
package_type = "composer"

async def load_api(self, pkg_set):
async with ClientSession(raise_for_status=True) as session:
async with client_session() as session:
await asyncio.gather(
*[self.fetch(pkg, session) for pkg in pkg_set if pkg not in self.cache]
)
Expand Down Expand Up @@ -343,7 +347,7 @@ class GitHubTagsAPI(VersionAPI):
package_type = "github"

async def load_api(self, repo_set):
async with ClientSession(raise_for_status=True) as session:
async with client_session() as session:
await asyncio.gather(
*[
self.fetch(owner_repo.lower(), session)
Expand All @@ -363,7 +367,7 @@ async def fetch(self, owner_repo: str, session) -> None:

class HexVersionAPI(VersionAPI):
async def load_api(self, pkg_set):
async with ClientSession(raise_for_status=True) as session:
async with client_session() as session:
await asyncio.gather(
*[self.fetch(pkg, session) for pkg in pkg_set if pkg not in self.cache]
)
Expand Down