local api (#482)

Co-authored-by: AlteredCoder
Co-authored-by: erenJag
This commit is contained in:
Thibault "bui" Koechlin 2020-11-30 10:37:17 +01:00 committed by GitHub
parent 5f339ab312
commit dbb420f79e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
563 changed files with 64363 additions and 10714 deletions

View file

@ -1,7 +1,7 @@
#!/bin/sh
./cscli -c dev.yaml list parsers -a -o json | jq -r ".[].name" > installed_parsers.txt
./cscli -c dev.yaml list parser list -a -o json | jq -r ".[].name" > installed_parsers.txt
cat installed_parsers.txt | while read parser; do
echo "install ${parser}" ;
./cscli -c dev.yaml install parser ${parser} ;
./cscli -c dev.yaml parsers install ${parser} ;
done

View file

@ -38,17 +38,7 @@ PARSER_S01="$PARSER_DIR/s01-parse"
PARSER_S02="$PARSER_DIR/s02-enrich"
SCENARIOS_DIR="$CONFIG_DIR/scenarios"
POSTOVERFLOWS_DIR="$CONFIG_DIR/postoverflows"
PLUGIN_BACKEND_DIR="$CONFIG_DIR/plugins/backend/"
DB_PLUGIN_FILE="$PLUGIN_BACKEND_DIR/database.yaml"
gen_sqlite_config() {
echo "name: database" >> "$DB_PLUGIN_FILE"
echo "path: ./plugins/backend/database.so" >> "$DB_PLUGIN_FILE"
echo "config:" >> "$DB_PLUGIN_FILE"
echo " type: sqlite" >> "$DB_PLUGIN_FILE"
echo " db_path: ./test.db" >> "$DB_PLUGIN_FILE"
echo " flush: true" >> "$DB_PLUGIN_FILE"
}
HUB_DIR="$CONFIG_DIR/hub"
log_info() {
msg=$1
@ -68,7 +58,7 @@ create_arbo() {
mkdir -p "$SCENARIOS_DIR"
mkdir -p "$POSTOVERFLOWS_DIR"
mkdir -p "$CSCLI_DIR"
mkdir -p "$PLUGIN_BACKEND_DIR"
mkdir -p "$HUB_DIR"
}
copy_files() {
@ -78,13 +68,19 @@ copy_files() {
cp "./cmd/crowdsec/crowdsec" "$BASE"
cp "./cmd/crowdsec-cli/cscli" "$BASE"
cp -r "./config/patterns" "$CONFIG_DIR"
cp -r "./plugins/" "$BASE"
cp "./config/acquis.yaml" "$CONFIG_DIR"
touch "$CONFIG_DIR"/local_api_credentials.yaml
touch "$CONFIG_DIR"/online_api_credentials.yaml
}
setup() {
$BASE/cscli -c "$CONFIG_FILE" update
$BASE/cscli -c "$CONFIG_FILE" install collection crowdsecurity/linux
$BASE/cscli -c "$CONFIG_FILE" hub update
$BASE/cscli -c "$CONFIG_FILE" collections install crowdsecurity/linux
}
setup_api() {
$BASE/cscli -c "$CONFIG_FILE" machines add test -p testpassword -f $CONFIG_DIR/local_api_credentials.yaml --force
}
@ -98,9 +94,9 @@ main() {
log_info "Setting up configurations"
CURRENT_PWD=$(pwd)
cd $BASE
setup_api
setup
cd $CURRENT_PWD
gen_sqlite_config
log_info "Environment is ready in $BASE"
}