mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-10 20:05:55 +02:00
Refactor hub management and cscli commands (#2545)
This commit is contained in:
parent
32e9eb4be4
commit
ffcab0b2bc
124 changed files with 6836 additions and 4414 deletions
|
@ -3,7 +3,6 @@ common:
|
|||
log_media: stdout
|
||||
log_level: info
|
||||
log_dir: /var/log/
|
||||
working_dir: .
|
||||
config_paths:
|
||||
config_dir: /etc/crowdsec/
|
||||
data_dir: /var/lib/crowdsec/data/
|
||||
|
|
|
@ -101,19 +101,23 @@ register_bouncer() {
|
|||
# $2 can be install, remove, upgrade
|
||||
# $3 is a list of object names separated by space
|
||||
cscli_if_clean() {
|
||||
local itemtype="$1"
|
||||
local action="$2"
|
||||
local objs=$3
|
||||
shift 3
|
||||
# loop over all objects
|
||||
for obj in $3; do
|
||||
if cscli "$1" inspect "$obj" -o json | yq -e '.tainted // false' >/dev/null 2>&1; then
|
||||
echo "Object $1/$obj is tainted, skipping"
|
||||
for obj in $objs; do
|
||||
if cscli "$itemtype" inspect "$obj" -o json | yq -e '.tainted // false' >/dev/null 2>&1; then
|
||||
echo "Object $itemtype/$obj is tainted, skipping"
|
||||
else
|
||||
# # Too verbose? Only show errors if not in debug mode
|
||||
# if [ "$DEBUG" != "true" ]; then
|
||||
# error_only=--error
|
||||
# fi
|
||||
error_only=""
|
||||
echo "Running: cscli $error_only $1 $2 \"$obj\""
|
||||
echo "Running: cscli $error_only $itemtype $action \"$obj\" $*"
|
||||
# shellcheck disable=SC2086
|
||||
cscli $error_only "$1" "$2" "$obj"
|
||||
cscli $error_only "$itemtype" "$action" "$obj" "$@"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
@ -327,22 +331,22 @@ fi
|
|||
## Remove collections, parsers, scenarios & postoverflows
|
||||
if [ "$DISABLE_COLLECTIONS" != "" ]; then
|
||||
# shellcheck disable=SC2086
|
||||
cscli_if_clean collections remove "$DISABLE_COLLECTIONS"
|
||||
cscli_if_clean collections remove "$DISABLE_COLLECTIONS" --force
|
||||
fi
|
||||
|
||||
if [ "$DISABLE_PARSERS" != "" ]; then
|
||||
# shellcheck disable=SC2086
|
||||
cscli_if_clean parsers remove "$DISABLE_PARSERS"
|
||||
cscli_if_clean parsers remove "$DISABLE_PARSERS" --force
|
||||
fi
|
||||
|
||||
if [ "$DISABLE_SCENARIOS" != "" ]; then
|
||||
# shellcheck disable=SC2086
|
||||
cscli_if_clean scenarios remove "$DISABLE_SCENARIOS"
|
||||
cscli_if_clean scenarios remove "$DISABLE_SCENARIOS" --force
|
||||
fi
|
||||
|
||||
if [ "$DISABLE_POSTOVERFLOWS" != "" ]; then
|
||||
# shellcheck disable=SC2086
|
||||
cscli_if_clean postoverflows remove "$DISABLE_POSTOVERFLOWS"
|
||||
cscli_if_clean postoverflows remove "$DISABLE_POSTOVERFLOWS" --force
|
||||
fi
|
||||
|
||||
## Register bouncers via env
|
||||
|
|
|
@ -30,8 +30,8 @@ def test_install_two_collections(crowdsec, flavor):
|
|||
cs.wait_for_log([
|
||||
# f'*collections install "{it1}"*'
|
||||
# f'*collections install "{it2}"*'
|
||||
f'*Enabled collections : {it1}*',
|
||||
f'*Enabled collections : {it2}*',
|
||||
f'*Enabled collections: {it1}*',
|
||||
f'*Enabled collections: {it2}*',
|
||||
])
|
||||
|
||||
|
||||
|
@ -72,7 +72,7 @@ def test_install_and_disable_collection(crowdsec, flavor):
|
|||
assert it not in items
|
||||
logs = cs.log_lines()
|
||||
# check that there was no attempt to install
|
||||
assert not any(f'Enabled collections : {it}' in line for line in logs)
|
||||
assert not any(f'Enabled collections: {it}' in line for line in logs)
|
||||
|
||||
|
||||
# already done in bats, prividing here as example of a somewhat complex test
|
||||
|
@ -91,7 +91,7 @@ def test_taint_bubble_up(crowdsec, tmp_path_factory, flavor):
|
|||
# implicit check for tainted=False
|
||||
assert items[coll]['status'] == 'enabled'
|
||||
cs.wait_for_log([
|
||||
f'*Enabled collections : {coll}*',
|
||||
f'*Enabled collections: {coll}*',
|
||||
])
|
||||
|
||||
scenario = 'crowdsecurity/http-crawl-non_statics'
|
||||
|
|
|
@ -21,8 +21,8 @@ def test_install_two_scenarios(crowdsec, flavor):
|
|||
}
|
||||
with crowdsec(flavor=flavor, environment=env) as cs:
|
||||
cs.wait_for_log([
|
||||
f'*scenarios install "{it1}*"',
|
||||
f'*scenarios install "{it2}*"',
|
||||
f'*scenarios install "{it1}"*',
|
||||
f'*scenarios install "{it2}"*',
|
||||
"*Starting processing data*"
|
||||
])
|
||||
cs.wait_for_http(8080, '/health', want_status=HTTPStatus.OK)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue