Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Required by Fabric, Power BI, Microsoft Graph, and SharePoint examples.
TENANT_ID=<azure-tenant-id>
CLIENT_ID=<app-registration-client-id>
CLIENT_SECRET=<app-registration-client-secret>
FABRIC_TENANT_ID=<azure-tenant-id>
FABRIC_CLIENT_ID=<app-registration-client-id>
FABRIC_CLIENT_SECRET=<app-registration-client-secret>

# Required only by examples/database.py.
FABRIC_SQL_ENDPOINT=<server>.datawarehouse.fabric.microsoft.com
Expand Down
11 changes: 6 additions & 5 deletions docs/dataflow_gen2_cicd_upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Fabric currently rejects a Dataflow Gen2 CI/CD refresh initiated by an SPN with
poll the refresh job. The user must have Member or higher workspace access and
access to every connection used by the dataflow. Connection visibility or an
`Online` connection test alone does not prove that refresh will succeed.
The interactive login is requested in the configured `TENANT_ID`, which also
matters when the user is a guest whose home tenant differs from the workspace
tenant.
The interactive login is requested in the configured `FABRIC_TENANT_ID`, which
also matters when the user is a guest whose home tenant differs from the
workspace tenant.

## Prerequisites

Expand All @@ -40,8 +40,9 @@ tenant.
3. Sign in as a user with Member or higher workspace access and access to all
those connections. Interactive login must be possible on the machine running
the script. Do not substitute an SPN token for this user token.
4. Set `TENANT_ID`, `CLIENT_ID`, and `CLIENT_SECRET` in `.env`, as described in
[the examples guide](../examples/README.md). Keep `.env` out of Git.
4. Set `FABRIC_TENANT_ID`, `FABRIC_CLIENT_ID`, and `FABRIC_CLIENT_SECRET` in
`.env`, as described in [the examples guide](../examples/README.md). Keep
`.env` out of Git.

The exact-match mode currently handles literal `Sql.Database(server, database)`,
`Fabric.Warehouse`, and `Lakehouse.Contents` calls. Dynamic SQL arguments and
Expand Down
8 changes: 4 additions & 4 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ it local:
cp .env.example .env
```

Set `TENANT_ID`, `CLIENT_ID`, and `CLIENT_SECRET` for Fabric, Power BI, Graph,
and SharePoint examples. The database and SharePoint scripts list their extra
variables in `.env.example`. See [Examples](../examples/README.md) for each
script's API audience and safety level.
Set `FABRIC_TENANT_ID`, `FABRIC_CLIENT_ID`, and `FABRIC_CLIENT_SECRET` for
Fabric, Power BI, Graph, and SharePoint examples. The database and SharePoint
scripts list their extra variables in `.env.example`. See
[Examples](../examples/README.md) for each script's API audience and safety level.

## Run and validate

Expand Down
6 changes: 4 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ Set the values required by the script you choose. Never commit `.env`.
| `sharepoint.py` | Microsoft Graph | Does not perform a file operation | `SP_HOSTNAME`, `SP_SITE_PATH` |
| `database.py` | Fabric SQL endpoint | Does not perform a write | `FABRIC_SQL_ENDPOINT`, `FABRIC_DATABASE` |

Any script that reaches an API call requires `TENANT_ID`, `CLIENT_ID`, and
`CLIENT_SECRET`.
The Fabric, Power BI, Graph, and SharePoint API examples require
`FABRIC_TENANT_ID`, `FABRIC_CLIENT_ID`, and `FABRIC_CLIENT_SECRET`. The database
example uses `FABRIC_CLIENT_ID` and `FABRIC_CLIENT_SECRET` with its SQL endpoint
and database settings.

## Run

Expand Down
7 changes: 5 additions & 2 deletions examples/_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def require_configured_value(value: str, name: str) -> str:
def build_auth() -> Auth:
"""Build the shared Azure credential used by Fabric, Graph, and SharePoint."""
tenant_id, client_id, client_secret = require_environment(
"TENANT_ID", "CLIENT_ID", "CLIENT_SECRET"
"FABRIC_TENANT_ID", "FABRIC_CLIENT_ID", "FABRIC_CLIENT_SECRET"
)
return Auth(tenant_id, client_id, client_secret)

Expand Down Expand Up @@ -113,6 +113,9 @@ def build_sharepoint_client() -> SharePointClient:
def build_database_client() -> Database:
"""Build a Fabric SQL endpoint client without opening a connection."""
endpoint, database, client_id, client_secret = require_environment(
"FABRIC_SQL_ENDPOINT", "FABRIC_DATABASE", "CLIENT_ID", "CLIENT_SECRET"
"FABRIC_SQL_ENDPOINT",
"FABRIC_DATABASE",
"FABRIC_CLIENT_ID",
"FABRIC_CLIENT_SECRET",
)
return Database(endpoint, database, client_id, client_secret)
2 changes: 1 addition & 1 deletion msdev_kit/fabric/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def get_report_definition(
return {"message": "Missing report id, please check.", "content": ""}

if operations is None:
# fabric_auth = Auth(TENANT_ID, CLIENT_ID, CLIENT_SECRET)
# fabric_auth = Auth(fabric_tenant_id, fabric_client_id, fabric_client_secret)
# fabric_token = fabric_auth.get_token('fabric')
operations = Operations(self.token)

Expand Down
69 changes: 69 additions & 0 deletions tests/fabric/test_example_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""Credential environment used by the runnable examples."""

import os
from unittest.mock import patch

import pytest

from examples import _setup


def test_build_auth_uses_fabric_prefixed_credentials():
values = {
"FABRIC_TENANT_ID": "fabric-tenant",
"FABRIC_CLIENT_ID": "fabric-client",
"FABRIC_CLIENT_SECRET": "fabric-secret",
"TENANT_ID": "legacy-tenant",
"CLIENT_ID": "legacy-client",
"CLIENT_SECRET": "legacy-secret",
}
with (
patch.dict(os.environ, values, clear=True),
patch.object(_setup, "Auth") as auth,
):
_setup.build_auth()

auth.assert_called_once_with("fabric-tenant", "fabric-client", "fabric-secret")


def test_build_auth_does_not_fall_back_to_legacy_credentials():
values = {
"TENANT_ID": "legacy-tenant",
"CLIENT_ID": "legacy-client",
"CLIENT_SECRET": "legacy-secret",
}
with patch.dict(os.environ, values, clear=True):
with pytest.raises(RuntimeError, match="FABRIC_TENANT_ID"):
_setup.build_auth()


def test_build_database_client_uses_fabric_prefixed_credentials():
values = {
"FABRIC_SQL_ENDPOINT": "server.example.com",
"FABRIC_DATABASE": "database",
"FABRIC_CLIENT_ID": "fabric-client",
"FABRIC_CLIENT_SECRET": "fabric-secret",
"CLIENT_ID": "legacy-client",
"CLIENT_SECRET": "legacy-secret",
}
with (
patch.dict(os.environ, values, clear=True),
patch.object(_setup, "Database") as database,
):
_setup.build_database_client()

database.assert_called_once_with(
"server.example.com", "database", "fabric-client", "fabric-secret"
)


def test_build_database_client_does_not_fall_back_to_legacy_credentials():
values = {
"FABRIC_SQL_ENDPOINT": "server.example.com",
"FABRIC_DATABASE": "database",
"CLIENT_ID": "legacy-client",
"CLIENT_SECRET": "legacy-secret",
}
with patch.dict(os.environ, values, clear=True):
with pytest.raises(RuntimeError, match="FABRIC_CLIENT_ID"):
_setup.build_database_client()
Loading