-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat(github): Improving GHA schema validation #3513
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.
nice job 🚀
@@ -62,8 +62,8 @@ def force_dict(obj: Any) -> dict[str, Any] | None: | |||
""" | |||
if isinstance(obj, dict): | |||
return obj | |||
if isinstance(obj, list) and len(obj) > 0 and isinstance(obj[0], dict): | |||
return obj[0] | |||
if (isinstance(obj, list) or isinstance(obj, tuple)) and len(obj) > 0: |
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.
can you add this change to the doc string?
If the object is a list/tuple of length 1 or more, ...
checkov/github_actions/runner.py
Outdated
@@ -181,13 +186,22 @@ def resolve_step_name(job_definition: dict[str, Any], start_line: int, end_line: | |||
@staticmethod | |||
def is_schema_valid(config: dict[str, Any] | list[dict[str, Any]]) -> bool: | |||
valid = False | |||
config = force_list(config) | |||
config = force_dict(config) | |||
dir_path = os.path.dirname(os.path.realpath(__file__)) |
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.
dir_path = os.path.dirname(os.path.realpath(__file__)) | |
dir_path = os.path.dirname(__file__) |
please never use realpath
it has unwanted behaviour on Mac for example
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Description
Improving GHA schema validation.
Schema resource is from https://www.schemastore.org/json/ - I made it "softer" to match the tests.
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Should improve false negatives as previous schema wasn't detailed enough.
Note - I suppressed a bandit check on yaml.load since the loader used is inheriting from SafeLoader.
Checklist: