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

Add istio importer and tests #336

Merged
merged 5 commits into from
Mar 14, 2021
Merged

Add istio importer and tests #336

merged 5 commits into from
Mar 14, 2021

Conversation

tushar912
Copy link
Contributor

@tushar912 tushar912 commented Feb 5, 2021

Description

Added importer and tests for istio
Also added test files in test_data/istio

Fixes #302

vulnerabilities/importers/istio.py Outdated Show resolved Hide resolved
vulnerabilities/importers/istio.py Outdated Show resolved Hide resolved
vulnerabilities/importers/istio.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@pombredanne pombredanne left a 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/importer_yielder.py Outdated Show resolved Hide resolved
vulnerabilities/importers/istio.py Show resolved Hide resolved
vulnerabilities/importers/istio.py Show resolved Hide resolved
vulnerabilities/importers/istio.py Outdated Show resolved Hide resolved

safe_pkg_versions = []
vuln_pkg_versions = []
all_version_list = self.version_api.get("istio/istio")
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

cve_id = cve_id

safe_purls = {
PackageURL(name="istio", type="golang", version=version)
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

}

vuln_purls = {
PackageURL(name="istio", type="golang", version=version)
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Contributor Author

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.

Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh Ok

vulnerabilities/importers/istio.py Outdated Show resolved Hide resolved
vulnerabilities/tests/test_istio.py Show resolved Hide resolved
@tushar912
Copy link
Contributor Author

@pombredanne @sbs2001 I have made some changes as per the suggestions made by you. Please review again.

@tushar912 tushar912 changed the title [WIP] Add istio importer and tests Add istio importer and tests Feb 10, 2021
vulnerabilities/importer_yielder.py Outdated Show resolved Hide resolved
safe_pkg_versions = []
vuln_pkg_versions = []
all_version_list = self.version_api.get("istio/istio")
if not version_range_list:
Copy link
Collaborator

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.

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}
Copy link
Collaborator

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 Show resolved Hide resolved
vulnerabilities/importers/istio.py Show resolved Hide resolved
vulnerabilities/importers/istio.py Outdated Show resolved Hide resolved
ubound = "<=" + release[2]
releases.append(lbound + "," + ubound)

data["releases"] = releases
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

safe_purls = []
vuln_purls = []

cve_id = cve_id
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ?

Copy link
Contributor Author

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

vulnerabilities/importers/istio.py Show resolved Hide resolved
vulnerabilities/importers/istio.py Show resolved Hide resolved
@tushar912
Copy link
Contributor Author

@sbs2001 I have made the changes.

safe_pkg_versions, vuln_pkg_versions = self.get_versions_for_pkg_from_range_list(
data["release_ranges"])

safe_purls = []
Copy link
Collaborator

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should remove it.

advisories.extend(processed_data)
return self.batch_advisories(advisories)

def get_versions_for_pkg_from_range_list(self, version_range_list):
Copy link
Collaborator

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 ?

Copy link
Contributor Author

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 Show resolved Hide resolved
@tushar912
Copy link
Contributor Author

@sbs2001 I have made the changes, also can you answer #336 (comment).

ubound = "<=" + release[2]
releases.append(lbound + "," + ubound)
# If it is a single release
elif isinstance(release, int):
Copy link
Collaborator

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

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 ?

Copy link
Contributor Author

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?

Copy link
Collaborator

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 ?

Copy link
Collaborator

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.

Copy link
Collaborator

@sbs2001 sbs2001 left a 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.

vulnerabilities/importers/istio.py Outdated Show resolved Hide resolved
@sbs2001
Copy link
Collaborator

sbs2001 commented Feb 23, 2021

@tushar912 Due to recent model changes, you would need to rename Advisory.cve_id ->Advisory.vulnerability_id

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:
Copy link
Collaborator

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 ?

Copy link
Contributor Author

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.

Copy link
Collaborator

@sbs2001 sbs2001 left a 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 <tushar.912u@gmail.com>
Signed-off-by: Tushar912 <tushar.912u@gmail.com>
Also add github as package type

Signed-off-by: Tushar912 <tushar.912u@gmail.com>
@tushar912 tushar912 force-pushed the istio branch 3 times, most recently from d8e4ec3 to 5b6c5dd Compare March 11, 2021 07:00
@tushar912
Copy link
Contributor Author

@sbs2001 Sorry for the delay. I have added a better check for single release using regex.

@tushar912 tushar912 requested a review from sbs2001 March 11, 2021 07:02
assign cve to empty string if its
N/A

Signed-off-by: Tushar912 <tushar.912u@gmail.com>
ubound = "<=" + release[2]
releases.append(lbound + "," + ubound)
# If it is a single release
elif is_release(release):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Copy link
Collaborator

@sbs2001 sbs2001 left a 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.

@sbs2001 sbs2001 merged commit a3e98c2 into aboutcode-org:main Mar 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Collect Istio
3 participants