-
Notifications
You must be signed in to change notification settings - Fork 210
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 istio importer and tests #336
Conversation
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.
Thank you for this! I have added a few comments for your consideration.
vulnerabilities/importers/istio.py
Outdated
|
||
safe_pkg_versions = [] | ||
vuln_pkg_versions = [] | ||
all_version_list = self.version_api.get("istio/istio") |
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.
what do you gain from suffixing your variable names with a type? Would not versions
or all_version
be better than all_version_list
?
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.
Sure, I would change them.
vulnerabilities/importers/istio.py
Outdated
cve_id = cve_id | ||
|
||
safe_purls = { | ||
PackageURL(name="istio", type="golang", version=version) |
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.
In the logical order of fields, type would go first
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.
Ok
vulnerabilities/importers/istio.py
Outdated
} | ||
|
||
vuln_purls = { | ||
PackageURL(name="istio", type="golang", version=version) |
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.
What about also creating github
type purls?
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.
Sure
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.
@pombredanne I am still unable to understand how to create two package types for a single purl. Can you explain it a bit.
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.
@tushar912 sorry if I was not clear: I meant to have multiple purls: one pkg:/golang
and one pkg:github
since the project has both personalities
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.
Oh Ok
@pombredanne @sbs2001 I have made some changes as per the suggestions made by you. Please review again. |
vulnerabilities/importers/istio.py
Outdated
safe_pkg_versions = [] | ||
vuln_pkg_versions = [] | ||
all_version_list = self.version_api.get("istio/istio") | ||
if not version_range_list: |
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.
the condition and all_version
should be at top. We don't want to create objects just to have them destroyed.
vulnerabilities/importers/istio.py
Outdated
all_version_list = self.version_api.get("istio/istio") | ||
if not version_range_list: | ||
return all_version_list, [] | ||
version_ranges = {RangeSpecifier(r) for r in version_range_list} |
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.
@pombredanne The codebase has (over) use of sets all over the place mostly because we were paranoid of duplicates and order didn't matter.
@tushar912 use a list, if that's ok ?
vulnerabilities/importers/istio.py
Outdated
ubound = "<=" + release[2] | ||
releases.append(lbound + "," + ubound) | ||
|
||
data["releases"] = releases |
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.
This a list of string version ranges now, change the key name here to something that reflects that
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.
Sure
vulnerabilities/importers/istio.py
Outdated
safe_purls = [] | ||
vuln_purls = [] | ||
|
||
cve_id = cve_id |
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.
Why ?
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.
Oh, I should remove this
73b81f6
to
e2ad923
Compare
@sbs2001 I have made the changes. |
vulnerabilities/importers/istio.py
Outdated
safe_pkg_versions, vuln_pkg_versions = self.get_versions_for_pkg_from_range_list( | ||
data["release_ranges"]) | ||
|
||
safe_purls = [] |
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.
Is there a need to declare this here, since you are assigning them the union below ?
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 should remove it.
vulnerabilities/importers/istio.py
Outdated
advisories.extend(processed_data) | ||
return self.batch_advisories(advisories) | ||
|
||
def get_versions_for_pkg_from_range_list(self, version_range_list): |
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.
The function name is too verbose. How about get_pkg_versions_from_ranges
?
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.
Sure
@sbs2001 I have made the changes, also can you answer #336 (comment). |
vulnerabilities/importers/istio.py
Outdated
ubound = "<=" + release[2] | ||
releases.append(lbound + "," + ubound) | ||
# If it is a single release | ||
elif isinstance(release, int): |
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.
Could you point me to an example of this ?
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.
Could this be done without using isinstance
? This is going to fail in case the release is of form 1.x.y
. Maybe some string check ?
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.
Should I use a regex check?
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 would try to avoid regex unless absolutely needed, because those are very cryptic when reading.
If there's no other way could you do something like https://github.com/nexB/vulnerablecode/blob/f81816fcd95d00736dc17c9aaad20e91cb6ce201/vulnerabilities/helpers.py#L81 ?
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.
That way atleast, it would be easy to understand what the regex is trying to do without going into the details.
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.
@tushar912 thanks this almost at a stage to be merged, please see my comments inline.
@tushar912 Due to recent model changes, you would need to rename |
d90ab42
to
b1f563a
Compare
vulnerabilities/importers/istio.py
Outdated
as parameter and returns a tuple of safe package versions and | ||
vulnerable package versions""" | ||
all_version = self.version_api.get("istio/istio") | ||
# if not version_range_list: |
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 guess this can be removed now ?
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.
Oh I missed this. I will remove it.
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.
See my comment of usage of isinstance
and remove the commented code and we're good to merge :)
Signed-off-by: Tushar912 <[email protected]>
Signed-off-by: Tushar912 <[email protected]>
Also add github as package type Signed-off-by: Tushar912 <[email protected]>
d8e4ec3
to
5b6c5dd
Compare
@sbs2001 Sorry for the delay. I have added a better check for single release using regex. |
assign cve to empty string if its N/A Signed-off-by: Tushar912 <[email protected]>
ubound = "<=" + release[2] | ||
releases.append(lbound + "," + ubound) | ||
# If it is a single release | ||
elif is_release(release): |
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.
Nice
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.
Thanks @tushar912 for your patience and I'm merging this.
Description
Added importer and tests for istio
Also added test files in
test_data/istio
Fixes #302