Skip to content

Instantly share code, notes, and snippets.

@TomMD
Last active December 1, 2021 21:51
Show Gist options
  • Save TomMD/3313a0b126fc47a25b000597539425a9 to your computer and use it in GitHub Desktop.
Save TomMD/3313a0b126fc47a25b000597539425a9 to your computer and use it in GitHub Desktop.
#!/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