Skip to content

Commit

Permalink
fix(snap): make secretstore connect hook idempotent
Browse files Browse the repository at this point in the history
Fixes: #3814
#3814

Signed-off-by: Farshid Tavakolizadeh <[email protected]>
  • Loading branch information
farshidtz committed Nov 13, 2021
1 parent f7c7132 commit 4930e0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 5 additions & 2 deletions snap/hooks/connect-plug-edgex-secretstore-token
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
12 changes: 6 additions & 6 deletions snap/hooks/prepare-plug-edgex-secretstore-token
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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



0 comments on commit 4930e0c

Please sign in to comment.