Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add missing docstrings to data_sources/curl_source.py #3464 #3475

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions cve_bin_tool/data_sources/curl_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@


class Curl_Source(Data_Source):
"""
Represents a data source for retrieving information about vulnerabilities in cURL.
"""
SOURCE = "Curl"
CACHEDIR = DISK_LOCATION_DEFAULT
BACKUPCACHEDIR = DISK_LOCATION_BACKUP
LOGGER = LOGGER.getChild("CVEDB")
DATA_SOURCE_LINK = "https://curl.se/docs/vuln.json"

def __init__(self, error_mode=ErrorMode.TruncTrace):
"""
Initialize a Curl_Source instance.

Args:
error_mode (ErrorMode): The error mode to be used.
"""
self.cve_list = None
self.cachedir = self.CACHEDIR
self.backup_cachedir = self.BACKUPCACHEDIR
Expand All @@ -40,12 +49,23 @@ def __init__(self, error_mode=ErrorMode.TruncTrace):
self.vulnerability_data = []

async def get_cve_data(self):
"""
Get cURL vulnerability data.

Fetches the cURL vulnerability data and retrieves a list of affected data.

Returns:
Tuple[Union[None, Any], str]: A tuple containing the affected data and the source name.
"""
await self.fetch_cves()
self.get_cve_list()

return (None, self.affected_data), self.source_name

async def fetch_cves(self):
"""
btwshivam marked this conversation as resolved.
Show resolved Hide resolved
Fetch cURL vulnerabilities data.
"""
if not self.session:
connector = aiohttp.TCPConnector(limit_per_host=19)
self.session = RateLimiter(
Expand All @@ -57,6 +77,12 @@ async def fetch_cves(self):
await self.session.close()

async def download_curl_vulnerabilities(self, session: RateLimiter) -> None:
"""
Download cURL vulnerability data and save it to a file.

Args:
session (RateLimiter): The session to use for the HTTP request.
"""
async with await session.get(self.DATA_SOURCE_LINK) as response:
response.raise_for_status()
self.vulnerability_data = await response.json()
Expand All @@ -66,6 +92,9 @@ async def download_curl_vulnerabilities(self, session: RateLimiter) -> None:
await f.write(json.dumps(self.vulnerability_data, indent=4))

def get_cve_list(self):
"""
Get a list of affected cURL vulnerabilities.
"""
self.affected_data = []

for cve in self.vulnerability_data:
Expand Down
Loading