From 9ce0527ac5e49e325db04ce713b6710146fa48fa Mon Sep 17 00:00:00 2001 From: TheTrustedAdvisor Date: Wed, 11 Mar 2026 07:51:50 +0100 Subject: [PATCH] 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 --- .gitignore | 2 ++ CLAUDE.md | 64 ++++++++++++++++++++++++++++++++++++++ scripts/fabric-api.sh | 67 ++++++++++++++++++++++++++++++++++++++++ scripts/refresh-token.sh | 33 ++++++++++++++++++++ 4 files changed, 166 insertions(+) create mode 100644 .gitignore create mode 100644 CLAUDE.md create mode 100755 scripts/fabric-api.sh create mode 100755 scripts/refresh-token.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..93ad088 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +.omc/ diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..82d9b4f --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,64 @@ +# Microsoft Fabric Environment Documentation + +## Project Goal +Document and analyze Microsoft Fabric environments via the Fabric REST API. + +## Authentication +- **Tenant ID:** `2bbd7e41-02c9-4b4e-8168-339f900c4319` +- **Account:** `matthias.gessenay@corporatesoftware.ch` +- **Subscription:** Microsoft Azure Sponsorship + +### Getting a fresh token +```bash +# Refresh token (writes to .env): +bash scripts/refresh-token.sh + +# Or inline: +FABRIC_TOKEN=$(az account get-access-token --resource "https://api.fabric.microsoft.com" --query accessToken -o tsv) +``` + +### Using the Fabric API +```bash +# Source the helper: +source scripts/fabric-api.sh + +# List workspaces: +list_workspaces + +# List items in a workspace: +list_workspace_items + +# Document a workspace: +document_workspace +``` + +## Fabric REST API Reference +- **Base URL:** `https://api.fabric.microsoft.com/v1` +- **Auth Header:** `Authorization: Bearer $FABRIC_TOKEN` + +### Key Endpoints +| Endpoint | Description | +|----------|-------------| +| `GET /workspaces` | List all workspaces | +| `GET /workspaces/{id}` | Get workspace details | +| `GET /workspaces/{id}/items` | List items in a workspace | +| `GET /capacities` | List capacities | +| `GET /workspaces/{id}/lakehouses/{id}` | Get lakehouse details | +| `GET /workspaces/{id}/lakehouses/{id}/tables` | List lakehouse tables | +| `GET /workspaces/{id}/semanticmodels/{id}` | Get semantic model details | +| `GET /workspaces/{id}/notebooks/{id}` | Get notebook details | +| `GET /workspaces/{id}/reports/{id}` | Get report details | + +### Item Types +Lakehouse, SQLEndpoint, SemanticModel, Report, Notebook, DataPipeline, Dataflow, Warehouse, Environment, SparkJobDefinition, MirroredDatabase, Eventstream, KQLDatabase, KQLQueryset, MLModel, MLExperiment + +## Key Workspaces +| Workspace | ID | +|-----------|-----| +| mf-202603-smstack | `feb90cd8-3d10-4429-8a97-fc53b4b47a8b` | + +## Conventions +- Always refresh token before API calls: `FABRIC_TOKEN=$(az account get-access-token --resource "https://api.fabric.microsoft.com" --query accessToken -o tsv)` +- Use `jq` for JSON parsing +- Output documentation as Markdown +- Never commit `.env` files (contains tokens) diff --git a/scripts/fabric-api.sh b/scripts/fabric-api.sh new file mode 100755 index 0000000..fc57379 --- /dev/null +++ b/scripts/fabric-api.sh @@ -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 diff --git a/scripts/refresh-token.sh b/scripts/refresh-token.sh new file mode 100755 index 0000000..bba0176 --- /dev/null +++ b/scripts/refresh-token.sh @@ -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" <