From 387e8ab1d15ec838323413725d11a2640c18939f Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Tue, 16 Nov 2021 10:59:55 +0100 Subject: [PATCH] fix(snap): make secretstore connect hook idempotent (#3815) Fixes https://github.com/edgexfoundry/edgex-go/issues/3814 Signed-off-by: Farshid Tavakolizadeh --- snap/hooks/connect-plug-edgex-secretstore-token | 7 +++++-- snap/hooks/prepare-plug-edgex-secretstore-token | 12 ++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/snap/hooks/connect-plug-edgex-secretstore-token b/snap/hooks/connect-plug-edgex-secretstore-token index fd80a0a3d0..ef3e1412c9 100755 --- a/snap/hooks/connect-plug-edgex-secretstore-token +++ b/snap/hooks/connect-plug-edgex-secretstore-token @@ -31,7 +31,7 @@ # able to share the same token. SLOTDIRS=$(snapctl get :edgex-secretstore-token --slot source.write) -logger "edgex-secretstore-token: prepare SLOTDIRS=$SLOTDIRS" +logger "edgex-secretstore-token: connect SLOTDIRS=$(echo $SLOTDIRS)" DIRS=$(jq -r '.[]' <<< "$SLOTDIRS" ) for tokenpath in $DIRS; @@ -42,7 +42,10 @@ do TARGET_PATH="$SNAP_DATA/secrets/${filename}/secrets-token.json" if [ -f "$APP_SVC_TOKEN" ]; then - logger "edgex-secretstore-token: token found in $APP_SVC_TOKEN; moving to $TARGET_PATH" + logger "edgex-secretstore-token: moving $APP_SVC_TOKEN to $TARGET_PATH" mv "$APP_SVC_TOKEN" "$TARGET_PATH" + else + logger --stderr "edgex-secretstore-token: could not find token for $filename" + exit 1 fi done diff --git a/snap/hooks/prepare-plug-edgex-secretstore-token b/snap/hooks/prepare-plug-edgex-secretstore-token index c53dbd0f6f..fece17154c 100755 --- a/snap/hooks/prepare-plug-edgex-secretstore-token +++ b/snap/hooks/prepare-plug-edgex-secretstore-token @@ -29,7 +29,7 @@ # able to share the same token. SLOTDIRS=$(snapctl get :edgex-secretstore-token --slot source.write) -logger "edgex-secretstore-token: prepare SLOTDIRS=$SLOTDIRS" +logger "edgex-secretstore-token: prepare SLOTDIRS=$(echo $SLOTDIRS)" DIRS=$(jq -r '.[]' <<< "$SLOTDIRS" ) for tokenpath in $DIRS; @@ -39,10 +39,10 @@ do APP_SVC_TOKEN="$SNAP_DATA/secrets/${filename}/secrets-token.json" TARGET_PATH="/tmp/${filename}-secrets-token.json" if [ -f "$APP_SVC_TOKEN" ]; then - logger "edgex-secretstore-token: token found in $APP_SVC_TOKEN; moving to $TARGET_PATH" - mv "$APP_SVC_TOKEN" "$TARGET_PATH" + logger "edgex-secretstore-token: copying $APP_SVC_TOKEN to $TARGET_PATH" + cp "$APP_SVC_TOKEN" "$TARGET_PATH" + else + logger --stderr "edgex-secretstore-token: could not find token for $filename" + exit 1 fi done - - -