Allow updating secret-store secrets by name (instead of id) #13225
alexkli
started this conversation in
Feature Requests
Replies: 2 comments
-
|
Related: with this in place, it would also be nice if the |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Here is my workaround. Tested on macOS and Linux. Depends on secret-store-update.sh#!/bin/bash
# Update or create secrets in Cloudflare Secret Store by NAME
set -e
STORE_ID="$1"
NAME="$2"
if [ -z "$STORE_ID" ] || [ -z "$NAME" ]; then
echo "Usage: echo <value> | secret-store-update.sh <secret-store-id> <name>"
echo
echo "Update or create secret in Cloudflare Secret Store by NAME."
echo "The secret <value> is passed via stdin to avoid exposing it in logs."
echo
echo " <secret-store-id> Cloudflare secret store ID (same as in production)"
echo
echo " <name> Name of the secret to update"
exit 1
fi
ID=$(wrangler secrets-store secret list $STORE_ID --remote 2>/dev/null | grep -F "$NAME" | awk '{print $4}')
if [ -z "$ID" ]; then
# if not found, create
cat /dev/stdin | wrangler secrets-store secret create $STORE_ID --remote --scopes workers --name "$NAME"
else
# if found, update
cat /dev/stdin | wrangler secrets-store secret update $STORE_ID --remote --scopes workers --secret-id "$ID"
fiExample invocation: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the solution
It would be very convenient if the
wrangler secrets-store secret updatecommand would support an option--name <name>that would update the secret by name, without the need to pass the secret id.Reason
Currently wrangler secrets-store secret update and the Patch a secret API require knowing the secret id. This makes it difficult to programmatically update a secret, e.g. for a secret rotation script.
One has to first call the command/API to list all secrets, parse the result, find the secret by name, get the id and then make the actual update command/request.
The cloudflare dashboard UI does not have this issue - I can select and edit a secret by name. From a worker developer/devops perspective, secret ids are an implementation detail that we normally don't care about at all.
Secret names have to be unique in the first place, so this should not create any issues.
Beta Was this translation helpful? Give feedback.
All reactions