Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions src/checkov_launcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import json
import sys
import warnings


if __name__ == '__main__':
sys.argv = json.load(sys.stdin)
from checkov.main import Checkov
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=SyntaxWarning)
sys.exit(Checkov(sys.argv[1:]).run())
15 changes: 5 additions & 10 deletions src/codacy_checkov.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import errno
import os
import re
import sys
Expand All @@ -11,6 +10,8 @@
import traceback


CHECKOV_LAUNCHER = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'checkov_launcher.py')

checkovProcess = None


Expand Down Expand Up @@ -183,15 +184,9 @@ def runCheckov(config, srcDir):
command = command + ['--framework', ','.join(frameworks)]

global checkovProcess
try:
checkovProcess = Popen(command + file_opts, stdout=PIPE, cwd=srcDir, env=processEnv)
except OSError as e:
if e.errno != errno.E2BIG or not config.files:
raise
print(f"{len(config.files)} files do not fit in the command line, scanning the whole directory", file=sys.stderr)
checkovProcess = Popen(command + ['-d', '.'], stdout=PIPE, cwd=srcDir, env=processEnv)

stdout = checkovProcess.communicate()[0]
checkovProcess = Popen([sys.executable, CHECKOV_LAUNCHER], stdin=PIPE, stdout=PIPE, cwd=srcDir, env=processEnv)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

When Checkov is installed in a different Python environment from the wrapper, scans now fail with an import error instead of using the checkov executable on PATH. Consider running the launcher with the interpreter associated with that executable, or explicitly installing Checkov in the wrapper's interpreter.

TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.


stdout = checkovProcess.communicate(json.dumps(command + file_opts).encode('utf-8'))[0]

if len(stdout) > 0:
return json.loads(stdout.decode('utf-8'))
Expand Down