Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(snap): make secretstore connect hook idempotent #3815

Merged
merged 2 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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