support yq prior to 4.18.1 (#1466)

This commit is contained in:
mmetc 2022-04-20 15:05:34 +02:00 committed by GitHub
parent ec4e193cbb
commit 6de175ad8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 32 additions and 25 deletions

View file

@ -37,7 +37,7 @@ declare stderr
@test "$FILE crowdsec should not run without LAPI (no api.server in configuration file)" {
skip
yq 'del(.api.server)' -i "${CONFIG_YAML}"
yq e 'del(.api.server)' -i "${CONFIG_YAML}"
run -1 --separate-stderr timeout 2s "${CROWDSEC}"
run -0 echo "$stderr"
@ -45,7 +45,7 @@ declare stderr
}
@test "$FILE capi status shouldn't be ok without api.server" {
yq 'del(.api.server)' -i "${CONFIG_YAML}"
yq e 'del(.api.server)' -i "${CONFIG_YAML}"
run -1 --separate-stderr cscli capi status
run -0 echo "$stderr"
@ -53,7 +53,7 @@ declare stderr
}
@test "$FILE cscli config show -o human" {
yq 'del(.api.server)' -i "${CONFIG_YAML}"
yq e 'del(.api.server)' -i "${CONFIG_YAML}"
run -0 cscli config show -o human
assert_output --partial "Global:"
assert_output --partial "Crowdsec:"
@ -62,7 +62,7 @@ declare stderr
}
@test "$FILE cscli config backup" {
yq 'del(.api.server)' -i "${CONFIG_YAML}"
yq e 'del(.api.server)' -i "${CONFIG_YAML}"
backupdir=$(TMPDIR="${BATS_TEST_TMPDIR}" mktemp -u)
run -0 cscli config backup "${backupdir}"
assert_output --partial "Starting configuration backup"
@ -75,7 +75,7 @@ declare stderr
}
@test "$FILE lapi status shouldn't be ok without api.server" {
yq 'del(.api.server)' -i "${CONFIG_YAML}"
yq e 'del(.api.server)' -i "${CONFIG_YAML}"
./instance-crowdsec start || true
run -1 --separate-stderr cscli machines list
run -0 echo "$stderr"
@ -84,7 +84,7 @@ declare stderr
@test "$FILE cscli metrics" {
skip 'need to trigger metrics with a live parse'
yq 'del(.api.server)' -i "${CONFIG_YAML}"
yq e 'del(.api.server)' -i "${CONFIG_YAML}"
./instance-crowdsec start
run -0 --separate-stderr cscli metrics
assert_output --partial "ROUTE"

View file

@ -25,7 +25,7 @@ declare stderr
#----------
config_disable_agent() {
yq 'del(.crowdsec_service)' -i "${CONFIG_YAML}"
yq e 'del(.crowdsec_service)' -i "${CONFIG_YAML}"
}
@test "$FILE with agent: test without -no-cs flag" {

View file

@ -25,7 +25,7 @@ declare stderr
#----------
config_disable_capi() {
yq 'del(.api.server.online_client)' -i "${CONFIG_YAML}"
yq e 'del(.api.server.online_client)' -i "${CONFIG_YAML}"
}
@test "$FILE without capi: crowdsec LAPI should still work" {

View file

@ -15,18 +15,18 @@ setup_file() {
export MOCK_URL
# https://mikefarah.gitbook.io/yq/operators/env-variable-operators
yq '
yq e '
.url=strenv(MOCK_URL) |
.group_wait="5s" |
.group_threshold=2
' -i "$(config_yq '.config_paths.notification_dir')/http.yaml"
yq '
yq e '
.notifications=["http_default"] |
.filters=["Alert.GetScope() == \"Ip\""]
' -i "$(config_yq '.api.server.profiles_path')"
yq '
yq e '
.plugin_config.user="" |
.plugin_config.group=""
' -i "${CONFIG_YAML}"

View file

@ -12,18 +12,18 @@ setup_file() {
tempfile=$(TMPDIR="${BATS_FILE_TMPDIR}" mktemp)
export tempfile
yq '
yq e '
.group_wait="5s" |
.group_threshold=2 |
.output_file=strenv(tempfile)
' -i "$(config_yq '.config_paths.notification_dir')/dummy.yaml"
yq '
yq e '
.notifications=["dummy_default"] |
.filters=["Alert.GetScope() == \"Ip\""]
' -i "$(config_yq '.api.server.profiles_path')"
yq '
yq e '
.plugin_config.user="" |
.plugin_config.group=""
' -i "${CONFIG_YAML}"

View file

@ -25,6 +25,13 @@ check_python3() {
fi
}
check_jq() {
# shellcheck disable=SC2016
if ! command -v jq >/dev/null; then
die "Missing required program 'jq'"
fi
}
check_nc() {
if ! command -v nc >/dev/null; then
die "missing required program 'nc' (package 'netcat-openbsd')"
@ -40,7 +47,6 @@ check_yq() {
if ! (yq --version | grep mikefarah >/dev/null); then
die "yq exists but it's not the one we need (mikefarah/yq). $howto_install"
fi
}
check_daemonizer() {
@ -69,10 +75,11 @@ check_gocovmerge() {
}
check_bats_core
check_python3
check_nc
check_yq
check_daemonizer
check_jq
check_nc
check_python3
check_yq
if [ -n "${TEST_COVERAGE}" ]; then
check_gocovmerge
fi

View file

@ -56,7 +56,7 @@ config_generate() {
cp ../plugins/notifications/*/{http,email,slack,splunk,dummy}.yaml \
"${CONFIG_DIR}/notifications/"
yq '
yq e '
.common.daemonize=true |
del(.common.pid_dir) |
.common.log_level="info" |
@ -74,7 +74,7 @@ config_generate() {
.api.server.profiles_path=strenv(CONFIG_DIR)+"/profiles.yaml" |
.api.server.console_path=strenv(CONFIG_DIR)+"/console.yaml" |
.api.server.online_client.credentials_path=strenv(CONFIG_DIR)+"/online_api_credentials.yaml"
' <../config/config.yaml >"${CONFIG_DIR}/config.yaml"
' - <../config/config.yaml >"${CONFIG_DIR}/config.yaml"
}
make_init_data() {

View file

@ -83,7 +83,7 @@ restore() {
}
config_yaml() {
MYSQL_PORT=${MYSQL_PORT} MYSQL_HOST=${MYSQL_HOST} yq '
MYSQL_PORT=${MYSQL_PORT} MYSQL_HOST=${MYSQL_HOST} yq e '
.db_config.type=strenv(DB_BACKEND)|
.db_config.user="crowdsec_test" |
.db_config.password="crowdsec_test" |

View file

@ -60,7 +60,7 @@ restore() {
}
config_yaml() {
yq '
yq e '
.db_config.type=strenv(DB_BACKEND)|
.db_config.user="crowdsec_test" |
.db_config.password="crowdsec_test" |

View file

@ -49,12 +49,12 @@ restore() {
# ---------------------------
# In most cases this is called with setup argument, and it shouldn't fail for missing config file.
if [ -f "${CONFIG_YAML}" ] ; then
DATA_DIR=$(yq '.config_paths.data_dir' <"${CONFIG_YAML}")
DATA_DIR=$(yq e '.config_paths.data_dir' - <"${CONFIG_YAML}")
DB_FILE="${DATA_DIR}/crowdsec.db"
fi
config_yaml() {
yq '
yq e '
.db_config.type=strenv(DB_BACKEND) |
.db_config.db_path="${DB_FILE}"
' -i "${CONFIG_YAML}"

View file

@ -34,7 +34,7 @@ cscli() {
export -f cscli
config_yq() {
yq <"${CONFIG_YAML}" "$@"
yq e "$@" - <"${CONFIG_YAML}"
}
export -f config_yq