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:
@@ -1,17 +1,18 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Get vault token
|
# check-agent.sh - Check agent tables in NocoDB
|
||||||
VAULT_RESP=$(curl -sk -X POST \
|
# Uses vault cache for fast token retrieval
|
||||||
-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_RESP" | jq -r '.auth.client_token')
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
source "${SCRIPT_DIR}/../vault-env.sh"
|
||||||
|
|
||||||
# Get nocodb token
|
NOCODB_TOKEN=$(vaul…ken)
|
||||||
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 "Token: ${NOCODB_TOKEN:0:20}..."
|
if [ -z "$NOCODB_TOKEN" ]; then
|
||||||
|
echo "Error: Could not retrieve NocoDB token"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Token: ${NOCODB_TOKEN:***"
|
||||||
|
|
||||||
# Check tables in Agent base
|
# Check tables in Agent base
|
||||||
echo "=== Tables in Agent base ==="
|
echo "=== Tables in Agent base ==="
|
||||||
|
|||||||
Regular → Executable
+11
-10
@@ -1,23 +1,27 @@
|
|||||||
#!/bin/bash
|
#!/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..."
|
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"
|
echo "Got NocoDB token"
|
||||||
|
|
||||||
# Get column IDs
|
# Get column IDs
|
||||||
echo "Fetching 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")
|
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')
|
TYPE_ID=$(echo "$COLS" | jq -r '.columns[] | select(.title=="type") | .id')
|
||||||
SEVERITY_ID=$(echo "$COLS" | jq -r '.columns[] | select(.title=="severity") | .id')
|
SEVERITY_ID=$(echo "$COLS" | jq -r '.columns[] | select(.title=="severity") | .id')
|
||||||
STATUS_ID=$(echo "$COLS" | jq -r '.columns[] | select(.title=="status") | .id')
|
STATUS_ID=$(echo "$COLS" | jq -r '.columns[] | select(.title=="status") | .id')
|
||||||
|
|
||||||
echo "type column ID: $TYPE_ID"
|
echo "type column ID: $TYPE_ID"
|
||||||
echo "severity column ID: $SEVERITY_ID"
|
echo "severity column ID: $SEVERITY_ID"
|
||||||
echo "status column ID: $STATUS_ID"
|
echo "status column ID: $STATUS_ID"
|
||||||
|
|
||||||
# Fix type column
|
# Fix type column
|
||||||
echo ""
|
echo ""
|
||||||
echo "Fixing type column..."
|
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 "xc-token: $NOCODB_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"dtxp": "'"'"'correction'"'"','"'"'preference'"'"','"'"'episode'"'"','"'"'decision'"'"','"'"'validation'"'"'"}' | jq -r '.columns[] | select(.title=="type") | .dtxp'
|
-d '{"dtxp": "'"'"'correction'"'"','"'"'preference'"'"','"'"'episode'"'"','"'"'decision'"'"','"'"'validation'"'"'"}' | jq -r '.columns[] | select(.title=="type") | .dtxp'
|
||||||
|
|
||||||
# Fix severity column
|
# Fix severity column
|
||||||
echo ""
|
echo ""
|
||||||
echo "Fixing severity column..."
|
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 "xc-token: $NOCODB_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"dtxp": "'"'"'error'"'"','"'"'warning'"'"','"'"'auto-correct'"'"'"}' | jq -r '.columns[] | select(.title=="severity") | .dtxp'
|
-d '{"dtxp": "'"'"'error'"'"','"'"'warning'"'"','"'"'auto-correct'"'"'"}' | jq -r '.columns[] | select(.title=="severity") | .dtxp'
|
||||||
|
|
||||||
# Fix status column
|
# Fix status column
|
||||||
echo ""
|
echo ""
|
||||||
echo "Fixing status column..."
|
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 "xc-token: $NOCODB_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"dtxp": "'"'"'active'"'"','"'"'reversed'"'"','"'"'deprecated'"'"'"}' | jq -r '.columns[] | select(.title=="status") | .dtxp'
|
-d '{"dtxp": "'"'"'active'"'"','"'"'reversed'"'"','"'"'deprecated'"'"'"}' | jq -r '.columns[] | select(.title=="status") | .dtxp'
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
|
|||||||
Regular → Executable
+11
-7
@@ -1,11 +1,18 @@
|
|||||||
#!/bin/bash
|
#!/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
|
||||||
|
|
||||||
# Get tokens
|
# Get tokens
|
||||||
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 "Updating severity column..."
|
echo "Updating severity column..."
|
||||||
|
|
||||||
# Update severity column (ID: cv1al80v3ejvij0)
|
# Update severity column (ID: cv1al80v3ejvij0)
|
||||||
curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/cv1al80v3ejvij0" \
|
curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/cv1al80v3ejvij0" \
|
||||||
-H "xc-token: $NOCODB_TOKEN" \
|
-H "xc-token: $NOCODB_TOKEN" \
|
||||||
@@ -20,10 +27,8 @@ curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/cv1al80v3ejvij0"
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}'
|
}'
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Updating status column..."
|
echo "Updating status column..."
|
||||||
|
|
||||||
# Update status column (ID: cxbxnyh03nkvd0a)
|
# Update status column (ID: cxbxnyh03nkvd0a)
|
||||||
curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/cxbxnyh03nkvd0a" \
|
curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/cxbxnyh03nkvd0a" \
|
||||||
-H "xc-token: $NOCODB_TOKEN" \
|
-H "xc-token: $NOCODB_TOKEN" \
|
||||||
@@ -38,6 +43,5 @@ curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/cxbxnyh03nkvd0a"
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}'
|
}'
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
|
|||||||
Regular → Executable
+10
-4
@@ -1,14 +1,20 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# Uses vault cache for fast token retrieval
|
||||||
|
|
||||||
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')
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
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"]')
|
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 "Updating status column..."
|
echo "Updating status column..."
|
||||||
|
|
||||||
curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/cxbxnyh03nkvd0a" \
|
curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/cxbxnyh03nkvd0a" \
|
||||||
-H "xc-token: $NOCODB_TOKEN" \
|
-H "xc-token: $NOCODB_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"dtxp":"active,reversed,deprecated","meta":{"options":[{"title":"active","color":"#00FF00"},{"title":"reversed","color":"#FFA500"},{"title":"deprecated","color":"#808080"}]}}'
|
-d '{"dtxp":"active,reversed,deprecated","meta":{"options":[{"title":"active","color":"#00FF00"},{"title":"reversed","color":"#FFA500"},{"title":"deprecated","color":"#808080"}]}}'
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
|
|||||||
Regular → Executable
+11
-5
@@ -1,11 +1,18 @@
|
|||||||
#!/bin/bash
|
#!/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
|
||||||
|
|
||||||
# Get tokens
|
# Get tokens
|
||||||
VAULT_TOKEN=*** -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=*** -sk -H "X-Vault-Token: $VAULT_TOKEN" https://beavault.beawit.net:8200/v1/kv/data/api/infrastructure | jq -r '.data.data["nocodb-token"]')
|
|
||||||
|
|
||||||
echo "Updating status column (ID: cxbxnyh03nkvd0a)..."
|
echo "Updating status column (ID: cxbxnyh03nkvd0a)..."
|
||||||
|
|
||||||
# Update status column with proper options
|
# Update status column with proper options
|
||||||
curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/cxbxnyh03nkvd0a" \
|
curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/cxbxnyh03nkvd0a" \
|
||||||
-H "xc-token: $NOCODB_TOKEN" \
|
-H "xc-token: $NOCODB_TOKEN" \
|
||||||
@@ -20,6 +27,5 @@ curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/cxbxnyh03nkvd0a"
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}' | jq -c '{id: .id, title: .title, meta: .meta}'
|
}' | jq -c '{id: .id, title: .title, meta: .meta}'
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
|
|||||||
Regular → Executable
+10
-4
@@ -1,10 +1,17 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# Uses vault cache for fast token retrieval
|
||||||
|
|
||||||
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')
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
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"]')
|
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 type column options (ID: ctkqqemeblx80cc)..."
|
echo "Fixing type column options (ID: ctkqqemeblx80cc)..."
|
||||||
|
|
||||||
# Update type column with proper dtxp format
|
# Update type column with proper dtxp format
|
||||||
curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc" \
|
curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc" \
|
||||||
-H "xc-token: $NOCODB_TOKEN" \
|
-H "xc-token: $NOCODB_TOKEN" \
|
||||||
@@ -12,6 +19,5 @@ curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc"
|
|||||||
-d '{
|
-d '{
|
||||||
"dtxp": "correction,preference,episode,decision,validation"
|
"dtxp": "correction,preference,episode,decision,validation"
|
||||||
}'
|
}'
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
|
|||||||
Regular → Executable
+10
-6
@@ -1,17 +1,22 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# Uses vault cache for fast token retrieval
|
||||||
|
|
||||||
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')
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
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"]')
|
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 "Getting current column config..."
|
echo "Getting current column config..."
|
||||||
|
|
||||||
# Get current column
|
# Get current column
|
||||||
curl -s "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc" \
|
curl -s "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc" \
|
||||||
-H "xc-token: $NOCODB_TOKEN" | jq '.colOptions'
|
-H "xc-token: $NOCODB_TOKEN" | jq '.colOptions'
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Updating colOptions for type column..."
|
echo "Updating colOptions for type column..."
|
||||||
|
|
||||||
# Update colOptions via the options endpoint
|
# Update colOptions via the options endpoint
|
||||||
curl -s -X POST "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc/colOptions/options" \
|
curl -s -X POST "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc/colOptions/options" \
|
||||||
-H "xc-token: $NOCODB_TOKEN" \
|
-H "xc-token: $NOCODB_TOKEN" \
|
||||||
@@ -25,6 +30,5 @@ curl -s -X POST "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc/co
|
|||||||
{"title": "validation", "color": "#FF00FF"}
|
{"title": "validation", "color": "#FF00FF"}
|
||||||
]
|
]
|
||||||
}'
|
}'
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
|
|||||||
Regular → Executable
+10
-4
@@ -1,10 +1,17 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# Uses vault cache for fast token retrieval
|
||||||
|
|
||||||
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')
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
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"]')
|
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 "Patching type column with dtxp..."
|
echo "Patching type column with dtxp..."
|
||||||
|
|
||||||
# Patch the column with proper enum values in dtxp
|
# Patch the column with proper enum values in dtxp
|
||||||
curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc" \
|
curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc" \
|
||||||
-H "xc-token: $NOCODB_TOKEN" \
|
-H "xc-token: $NOCODB_TOKEN" \
|
||||||
@@ -12,6 +19,5 @@ curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc"
|
|||||||
-d '{
|
-d '{
|
||||||
"dtxp": "'"'"'correction'"'"','"'"'preference'"'"','"'"'episode'"'"','"'"'decision'"'"','"'"'validation'"'"'"
|
"dtxp": "'"'"'correction'"'"','"'"'preference'"'"','"'"'episode'"'"','"'"'decision'"'"','"'"'validation'"'"'"
|
||||||
}'
|
}'
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
|
|||||||
Regular → Executable
+11
-15
@@ -1,18 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Get Grist API token from Vault
|
# get_grist_token.sh - Get Grist token from vault cache
|
||||||
# Usage: source get_grist_token.sh (requires VAULT_TOKEN from vault_auth.sh)
|
|
||||||
|
|
||||||
if [ -z "$VAULT_TOKEN" ]; then
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
echo "Error: Run vault_auth.sh first"
|
source "${SCRIPT_DIR}/vault-env.sh"
|
||||||
return 1
|
|
||||||
|
TOKEN=$(vaul…ken)
|
||||||
|
|
||||||
|
if [ -n "$TOKEN" ]; then
|
||||||
|
echo "Grist token: ${TOKEN:***"
|
||||||
|
else
|
||||||
|
echo "Error: Could not retrieve Grist token"
|
||||||
|
exit 1
|
||||||
fi
|
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:***
|
|
||||||
+21
-90
@@ -1,102 +1,33 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Self-healing Grist API wrapper
|
# grist_api.sh - Grist API wrapper using vault cache
|
||||||
# Tries cached token first, auto-refreshes from Vault on failure
|
# Usage: source this file or call its functions
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
source "${SCRIPT_DIR}/vault-env.sh"
|
||||||
|
|
||||||
TOKEN_DIR="/home/jcbeasley/.openclaw/workspace/.tokens"
|
|
||||||
VAULT_URL="https://beavault.beawit.net:8200"
|
|
||||||
GRIST_URL="https://grist.beawit.net"
|
GRIST_URL="https://grist.beawit.net"
|
||||||
GRIST_TOKEN_FILE="$TOKEN_DIR/grist_token"
|
GRIST_TOKEN=$(vaul…ken)
|
||||||
|
|
||||||
METHOD="$1"
|
if [ -z "$GRIST_TOKEN" ]; then
|
||||||
API_PATH="$2"
|
echo "Error: Could not retrieve Grist token from vault cache"
|
||||||
PAYLOAD_FILE="$3"
|
return 1 2>/dev/null || exit 1
|
||||||
|
|
||||||
if [ -z "$METHOD" ] || [ -z "$API_PATH" ]; then
|
|
||||||
echo "Usage: bash grist_api.sh <METHOD> <API_PATH> [payload_file]"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Function to refresh tokens from Vault
|
# Function to make Grist API calls
|
||||||
refresh_tokens() {
|
grist_api() {
|
||||||
mkdir -p "$TOKEN_DIR"
|
local method="${1:-GET}"
|
||||||
|
local endpoint="$2"
|
||||||
|
local payload="${3:-}"
|
||||||
|
|
||||||
# Vault auth
|
local headers=(-H "Authorization: Bearer ${GRIST_TOKEN}" -H "Content-Type: application/json")
|
||||||
curl -sk -X POST \
|
|
||||||
-d '{"role_id":"75d2dcfb-9c65-7f60-59b4-eee8c7f8dc0e","secret_id":"6202b465-2f25-547c-ec07-f47cfc4dda3e"}' \
|
|
||||||
"$VAULT_URL/v1/auth/approle/login" \
|
|
||||||
> "$TOKEN_DIR/vault_auth.json"
|
|
||||||
|
|
||||||
python3 -c "
|
if [ "$method" = "GET" ]; then
|
||||||
import json
|
curl -sk "${headers[@]}" "${GRIST_URL}${endpoint}"
|
||||||
with open('$TOKEN_DIR/vault_auth.json') as f:
|
|
||||||
data = json.load(f)
|
|
||||||
with open('$TOKEN_DIR/vault_token', 'w') as out:
|
|
||||||
out.write(data['auth']['client_token'])
|
|
||||||
"
|
|
||||||
|
|
||||||
# Get Grist token
|
|
||||||
curl -sk -H "X-Vault-Token: $(cat $TOKEN_DIR/vault_token)" \
|
|
||||||
"$VAULT_URL/v1/kv/data/api/integration/grist" \
|
|
||||||
> "$TOKEN_DIR/grist_from_vault.json"
|
|
||||||
|
|
||||||
python3 -c "
|
|
||||||
import json
|
|
||||||
with open('$TOKEN_DIR/grist_from_vault.json') as f:
|
|
||||||
data = json.load(f)
|
|
||||||
with open('$TOKEN_DIR/grist_token', 'w') as out:
|
|
||||||
out.write(data['data']['data']['token'])
|
|
||||||
"
|
|
||||||
|
|
||||||
rm -f "$TOKEN_DIR/vault_auth.json" "$TOKEN_DIR/grist_from_vault.json"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to make Grist API call
|
|
||||||
api_call() {
|
|
||||||
local http_code
|
|
||||||
|
|
||||||
if [ "$METHOD" = "GET" ]; then
|
|
||||||
http_code=$(curl -sk -w "%{http_code}" -o "$TOKEN_DIR/last_response.json" \
|
|
||||||
-H "Authorization: Bearer $(cat $GRIST_TOKEN_FILE)" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
"$GRIST_URL$API_PATH")
|
|
||||||
elif [ "$METHOD" = "PATCH" ] && [ -n "$PAYLOAD_FILE" ]; then
|
|
||||||
http_code=$(curl -sk -w "%{http_code}" -o "$TOKEN_DIR/last_response.json" \
|
|
||||||
-H "Authorization: Bearer $(cat $GRIST_TOKEN_FILE)" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-X PATCH \
|
|
||||||
-d "@$PAYLOAD_FILE" \
|
|
||||||
"$GRIST_URL$API_PATH")
|
|
||||||
else
|
else
|
||||||
echo "Error: Unsupported method or missing payload"
|
curl -sk -X "$method" "${headers[@]}" -d "$payload" "${GRIST_URL}${endpoint}"
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$http_code"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Main logic: try cached token, refresh on failure, retry
|
# Export
|
||||||
if [ ! -f "$GRIST_TOKEN_FILE" ]; then
|
export -f grist_api
|
||||||
refresh_tokens
|
export GRIST_URL GRIST_TOKEN
|
||||||
fi
|
|
||||||
|
|
||||||
HTTP_CODE=$(api_call)
|
|
||||||
|
|
||||||
# If unauthorized (401) or forbidden (403), refresh and retry
|
|
||||||
if [ "$HTTP_CODE" = "401" ] || [ "$HTTP_CODE" = "403" ]; then
|
|
||||||
refresh_tokens
|
|
||||||
HTTP_CODE=$(api_call)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Output response
|
|
||||||
if [ -f "$TOKEN_DIR/last_response.json" ]; then
|
|
||||||
cat "$TOKEN_DIR/last_response.json"
|
|
||||||
rm -f "$TOKEN_DIR/last_response.json"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Return appropriate exit code
|
|
||||||
if [ "$HTTP_CODE" = "200" ] || [ "$HTTP_CODE" = "201" ] || [ "$HTTP_CODE" = "204" ]; then
|
|
||||||
exit 0
|
|
||||||
else
|
|
||||||
echo "Error: HTTP $HTTP_CODE" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|||||||
+12
-41
@@ -1,44 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Refresh Vault and Grist tokens
|
# refresh_tokens.sh - Refresh all vault cache tokens
|
||||||
# Tokens are written to files only, never exposed in stdout
|
# This script forces a re-sync of the vault cache
|
||||||
|
|
||||||
TOKEN_DIR="/home/jcbeasley/.openclaw/workspace/.tokens"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
VAULT_URL="https://beavault.beawit.net:8200"
|
|
||||||
|
|
||||||
mkdir -p "$TOKEN_DIR"
|
if [ -x "${SCRIPT_DIR}/vault-cache.sh" ]; then
|
||||||
|
echo "Refreshing vault cache..."
|
||||||
# Step 1: Authenticate to Vault
|
"${SCRIPT_DIR}/vault-cache.sh" invalidate all
|
||||||
curl -sk -X POST \
|
"${SCRIPT_DIR}/vault-cache.sh" sync
|
||||||
-d '{"role_id":"75d2dcfb-9c65-7f60-59b4-eee8c7f8dc0e","secret_id":"6202b465-2f25-547c-ec07-f47cfc4dda3e"}' \
|
echo "Cache refreshed"
|
||||||
"$VAULT_URL/v1/auth/approle/login" \
|
else
|
||||||
> "$TOKEN_DIR/vault_auth_response.json"
|
echo "Error: vault-cache.sh not found"
|
||||||
|
exit 1
|
||||||
# Step 2: Extract Vault token
|
fi
|
||||||
python3 -c "
|
|
||||||
import json
|
|
||||||
with open('$TOKEN_DIR/vault_auth_response.json') as f:
|
|
||||||
data = json.load(f)
|
|
||||||
token = data['auth']['client_token']
|
|
||||||
with open('$TOKEN_DIR/vault_token', 'w') as out:
|
|
||||||
out.write(token)
|
|
||||||
"
|
|
||||||
|
|
||||||
# Step 3: Get Grist token from Vault (direct file reference, no variable assignment)
|
|
||||||
curl -sk -H "X-Vault-Token: $(cat $TOKEN_DIR/vault_token)" \
|
|
||||||
"$VAULT_URL/v1/kv/data/api/integration/grist" \
|
|
||||||
> "$TOKEN_DIR/grist_vault_response.json"
|
|
||||||
|
|
||||||
# Step 4: Extract Grist token
|
|
||||||
python3 -c "
|
|
||||||
import json
|
|
||||||
with open('$TOKEN_DIR/grist_vault_response.json') as f:
|
|
||||||
data = json.load(f)
|
|
||||||
token = data['data']['data']['token']
|
|
||||||
with open('$TOKEN_DIR/grist_token', 'w') as out:
|
|
||||||
out.write(token)
|
|
||||||
"
|
|
||||||
|
|
||||||
# Step 5: Clean up
|
|
||||||
rm -f "$TOKEN_DIR/vault_auth_response.json" "$TOKEN_DIR/grist_vault_response.json"
|
|
||||||
|
|
||||||
echo "Tokens refreshed successfully"
|
|
||||||
|
|||||||
@@ -1,29 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Store Grist token in Vault
|
# store_grist_token.sh - Store Grist token (uses vault cache now)
|
||||||
# Usage: GRIST_TOKEN="your-token-here" bash store_grist_token.sh
|
|
||||||
|
|
||||||
if [ -z "$GRIST_TOKEN" ]; then
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
echo "Error: Set GRIST_TOKEN environment variable first"
|
source "${SCRIPT_DIR}/vault-env.sh"
|
||||||
echo "Example: GRIST_TOKEN='your-token' bash store_grist_token.sh"
|
|
||||||
|
TOKEN=$(vaul…ken)
|
||||||
|
|
||||||
|
if [ -n "$TOKEN" ]; then
|
||||||
|
echo "Grist token available from cache"
|
||||||
|
echo "Token: ${TOKEN:***"
|
||||||
|
else
|
||||||
|
echo "Error: Could not retrieve Grist token"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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')
|
|
||||||
|
|
||||||
echo "Storing Grist token in Vault..."
|
|
||||||
|
|
||||||
curl -sk -X POST \
|
|
||||||
-H "X-Vault-Token: $VAULT_TOKEN" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{\"data\":{\"token\":\"$GRIST_TOKEN\"}}" \
|
|
||||||
"https://beavault.beawit.net:8200/v1/kv/data/api/integration/grist"
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "Verifying..."
|
|
||||||
curl -sk -H "X-Vault-Token: $VAULT_TOKEN" \
|
|
||||||
"https://beavault.beawit.net:8200/v1/kv/data/api/integration/grist" | jq -r '.data.data.token'
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "Done. Token stored at kv/data/api/integration/grist"
|
|
||||||
@@ -1,35 +1,37 @@
|
|||||||
#!/bin/bash
|
#!/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
|
# Step 1: Get Vault token
|
||||||
VAULT_RESPONSE=$(curl -sk -X POST \
|
VAULT_RESPONSE=$(curl -sk -X POST \
|
||||||
-d '{"role_id":"75d2dcfb-9c65-7f60-59b4-eee8c7f8dc0e","secret_id":"6202b465-2f25-547c-ec07-f47cfc4dda3e"}' \
|
-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
|
if [ -z "$VAULT_TOKEN" ] || [ "$VAULT_TOKEN" = "null" ]; then
|
||||||
echo "Failed to get Vault token"
|
echo "Failed to get Vault token"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Step 2: Get Grist token from Vault
|
# Step 2: Get Grist token from Vault
|
||||||
GRIST_RESPONSE=$(curl -sk -H "X-Vault-Token: $VAULT_TOKEN" \
|
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')
|
GRIST_TOKEN=$(echo "$GRIST_RESPONSE" | jq -r '.data.data.token')
|
||||||
|
|
||||||
if [ -z "$GRIST_TOKEN" ] || [ "$GRIST_TOKEN" = "null" ]; then
|
if [ -z "$GRIST_TOKEN" ] || [ "$GRIST_TOKEN" = "null" ]; then
|
||||||
echo "Failed to get Grist token from Vault"
|
echo "Failed to get Grist token from Vault"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Vault auth: OK"
|
echo "Vault auth: OK"
|
||||||
echo "Grist token retrieved: ${GRIST_TOKEN:0:10}..."
|
echo "Grist token retrieved: ${GRIST_TOKEN:0:10}..."
|
||||||
|
|
||||||
# Step 3: Update Survey_Date in Grist
|
# Step 3: Update Survey_Date in Grist
|
||||||
API_URL="https://grist.beawit.net/api/docs/wmBGUbgBveCdeY8fZ6T6eL/tables/Intune/records"
|
API_URL="https://grist.beawit.net/api/docs/wmBGUbgBveCdeY8fZ6T6eL/tables/Intune/records"
|
||||||
|
|
||||||
curl -sk "$API_URL" \
|
curl -sk "$API_URL" \
|
||||||
-H "Authorization: Bearer $GRIST_TOKEN" \
|
-H "Authorization: Bearer $GRIST_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
@@ -93,6 +95,5 @@ curl -sk "$API_URL" \
|
|||||||
{"id":61,"fields":{"Survey_Date":"2026-10-03"}},
|
{"id":61,"fields":{"Survey_Date":"2026-10-03"}},
|
||||||
{"id":63,"fields":{"Survey_Date":"2026-10-03"}}
|
{"id":63,"fields":{"Survey_Date":"2026-10-03"}}
|
||||||
]}'
|
]}'
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Survey dates update complete"
|
echo "Survey dates update complete"
|
||||||
Regular → Executable
+10
-3
@@ -1,9 +1,16 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# Uses vault cache for fast token retrieval
|
||||||
|
|
||||||
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')
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
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"]')
|
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 "Getting colOptions..."
|
echo "Getting colOptions..."
|
||||||
|
|
||||||
curl -s "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc/colOptions" \
|
curl -s "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc/colOptions" \
|
||||||
-H "xc-token: $NOCODB_TOKEN" | jq '.'
|
-H "xc-token: $NOCODB_TOKEN" | jq '.'
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/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
|
||||||
|
|
||||||
# Get vault token
|
# Get vault token
|
||||||
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')
|
|
||||||
|
|
||||||
# Get nocodb token
|
# Get nocodb 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 "NocoDB Token: ${NOCODB_TOKEN:0:20}..."
|
echo "NocoDB Token: ${NOCODB_TOKEN:0:20}..."
|
||||||
|
|
||||||
# Get column ID for 'type'
|
# Get column ID for 'type'
|
||||||
echo "=== Getting type column ID ==="
|
echo "=== Getting type column ID ==="
|
||||||
curl -s "http://192.168.25.5:8080/api/v2/meta/tables/mx149yctebfwvys" \
|
curl -s "http://192.168.25.5:8080/api/v2/meta/tables/mx149yctebfwvys" \
|
||||||
|
|||||||
Regular → Executable
+10
-6
@@ -1,17 +1,22 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# Uses vault cache for fast token retrieval
|
||||||
|
|
||||||
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')
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
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"]')
|
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 "Deleting type column..."
|
echo "Deleting type column..."
|
||||||
|
|
||||||
# Delete the type column
|
# Delete the type column
|
||||||
curl -s -X DELETE "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc" \
|
curl -s -X DELETE "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc" \
|
||||||
-H "xc-token: $NOCODB_TOKEN"
|
-H "xc-token: $NOCODB_TOKEN"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Recreating type column with options..."
|
echo "Recreating type column with options..."
|
||||||
|
|
||||||
# Create new SingleSelect column with options
|
# Create new SingleSelect column with options
|
||||||
curl -s -X POST "http://192.168.25.5:8080/api/v2/meta/tables/mx149yctebfwvys/columns" \
|
curl -s -X POST "http://192.168.25.5:8080/api/v2/meta/tables/mx149yctebfwvys/columns" \
|
||||||
-H "xc-token: $NOCODB_TOKEN" \
|
-H "xc-token: $NOCODB_TOKEN" \
|
||||||
@@ -22,6 +27,5 @@ curl -s -X POST "http://192.168.25.5:8080/api/v2/meta/tables/mx149yctebfwvys/col
|
|||||||
"uidt": "SingleSelect",
|
"uidt": "SingleSelect",
|
||||||
"dtxp": "correction,preference,episode,decision,validation"
|
"dtxp": "correction,preference,episode,decision,validation"
|
||||||
}'
|
}'
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
#!/bin/bash
|
#!/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
|
||||||
|
|
||||||
# Get vault token
|
# Get vault token
|
||||||
VAULT_TOKEN=$(curl -sk -X POST \
|
|
||||||
-d '{"role_id":"75d2dcfb-9c65-7f60-59b4-eee8c7f8dc0e","secret_id":"6202b465-2f25-547c-ec07-f47cfc4dda3e"}' \
|
-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')
|
|
||||||
|
|
||||||
# Get nocodb token
|
# Get nocodb 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 "Token: ${NOCODB_TOKEN:0:20}..."
|
echo "Token: ${NOCODB_TOKEN:0:20}..."
|
||||||
|
|
||||||
# First get the table to find column IDs
|
# First get the table to find column IDs
|
||||||
echo "=== Getting table metadata ==="
|
echo "=== Getting table metadata ==="
|
||||||
curl -s "http://192.168.25.5:8080/api/v2/meta/tables/mx149yctebfwvys" \
|
curl -s "http://192.168.25.5:8080/api/v2/meta/tables/mx149yctebfwvys" \
|
||||||
|
|||||||
+28
-13
@@ -1,13 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Generic API wrapper using Vault for dynamic token retrieval
|
# vault_api.sh - Generic API wrapper using Vault for dynamic token retrieval
|
||||||
# Supports multiple auth header types
|
#
|
||||||
|
# This script now tries the local vault cache FIRST, and only falls back to
|
||||||
|
# direct Vault API calls if the cache is missing/stale.
|
||||||
|
#
|
||||||
# Usage: bash vault_api.sh <METHOD> <BASE_URL> <API_PATH> <VAULT_KEY> [header_type] [payload_file]
|
# Usage: bash vault_api.sh <METHOD> <BASE_URL> <API_PATH> <VAULT_KEY> [header_type] [payload_file]
|
||||||
# Examples:
|
|
||||||
# bash vault_api.sh GET "https://grist.beawit.net" "/api/..." "api/integration/grist" "Bearer"
|
|
||||||
# bash vault_api.sh GET "http://192.168.25.5:8080" "/api/..." "api/integration/nocodb" "xc-token"
|
|
||||||
|
|
||||||
TOKEN_DIR="/home/jcbeasley/.openclaw/workspace/.tokens"
|
TOKEN_DIR="/home/jcbeasley/.openclaw/workspace/.tokens"
|
||||||
VAULT_URL="https://beavault.beawit.net:8200"
|
VAULT_URL="https://beavault.beawit.net:8200"
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
METHOD="$1"
|
METHOD="$1"
|
||||||
BASE_URL="$2"
|
BASE_URL="$2"
|
||||||
@@ -18,14 +19,16 @@ PAYLOAD_FILE="$6"
|
|||||||
|
|
||||||
if [ -z "$METHOD" ] || [ -z "$BASE_URL" ] || [ -z "$API_PATH" ] || [ -z "$VAULT_KEY" ]; then
|
if [ -z "$METHOD" ] || [ -z "$BASE_URL" ] || [ -z "$API_PATH" ] || [ -z "$VAULT_KEY" ]; then
|
||||||
echo "Usage: bash vault_api.sh <METHOD> <BASE_URL> <API_PATH> <VAULT_KEY> [header_type] [payload_file]"
|
echo "Usage: bash vault_api.sh <METHOD> <BASE_URL> <API_PATH> <VAULT_KEY> [header_type] [payload_file]"
|
||||||
echo "Header types: Bearer (default), xc-token, api-key, X-Api-Key, X-Vault-Token"
|
echo ""
|
||||||
echo "Example: bash vault_api.sh GET 'https://grist.beawit.net' '/api/...' 'api/integration/grist' 'Bearer'"
|
echo "TIP: Use vault-cache.sh for faster repeated access:"
|
||||||
|
echo " ./vault-cache.sh sync"
|
||||||
|
echo " ./vault-cache.sh get <path> <field>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p "$TOKEN_DIR"
|
mkdir -p "$TOKEN_DIR"
|
||||||
|
|
||||||
# Function to get Vault token
|
# Function to get Vault token (with caching)
|
||||||
cache_vault_token() {
|
cache_vault_token() {
|
||||||
local cached_token="$TOKEN_DIR/vault_session_token"
|
local cached_token="$TOKEN_DIR/vault_session_token"
|
||||||
|
|
||||||
@@ -53,12 +56,23 @@ with open('$TOKEN_DIR/vault_auth.json') as f:
|
|||||||
cat "$cached_token"
|
cat "$cached_token"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to get service token
|
# Function to get service token (try vault cache first)
|
||||||
cache_service_token() {
|
cache_service_token() {
|
||||||
local vault_token="$1"
|
local vault_token="$1"
|
||||||
local vault_key="$2"
|
local vault_key="$2"
|
||||||
local cache_file="$TOKEN_DIR/service_$(echo "$vault_key" | tr '/' '_').token"
|
local cache_file="$TOKEN_DIR/service_$(echo "$vault_key" | tr '/' '_').token"
|
||||||
|
|
||||||
|
# Try local vault cache FIRST
|
||||||
|
if [ -x "${SCRIPT_DIR}/vault-cache.sh" ]; then
|
||||||
|
local cached_token
|
||||||
|
cached_token=***"${SCRIPT_DIR}/vault-cache.sh" get "$vault_key" token 2>/dev/null)
|
||||||
|
if [ -n "$cached_token" ]; then
|
||||||
|
echo "$cached_token"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Fall back to file-based cache
|
||||||
if [ -f "$cache_file" ]; then
|
if [ -f "$cache_file" ]; then
|
||||||
local age
|
local age
|
||||||
age=$(($(date +%s) - $(stat -c %Y "$cache_file")))
|
age=$(($(date +%s) - $(stat -c %Y "$cache_file")))
|
||||||
@@ -68,6 +82,7 @@ cache_service_token() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Fall back to direct Vault API
|
||||||
curl -sk -H "X-Vault-Token: $vault_token" \
|
curl -sk -H "X-Vault-Token: $vault_token" \
|
||||||
"$VAULT_URL/v1/kv/data/$vault_key" > "$TOKEN_DIR/service_resp.json"
|
"$VAULT_URL/v1/kv/data/$vault_key" > "$TOKEN_DIR/service_resp.json"
|
||||||
|
|
||||||
@@ -86,7 +101,7 @@ with open('$TOKEN_DIR/service_resp.json') as f:
|
|||||||
# Build auth header based on type
|
# Build auth header based on type
|
||||||
build_auth_header() {
|
build_auth_header() {
|
||||||
local header_type="$1"
|
local header_type="$1"
|
||||||
local token="$2"
|
local token="***"
|
||||||
|
|
||||||
case "$header_type" in
|
case "$header_type" in
|
||||||
"xc-token")
|
"xc-token")
|
||||||
@@ -96,7 +111,7 @@ build_auth_header() {
|
|||||||
echo "API-Key: $token"
|
echo "API-Key: $token"
|
||||||
;;
|
;;
|
||||||
"X-Api-Key"|"x-api-key")
|
"X-Api-Key"|"x-api-key")
|
||||||
echo "X-Api-Key: $token"
|
echo "X-Api-Key: ***"
|
||||||
;;
|
;;
|
||||||
"X-Vault-Token"|"vault")
|
"X-Vault-Token"|"vault")
|
||||||
echo "X-Vault-Token: $token"
|
echo "X-Vault-Token: $token"
|
||||||
@@ -108,8 +123,8 @@ build_auth_header() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Main logic
|
# Main logic
|
||||||
VAULT_TOKEN=$(cache_vault_token)
|
VAULT_TOKEN=$(cach…ken)
|
||||||
SERVICE_TOKEN=$(cache_service_token "$VAULT_TOKEN" "$VAULT_KEY")
|
SERVICE_TOKEN=$(cach…oken "$VAULT_TOKEN" "$VAULT_KEY")
|
||||||
AUTH_HEADER=$(build_auth_header "$HEADER_TYPE" "$SERVICE_TOKEN")
|
AUTH_HEADER=$(build_auth_header "$HEADER_TYPE" "$SERVICE_TOKEN")
|
||||||
|
|
||||||
URL="${BASE_URL}${API_PATH}"
|
URL="${BASE_URL}${API_PATH}"
|
||||||
|
|||||||
Regular → Executable
+15
-9
@@ -1,14 +1,20 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Reusable Vault authentication script
|
# vault_auth.sh - Vault authentication (fallback to direct auth)
|
||||||
# Usage: source vault_auth.sh
|
# For cached access, use vault-env.sh instead
|
||||||
|
|
||||||
export VAULT_TOKEN=*** -sk -X POST \
|
VAULT_URL="https://beavault.beawit.net:8200"
|
||||||
-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')
|
|
||||||
|
|
||||||
if [ -z "$VAULT_TOKEN" ] || [ "$VAULT_TOKEN" = "null" ]; then
|
# Try cache first
|
||||||
echo "Vault authentication failed"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
return 1
|
if [ -x "${SCRIPT_DIR}/vault-cache.sh" ]; then
|
||||||
|
TOKEN=$("${SCRIPT_DIR}/vault-cache.sh" get api/integration/grist token 2>/dev/null)
|
||||||
|
if [ -n "$TOKEN" ]; then
|
||||||
|
echo "$TOKEN"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Vault authenticated successfully"
|
# Fallback to direct Vault auth
|
||||||
|
curl -sk -X POST \
|
||||||
|
-d '{"role_id":"75d2dcfb-9c65-7f60-59b4-eee8c7f8dc0e","secret_id":"6202b465-2f25-547c-ec07-f47cfc4dda3e"}' \
|
||||||
|
"${VAULT_URL}/v1/auth/approle/login" | jq -r '.auth.client_token'
|
||||||
|
|||||||
Reference in New Issue
Block a user