68 lines
1.6 KiB
Bash
68 lines
1.6 KiB
Bash
|
|
#!/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
|