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

fix(general): refactor SARIF output #4606

Merged
merged 1 commit into from
Mar 6, 2023

Conversation

gruebel
Copy link
Contributor

@gruebel gruebel commented Mar 3, 2023

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Description

  • adds affected code lines to the report
  • fixes an issue with IR output
  • moved and refactored the SARIF code to a dedicated class
  • rule IDs for licenses and CVEs are now correct and don't smooshed to a few
  • also added a doc page for SARIF

Fixes #4600
Fixes #4585

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my feature, policy, or fix is effective and works
  • New and existing tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules


def _create_rules(self) -> list[dict[str, Any]]:
rule_idx = 0
rules: "list[dict[str, Any]]" = []
Copy link
Contributor

Choose a reason for hiding this comment

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

Is quoted typing necessary even if you imported annotations from __future__?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is a bit faster to put into a string literal, I somehow got used to it, when I add complex type hints. But you are right it is not needed when using the __future__ import

Copy link
Contributor

Choose a reason for hiding this comment

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

I dug the rabbit hole a bit further and found out that "list[dict[str, Any]]" != list[dict[str, Any]]
It seems to have no real effect on linting for now but may be worth changing it regardless (?)
https://stackoverflow.com/a/46458497/11918269

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and as the comment to the answer suggests, don't do that and use the proper function typing.get_type_hints()

>>> typing.get_type_hints(bad_foo) == typing.get_type_hints(good_foo)
True

😉

Copy link
Contributor

Choose a reason for hiding this comment

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

🤯

Comment on lines +239 to +242
print("\nWrote output in SARIF format to the file 'results.sarif'")
except EnvironmentError as e:
print("\nAn error occurred while writing SARIF results to file: results.sarif")
print(f"More details: \n {e}")
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we use logging instead of print here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in general yes, this is especially used in our checkov action and there printing is a bit more clear to the user.

@gruebel gruebel merged commit 5ea0be3 into bridgecrewio:main Mar 6, 2023
@gruebel gruebel deleted the refactor-sarif-output branch March 6, 2023 15:45
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.

Invalid URI when scanning Nginx based image Checkov to include affected code snippet in SARIF output
4 participants