-
Notifications
You must be signed in to change notification settings - Fork 202
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
Add Gitlab datasource #883
Add Gitlab datasource #883
Conversation
cd1ee0b
to
06265f6
Compare
06265f6
to
55fc8a8
Compare
vulntotal/datasources/gitlab.py
Outdated
os.remove(response.location) | ||
|
||
|
||
def clear_download(location): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add docstring
vulntotal/datasources/gitlab.py
Outdated
return f"{ecosystem}/{package_name}" | ||
|
||
|
||
def download_subtree(package_slug: str, speculative_execution=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add docstring
vulntotal/datasources/gitlab.py
Outdated
} | ||
|
||
|
||
def get_package_slug(purl): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add docstring
vulntotal/datasources/gitlab.py
Outdated
shutil.rmtree(location) | ||
|
||
|
||
def get_casesensitive_slug(path, package_slug): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add docstring
vulntotal/datasources/gitlab.py
Outdated
|
||
while hasnext: | ||
response = requests.post(url, json=payload).json() | ||
paginated_tree = response[0]["data"]["project"]["repository"]["paginatedTree"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check get_item
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, that won't work here.
>>> from vulnerabilities.utils import get_item
>>> data = [
... {
... "data": {
... "project": {
... "repository": {
... "paginatedTree": {
... "pageInfo": {
... "endCursor": "e1d88bf61d8f6e2d39bdae52121d2c19e0a86ea6",
... "startCursor": "",
... "hasNextPage": True
... },
... "nodes": [
... {
... "trees": {
... "nodes": [
... {
... "flatPath": "pypi/AccessControl"
... },
... {
... "flatPath": "pypi/Acqusition"
... },
... {
... "flatPath": "pypi/Beaker"
... }
... ]
... }
... }
... ]
... }
... }
... }
... }
... }
... ]
>>> get_item(data, 0, 'data', 'project', 'repository', 'paginatedTree')
dictionary must be of type `dict
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant this
paginated_tree = response[0]["data"]["project"]["repository"]["paginatedTree"] | |
assert len(response) > 0 | |
data = response[0] | |
paginated_tree = get_item(data, "data", "project", "repository", "paginatedTree") |
You are not checking if the item you are accesing exists in the dictionary or not
vulntotal/datasources/gitlab.py
Outdated
paginated_tree = response[0]["data"]["project"]["repository"]["paginatedTree"] | ||
|
||
for slug in paginated_tree["nodes"][0]["trees"]["nodes"]: | ||
if slug["flatPath"].lower() == package_slug.lower(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check get_item
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check my comment above for same.
vulntotal/datasources/gitlab.py
Outdated
|
||
|
||
def parse_interesting_advisories(location, version, delete_download=False) -> Iterable[VendorData]: | ||
path = Path(location) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add docstring
vulntotal/datasources/gitlab.py
Outdated
if package_slug.lower().startswith(slug["flatPath"].lower()): | ||
return get_gitlab_style_slug(slug["flatPath"], package_slug) | ||
|
||
payload[0]["variables"]["nextPageCursor"] = paginated_tree["pageInfo"]["endCursor"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check get_item
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check my comment above for same.
Add doctsrings for all the functions and also add doctests/ unit tests for functions which have not been tested at all |
closes #836