#!/bin/bash
# Get Grist API token from Vault
# Usage: source get_grist_token.sh (requires VAULT_TOKEN from vault_auth.sh)

if [ -z "$VAULT_TOKEN" ]; then
    echo "Error: Run vault_auth.sh first"
    return 1
fi

export GRIST_TOKEN=*** -sk -H "X-Vault-Token: $VAULT_TOKEN" \
  "https://beavault.beawit.net:8200/v1/kv/data/api/integration/grist" | jq -r '.data.data.token')

if [ -z "$GRIST_TOKEN" ] || [ "$GRIST_TOKEN" = "null" ]; then
    echo "Failed to get Grist token from Vault"
    return 1
fi

echo "Grist token retrieved: ${GRIST_TOKEN:***