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:
Regular → Executable
+11
-10
@@ -1,23 +1,27 @@
|
||||
#!/bin/bash
|
||||
# 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)
|
||||
|
||||
if [ -z "$NOCODB_TOKEN" ]; then
|
||||
echo "Error: Could not retrieve NocoDB token"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Fixing SingleSelect columns in NocoDB..."
|
||||
|
||||
VAULT_TOKEN=$(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 | jq -r '.auth.client_token')
|
||||
NOCODB_TOKEN=$(curl -sk -H "X-Vault-Token: $VAULT_TOKEN" https://beavault.beawit.net:8200/v1/kv/data/api/infrastructure | jq -r '.data.data["nocodb-token"]')
|
||||
|
||||
echo "Got NocoDB token"
|
||||
|
||||
# Get column IDs
|
||||
echo "Fetching column IDs..."
|
||||
COLS=$(curl -s "http://192.168.25.5:8080/api/v2/meta/tables/mx149yctebfwvys" -H "xc-token: $NOCODB_TOKEN")
|
||||
TYPE_ID=$(echo "$COLS" | jq -r '.columns[] | select(.title=="type") | .id')
|
||||
SEVERITY_ID=$(echo "$COLS" | jq -r '.columns[] | select(.title=="severity") | .id')
|
||||
STATUS_ID=$(echo "$COLS" | jq -r '.columns[] | select(.title=="status") | .id')
|
||||
|
||||
echo "type column ID: $TYPE_ID"
|
||||
echo "severity column ID: $SEVERITY_ID"
|
||||
echo "status column ID: $STATUS_ID"
|
||||
|
||||
# Fix type column
|
||||
echo ""
|
||||
echo "Fixing type column..."
|
||||
@@ -25,7 +29,6 @@ curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/$TYPE_ID" \
|
||||
-H "xc-token: $NOCODB_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"dtxp": "'"'"'correction'"'"','"'"'preference'"'"','"'"'episode'"'"','"'"'decision'"'"','"'"'validation'"'"'"}' | jq -r '.columns[] | select(.title=="type") | .dtxp'
|
||||
|
||||
# Fix severity column
|
||||
echo ""
|
||||
echo "Fixing severity column..."
|
||||
@@ -33,7 +36,6 @@ curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/$SEVERITY_ID" \
|
||||
-H "xc-token: $NOCODB_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"dtxp": "'"'"'error'"'"','"'"'warning'"'"','"'"'auto-correct'"'"'"}' | jq -r '.columns[] | select(.title=="severity") | .dtxp'
|
||||
|
||||
# Fix status column
|
||||
echo ""
|
||||
echo "Fixing status column..."
|
||||
@@ -41,6 +43,5 @@ curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/$STATUS_ID" \
|
||||
-H "xc-token: $NOCODB_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"dtxp": "'"'"'active'"'"','"'"'reversed'"'"','"'"'deprecated'"'"'"}' | jq -r '.columns[] | select(.title=="status") | .dtxp'
|
||||
|
||||
echo ""
|
||||
echo "Done!"
|
||||
|
||||
Reference in New Issue
Block a user