Skip to content

Commit

Permalink
Merge pull request #70 from wallarm/feature/ruby_to_golang_migration
Browse files Browse the repository at this point in the history
NODE-5399 Node 5.0 Migration to wcli scripts
  • Loading branch information
nedvna authored Aug 7, 2024
2 parents ec30808 + fa5d730 commit aa87626
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SHELL=/bin/bash -o pipefail -o errexit

-include .env

AIO_VERSION ?= 4.10.9
AIO_VERSION ?= 5.0.0
CONTAINER_VERSION ?= test
ALPINE_VERSION = 3.20
NGINX_VERSION = 1.26.1
Expand Down
43 changes: 8 additions & 35 deletions scripts/init
Original file line number Diff line number Diff line change
@@ -1,80 +1,54 @@
#!/bin/bash

register_node() {
args="--batch --no-sync"
args="job:register"

WALLARM_API_USE_SSL="${WALLARM_API_USE_SSL:-true}"
WALLARM_API_CA_VERIFY="${WALLARM_API_CA_VERIFY:-true}"

if [ -n "${DEPLOY_FORCE}" ]; then
args="$args --force"
fi

if [ -n "$WALLARM_API_HOST" ]; then
args="$args -H $WALLARM_API_HOST"
args="$args -host=$WALLARM_API_HOST"
fi

if [ -n "$WALLARM_API_PORT" ]; then
args="$args -P $WALLARM_API_PORT"
args="$args -port=$WALLARM_API_PORT"
fi

if [ x"$WALLARM_API_USE_SSL" = x"false" ] \
|| [ x"$WALLARM_API_USE_SSL" = x"False" ] \
|| [ x"$WALLARM_API_USE_SSL" = x"no" ]
then
args="$args --no-ssl"
args="$args -ssl=false"
fi

if [ x"$WALLARM_API_CA_VERIFY" = x"false" ] \
|| [ x"$WALLARM_API_CA_VERIFY" = x"False" ] \
|| [ x"$WALLARM_API_CA_VERIFY" = x"no" ]
then
args="$args --no-verify"
args="$args -ssl-verify=false"
fi

if [ x"$POSTANALYTIC_ONLY" = x"true" ] \
|| [ x"$POSTANALYTIC_ONLY" = x"True" ] \
|| [ x"$POSTANALYTIC_ONLY" = x"yes" ]
then
args="$args --postanalytic-only"
args="$args -mode=post_analytic"
fi

if [ -n "$POSTANALYTIC_ADDRESS" ]; then
args="$args --filtering-only"
args="$args -mode=filtering"
fi

if [ -e /opt/wallarm/etc/wallarm/node.yaml ] \
&& [ -s /opt/wallarm/etc/wallarm/node.yaml ]
then
echo "Node registration skipped - node.yaml already exists"
elif [ -n "$NODE_UUID" ] \
&& [ -n "$NODE_SECRET" ] \
&& [ -n "$WALLARM_API_TOKEN" ]
then
/opt/wallarm/register-node \
$args \
--uuid "$NODE_UUID"
else
/opt/wallarm/register-node \
$args
fi
}

sync_node() {
cmd="/opt/wallarm/usr/share/wallarm-common/syncnode -l STDOUT"

for i in $(seq 1 3); do
if $cmd; then
break
elif [ -f /opt/wallarm/etc/wallarm/proton.db ] && [ -f /opt/wallarm/etc/wallarm/custom_ruleset ]; then
break
else
echo "Wait before next syncnode attempt..."
sleep 5
fi
done
}

configure_nginx() {
read -r NGX_CONF_FIRST < /etc/nginx/nginx.conf
if [ "$NGX_CONF_FIRST" = "### Wallarm default ###" ] \
Expand Down Expand Up @@ -166,8 +140,7 @@ set -a && source /opt/wallarm/env.list && set +a
printenv >> /etc/environment
configure_services
#taken from https://unix.stackexchange.com/a/71511
{ register_node |& tee /dev/fd/3 | grep -q 'Label "group" is required for this registration type' && exit; } 3>&1
sync_node
{ register_node |& tee /dev/fd/3 | grep -q 'label "group" is required for this registration type' && exit; } 3>&1
configure_nginx

if [ x"$POSTANALYTIC_ONLY" = x"true" ] \
Expand Down

0 comments on commit aa87626

Please sign in to comment.