Initial setup: Fabric API helper scripts and project config

- CLAUDE.md with API reference, auth setup, and workspace details
- scripts/fabric-api.sh: helper functions for Fabric REST API
- scripts/refresh-token.sh: token refresh and .env writer
- .gitignore: protect .env and .omc/

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
TheTrustedAdvisor 2026-03-11 07:51:50 +01:00
commit 9ce0527ac5
4 changed files with 166 additions and 0 deletions

67
scripts/fabric-api.sh Executable file
View file

@ -0,0 +1,67 @@
#!/bin/bash
# Microsoft Fabric API Helper Script
# Refreshes token and provides convenience functions for Fabric REST API
set -euo pipefail
FABRIC_RESOURCE="https://api.fabric.microsoft.com"
FABRIC_API_BASE="https://api.fabric.microsoft.com/v1"
# Get a fresh token
get_token() {
az account get-access-token --resource "$FABRIC_RESOURCE" --query accessToken -o tsv
}
# Generic GET request
fabric_get() {
local endpoint="$1"
local token
token=$(get_token)
curl -s -H "Authorization: Bearer $token" "${FABRIC_API_BASE}${endpoint}"
}
# List all workspaces
list_workspaces() {
fabric_get "/workspaces" | jq '.value[] | {id, displayName, type}'
}
# List items in a workspace
list_workspace_items() {
local workspace_id="$1"
fabric_get "/workspaces/${workspace_id}/items" | jq '.value[] | {id, displayName, type}'
}
# Get workspace details with all items
document_workspace() {
local workspace_id="$1"
local workspace_name
workspace_name=$(fabric_get "/workspaces/${workspace_id}" | jq -r '.displayName')
echo "=== Workspace: $workspace_name ==="
echo ""
echo "--- Items ---"
fabric_get "/workspaces/${workspace_id}/items" | jq -r '.value[] | "\(.type): \(.displayName) (\(.id))"'
}
# Document ALL workspaces
document_all() {
local token
token=$(get_token)
local workspaces
workspaces=$(curl -s -H "Authorization: Bearer $token" "${FABRIC_API_BASE}/workspaces" | jq -r '.value[] | .id')
for ws_id in $workspaces; do
document_workspace "$ws_id"
echo ""
done
}
# Get capacities
list_capacities() {
fabric_get "/capacities" | jq '.value'
}
# If called directly, run the specified function
if [[ "${1:-}" != "" ]]; then
"$@"
fi

33
scripts/refresh-token.sh Executable file
View file

@ -0,0 +1,33 @@
#!/bin/bash
# Refresh Fabric API token and write it to .env
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
ENV_FILE="$PROJECT_DIR/.env"
echo "Refreshing Microsoft Fabric API token..."
TOKEN=$(az account get-access-token --resource "https://api.fabric.microsoft.com" --query accessToken -o tsv)
TENANT_ID=$(az account show --query tenantId -o tsv)
ACCOUNT_NAME=$(az account show --query user.name -o tsv)
SUBSCRIPTION=$(az account show --query name -o tsv)
EXPIRES=$(az account get-access-token --resource "https://api.fabric.microsoft.com" --query expiresOn -o tsv)
cat > "$ENV_FILE" <<EOF
# Microsoft Fabric API Configuration
# Auto-generated by refresh-token.sh - DO NOT COMMIT
# Token expires: $EXPIRES
FABRIC_TOKEN=$TOKEN
FABRIC_TENANT_ID=$TENANT_ID
FABRIC_ACCOUNT=$ACCOUNT_NAME
FABRIC_SUBSCRIPTION=$SUBSCRIPTION
FABRIC_API_BASE=https://api.fabric.microsoft.com/v1
EOF
echo "Token written to .env"
echo " Tenant: $TENANT_ID"
echo " Account: $ACCOUNT_NAME"
echo " Subscription: $SUBSCRIPTION"
echo " Expires: $EXPIRES"