This repository has been archived by the owner on Sep 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from RickBarretto/issue1
Issue #1
- Loading branch information
Showing
3 changed files
with
58 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,44 @@ | ||
"""Fetch the OSV API""" | ||
|
||
import requests | ||
from requests.exceptions import HTTPError | ||
|
||
from src.core.utils.osv_model import OsvModel, OsvUrl | ||
from src.core.utils.exceptions import PackageNotFound | ||
|
||
|
||
def fetch_api(osv_model: OsvModel) -> dict: | ||
"""Fetch the OSV API and return a Json""" | ||
import requests | ||
|
||
|
||
class OsvApi: | ||
"""Deal with OsvApi to get package Vulnerabilities | ||
usage: | ||
>>> django_pkg = OsvModel("Django", "3.0") | ||
>>> response = OsvApi(django_pkg).fetch() | ||
{...} | ||
""" | ||
|
||
def __init__(self, osv_parameters: OsvModel): | ||
|
||
# Attributes | ||
self.api_parameters = osv_parameters.get_data() | ||
|
||
def fetch(self): | ||
json: dict = self.__request() | ||
if json: | ||
return json | ||
else: | ||
raise PackageNotFound | ||
|
||
def __request(self) -> dict: | ||
"""Fetch the OSV API and return a Json""" | ||
|
||
osv_link = "https://api.osv.dev/v1/query" | ||
|
||
osv_link = OsvUrl().get_url() | ||
osv_model = osv_model.get_data() | ||
response = requests.post(osv_link, data=self.api_parameters, timeout=3.05) | ||
response.raise_for_status() | ||
|
||
response = requests.post(osv_link, data=osv_model) | ||
json = response.json() | ||
|
||
return response.json() | ||
return json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class PackageNotFound(Exception): | ||
pass |