fix: allow get_docker_configuration_file_args to parse minified json

Closes #524.
This commit is contained in:
Brad Solomon 2023-06-02 09:18:42 -04:00
parent 16c235080d
commit 39963dad60
3 changed files with 15 additions and 2 deletions

View file

@ -7,7 +7,8 @@ LABEL \
RUN apk add --no-cache iproute2 \ RUN apk add --no-cache iproute2 \
docker-cli \ docker-cli \
dumb-init dumb-init \
jq
COPY . /usr/local/bin/ COPY . /usr/local/bin/

View file

@ -26,6 +26,8 @@ cd docker-bench-security
sudo sh docker-bench-security.sh sudo sh docker-bench-security.sh
``` ```
> Note: [`jq`](https://jqlang.github.io/jq/) is an optional but recommended dependency.
### Run with Docker ### Run with Docker
_Please note that the `docker/docker-bench-security` image is out-of-date and and a manual build is required. See [#405](https://github.com/docker/docker-bench-security/issues/405) for more information._ _Please note that the `docker/docker-bench-security` image is out-of-date and and a manual build is required. See [#405](https://github.com/docker/docker-bench-security/issues/405) for more information._

View file

@ -112,12 +112,22 @@ get_docker_configuration_file() {
CONFIG_FILE='/dev/null' CONFIG_FILE='/dev/null'
} }
if command -v jq &> /dev/null; then
HAVE_JQ=true
else
HAVE_JQ=false
fi
get_docker_configuration_file_args() { get_docker_configuration_file_args() {
OPTION="$1" OPTION="$1"
get_docker_configuration_file get_docker_configuration_file
grep "$OPTION" "$CONFIG_FILE" | sed 's/.*://g' | tr -d '" ', if "$HAVE_JQ"; then
jq --monochrome-output --raw-output ".[\"${OPTION}\"]" "$CONFIG_FILE"
else
cat "$CONFIG_FILE" | tr -u { '\n' | tr , '\n' | tr } '\n' | grep "$OPTION" | sed 's/.*://g' | tr -d '" ',
fi
} }
get_service_file() { get_service_file() {