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

feat(github): Improving GHA schema validation #3513

Merged
merged 4 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions checkov/common/parsers/yaml/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,17 @@ def construct_mapping(self, node: MappingNode, deep: bool = False) -> dict[str,
'on': 'on',
'off': False,
}


class SafeLineLoaderGhaSchema(SafeLoader):
def construct_mapping(self, node: MappingNode, deep: bool = False) -> dict[str, Any]:
mapping: dict[str, Any] = super().construct_mapping(node, deep=deep) # type:ignore[no-untyped-call] # sadly it is untyped
return mapping

bool_values = { # noqa: CCE003 # used to override the SafeLoader default behaviour
'on': 'on',
'yes': 'true',
'no': 'false',
'true': 'true',
'false': 'false'
}
4 changes: 2 additions & 2 deletions checkov/common/util/type_forcers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor

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, ...

return force_dict(obj[0])
return None


Expand Down
654 changes: 654 additions & 0 deletions checkov/github_actions/gha_schema.json

Large diffs are not rendered by default.

Loading