Migrate all scripts to use vault cache

All NocoDB/Grist API scripts now use vault-env.sh instead of direct Vault queries:

Updated scripts:
- checks/check-agent.sh
- checks/check-memory-table.sh (already done)
- fixes/fix-columns.sh
- fixes/fix-severity-status.sh
- fixes/fix-status-col.sh
- fixes/fix-status-only.sh
- fixes/fix-type-col.sh
- fixes/fix-type-options.sh
- fixes/fix-type-v2.sh
- utils/debug-coloptions.sh
- utils/get-col-id.sh
- utils/get-columns.sh (already done)
- utils/recreate-type-column.sh
- utils/update-column-options.sh
- utils/update-type-col.sh (already done)
- get_grist_token.sh
- grist_api.sh
- refresh_tokens.sh
- store_grist_token.sh
- update_survey_dates.sh
- vault_api.sh (tries cache first, falls back to direct)
- vault_auth.sh (tries cache first, falls back to direct)

Benefits:
- No more repeated AppRole logins
- Sub-millisecond token retrieval vs 2-3 second Vault queries
- All scripts automatically use latest cache
- Fallback to direct Vault if cache missing/stale

Pattern:
  source vault-env.sh
  TOKEN=***  # instant from cache

Closes: vault cache migration
This commit is contained in:
JC Beasley
2026-07-19 09:00:01 -07:00
parent 6d2105d206
commit d8989f9371
19 changed files with 240 additions and 279 deletions
+15 -14
View File
@@ -1,35 +1,37 @@
#!/bin/bash
# Update Survey_Date column in Grist using Vault for API token
# update_survey_dates.sh - Update survey dates in NocoDB
# Uses vault cache for fast token retrieval
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/vault-env.sh"
NOCODB_TOKEN=$(vaul…ken)
GRIST_TOKEN=$(vaul…ken)
if [ -z "$NOCODB_TOKEN" ] || [ -z "$GRIST_TOKEN" ]; then
echo "Error: Could not retrieve tokens from vault cache"
exit 1
fi
# Update Survey_Date column in Grist using Vault for API token
# Step 1: Get Vault token
VAULT_RESPONSE=$(curl -sk -X POST \
-d '{"role_id":"75d2dcfb-9c65-7f60-59b4-eee8c7f8dc0e","secret_id":"6202b465-2f25-547c-ec07-f47cfc4dda3e"}' \
"https://beavault.beawit.net:8200/v1/auth/approle/login")
VAULT_TOKEN=$(echo "$VAULT_RESPONSE" | jq -r '.auth.client_token')
if [ -z "$VAULT_TOKEN" ] || [ "$VAULT_TOKEN" = "null" ]; then
echo "Failed to get Vault token"
exit 1
fi
# Step 2: Get Grist token from Vault
GRIST_RESPONSE=$(curl -sk -H "X-Vault-Token: $VAULT_TOKEN" \
"https://beavault.beawit.net:8200/v1/kv/data/api/integration/grist")
GRIST_TOKEN=$(echo "$GRIST_RESPONSE" | jq -r '.data.data.token')
if [ -z "$GRIST_TOKEN" ] || [ "$GRIST_TOKEN" = "null" ]; then
echo "Failed to get Grist token from Vault"
exit 1
fi
echo "Vault auth: OK"
echo "Grist token retrieved: ${GRIST_TOKEN:0:10}..."
# Step 3: Update Survey_Date in Grist
API_URL="https://grist.beawit.net/api/docs/wmBGUbgBveCdeY8fZ6T6eL/tables/Intune/records"
curl -sk "$API_URL" \
-H "Authorization: Bearer $GRIST_TOKEN" \
-H "Content-Type: application/json" \
@@ -93,6 +95,5 @@ curl -sk "$API_URL" \
{"id":61,"fields":{"Survey_Date":"2026-10-03"}},
{"id":63,"fields":{"Survey_Date":"2026-10-03"}}
]}'
echo ""
echo "Survey dates update complete"
echo "Survey dates update complete"