unraid_api_key_renew: always sync registry key to conf
Previously exited early when key was found in registry without checking if the conf matched. After a reboot or key rotation the registry holds the current key but the conf could have a stale value causing API auth failures on every boot. Now compares registry key to conf value and syncs if they differ.
This commit is contained in:
@@ -63,8 +63,21 @@ KEY=$(echo "$EXISTING" | jq -r '.key // empty' 2>/dev/null)
|
||||
|
||||
if [[ -n "$KEY" ]]; then
|
||||
PREVIEW="${KEY:0:8}...${KEY: -4}"
|
||||
echo "API key valid ✅ — $VAR_NAME = $PREVIEW"
|
||||
log "Key found in registry — no renewal needed"
|
||||
# Always sync registry key → conf — prevents stale key mismatch after reboot/update
|
||||
CONF_KEY=$(grep "^\s*${VAR_NAME}\s*=" "$CONF_FILE" 2>/dev/null | \
|
||||
sed 's/.*="\(.*\)".*/\1/' | tr -d '[:space:]')
|
||||
if [[ "$CONF_KEY" == "$KEY" ]]; then
|
||||
echo "API key valid ✅ — $VAR_NAME = $PREVIEW"
|
||||
log "Key in sync — no update needed"
|
||||
exit 0
|
||||
fi
|
||||
log "Registry key differs from conf — syncing..."
|
||||
if grep -q "^\s*${VAR_NAME}\s*=" "$CONF_FILE"; then
|
||||
sed -i "s|^\(\s*${VAR_NAME}\s*=\s*\)\"[^\"]*\"|\1\"${KEY}\"|" "$CONF_FILE"
|
||||
else
|
||||
echo " ${VAR_NAME}=\"${KEY}\"" >> "$CONF_FILE"
|
||||
fi
|
||||
warn "API key synced to conf ✅ — $VAR_NAME = $PREVIEW"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user