Skip to content

Commit

Permalink
fix(snap): source security-bootstrapper config overrides from env file (
Browse files Browse the repository at this point in the history
#4283)

Signed-off-by: Farshid Tavakolizadeh <farshid.tavakolizadeh@canonical.com>
  • Loading branch information
farshidtz authored Jan 17, 2023
1 parent bf562dc commit 01248c1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
6 changes: 5 additions & 1 deletion snap/local/runtime-helpers/bin/service-config-overrides.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ BINPATH="${ARGV[0]}"

# binary name == service name/key
SERVICE=$(basename "$BINPATH")
ENV_FILE="$SNAP_DATA/config/$SERVICE/res/$SERVICE.env"
if [ -z $ENV_FILE ]; then
ENV_FILE="$SNAP_DATA/config/$SERVICE/res/$SERVICE.env"
fi
TAG="edgex-$SERVICE."$(basename "$0")

if [ -f "$ENV_FILE" ]; then
logger --tag=$TAG "sourcing $ENV_FILE"
set -o allexport
source "$ENV_FILE" set
set +o allexport
else
logger --tag=$TAG --stderr "sourcing $ENV_FILE: not found!"
fi

exec "$@"
10 changes: 0 additions & 10 deletions snap/local/runtime-helpers/bin/setup-consul-acl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
# we don't want to exit out the whole Consul process when ACL bootstrapping failed, just that
# Consul won't have ACL to be used

# TODO: determine if this script is really necessary. I'm not sure why the command below isn't
# simply specified as the service command, with the command-chain service-overrides script to
# handle sourcing the .env file

SERVICE_ENV="$SNAP_DATA/config/security-bootstrapper/res/security-bootstrapper.env"
if [ -f "$SERVICE_ENV" ]; then
logger "edgex service override: : sourcing $SERVICE_ENV"
source "$SERVICE_ENV"
fi

# setup Consul's ACL via security-bootstrapper's subcommand
"$SNAP"/bin/security-bootstrapper -configDir "$SNAP_DATA"/config/security-bootstrapper/res setupRegistryACL
setupACL_code=$?
Expand Down
7 changes: 6 additions & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,10 @@ apps:
after:
- security-secretstore-setup
command: bin/setup-redis-acl.sh
command-chain:
- bin/service-config-overrides.sh
environment:
# TODO: determine the correct cmd-line args & env var overrides...
ENV_FILE: $SNAP_DATA/config/security-bootstrapper/res/security-bootstrapper.env
SECRETSTORE_SERVERNAME: localhost
SECRETSTORE_TOKENFILE: $SNAP_DATA/secrets/security-bootstrapper-redis/secrets-token.json
DATABASECONFIG_PATH: $SNAP_DATA/redis/conf
Expand All @@ -242,7 +244,10 @@ apps:
after:
- security-secretstore-setup
command: bin/setup-consul-acl.sh
command-chain:
- bin/service-config-overrides.sh
environment:
ENV_FILE: $SNAP_DATA/config/security-bootstrapper/res/security-bootstrapper.env
STAGEGATE_REGISTRY_HOST: localhost
STAGEGATE_REGISTRY_ACL_BOOTSTRAPTOKENPATH: $SNAP_DATA/secrets/consul-acl-token/bootstrap_token.json
STAGEGATE_REGISTRY_ACL_MANAGEMENTTOKENPATH: $SNAP_DATA/secrets/consul-acl-token/mgmt_token.json
Expand Down

0 comments on commit 01248c1

Please sign in to comment.