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:
commit
9ce0527ac5
4 changed files with 166 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
.env
|
||||
.omc/
|
||||
64
CLAUDE.md
Normal file
64
CLAUDE.md
Normal file
|
|
@ -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 <workspace-id>
|
||||
|
||||
# Document a workspace:
|
||||
document_workspace <workspace-id>
|
||||
```
|
||||
|
||||
## 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)
|
||||
67
scripts/fabric-api.sh
Executable file
67
scripts/fabric-api.sh
Executable 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
33
scripts/refresh-token.sh
Executable 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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue