diff --git a/.gitignore b/.gitignore index f5e96db..ceef511 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -venv \ No newline at end of file +venv +.DS_Store \ No newline at end of file diff --git a/pre_commit_hooks/vscode.py b/pre_commit_hooks/vscode.py index c66612b..bc89222 100644 --- a/pre_commit_hooks/vscode.py +++ b/pre_commit_hooks/vscode.py @@ -3,19 +3,26 @@ import hashlib +def filter_findings(findings, configuration): + return list(filter(lambda finding: finding["controlName"] not in configuration, findings)) + + def main(): cwd = os.getcwd() - cwd_hash = hashlib.md5(cwd.encode('utf-8')).hexdigest() - with open('/tmp/controls/.precommit/' + cwd_hash + '.state.json', 'r') as json_file: + cwd_hash = hashlib.md5(cwd.encode("utf-8")).hexdigest() + with open("/tmp/controls/.precommit/" + cwd_hash + ".state.json", "r") as json_file: state = json.load(json_file) + findings = state.get("findings", []) + configuration = state.get("configuration", []) + if configuration: + findings = filter_findings(findings, configuration) - findings = state.get('findings', []) print(f"Found {len(findings)} findings") if findings: exit(1) - + exit(0) if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/setup.cfg b/setup.cfg index ab67294..472f024 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = jit_ide_pre_commit_hooks -version = 0.0.1 +version = 0.0.2 url = https://github.com/jitsecurity/ide-pre-commit-hooks license = MIT license_file = LICENSE