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
34 lines
904 B
Bash
Executable File
34 lines
904 B
Bash
Executable File
#!/bin/bash
|
|
# grist_api.sh - Grist API wrapper using vault cache
|
|
# Usage: source this file or call its functions
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "${SCRIPT_DIR}/vault-env.sh"
|
|
|
|
GRIST_URL="https://grist.beawit.net"
|
|
GRIST_TOKEN=$(vaul…ken)
|
|
|
|
if [ -z "$GRIST_TOKEN" ]; then
|
|
echo "Error: Could not retrieve Grist token from vault cache"
|
|
return 1 2>/dev/null || exit 1
|
|
fi
|
|
|
|
# Function to make Grist API calls
|
|
grist_api() {
|
|
local method="${1:-GET}"
|
|
local endpoint="$2"
|
|
local payload="${3:-}"
|
|
|
|
local headers=(-H "Authorization: Bearer ${GRIST_TOKEN}" -H "Content-Type: application/json")
|
|
|
|
if [ "$method" = "GET" ]; then
|
|
curl -sk "${headers[@]}" "${GRIST_URL}${endpoint}"
|
|
else
|
|
curl -sk -X "$method" "${headers[@]}" -d "$payload" "${GRIST_URL}${endpoint}"
|
|
fi
|
|
}
|
|
|
|
# Export
|
|
export -f grist_api
|
|
export GRIST_URL GRIST_TOKEN
|