bridgecrewio / checkov

Prevent cloud misconfigurations and find vulnerabilities during build-time in infrastructure as code, container images and open source packages with Checkov by Bridgecrew.
https://www.checkov.io/
Apache License 2.0
6.71k stars 1.07k forks source link

Checkov --list ouput is not 'awk' friendly #6400

Closed tmprender closed 18 hours ago

tmprender commented 3 weeks ago

Describe the issue When calling the --list option to output policies, this output cannot be easily parsed using awk (and does not support outputting to json).

Additional context Expecting the header and values in each column to be aligned and not to have to write custom parsing on separators.

Example: $ checkov --list --framework ansible | awk '{print $3}' | head -n 5 Id

$ checkov --list --framework ansible awk '{print $4}' head -n 5

CKV_ANSIBLE_1 CKV_ANSIBLE_1 CKV_ANSIBLE_1

Saarett commented 21 hours ago

@tmprender What about the following command: checkov --list --framework ansible | awk -F'|' 'NR > 1 {print $3}' | sort | uniq It would be much easier than changing/supporting a new format. The purpose of the –list option is to output both the policy and the validations made against the resources for that policy.

Other than that, we would be glad to receive a contribution for a new option. Thanks 🙂

tmprender commented 18 hours ago

Ah, this can be attributed to user error then :) this works. FYI - it does not seem that NR > 1 is needed but I did learn something new...

Thanks for solution and reply.