Last active
December 1, 2021 21:51
-
-
Save TomMD/3313a0b126fc47a25b000597539425a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
function emit_results() { | |
results=$1 | |
echo $results | \ | |
jq '[ .[] | | |
select (.vulns != null) | | |
.vulns | | |
.[] | | |
.type = .id | | |
.message = .description | | |
.file = "requirements.txt" | | |
.line = 1 | | |
del(.description, .fix_versions, .id) | |
]' | |
} | |
function run() { | |
if [[ -e "requirements.txt" ]] ; then | |
raw_results=$($HOME/.local/bin/pip-audit --desc on -l -f json -r ./requirements.txt) | |
else | |
raw_results=$($HOME/.local/bin/pip-audit --desc on -l -f json) | |
fi | |
emit_results "$raw_results" | |
} | |
function install() { | |
python -m pip install pip-audit 2>/dev/null 1>&2 | |
} | |
function applicable() { | |
if [[ -f "requirements.txt" ]] ; then | |
echo true | |
elif [[ -f "setup.py" ]] ; then | |
echo true | |
else | |
echo false | |
fi | |
} | |
function name() { | |
echo "pip-audit" | |
} | |
function api_version() { | |
echo 1 | |
} | |
case "$3" in | |
run) | |
install | |
run | |
;; | |
applicable) | |
applicable | |
;; | |
name) | |
name | |
;; | |
*) | |
api_version | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment