Metadata-Version: 2.4
Name: vdstudio-dbtfabriclake-cred
Version: 0.1.0
Summary: Azure TokenCredential that fetches Fabric tokens from vd-studio's local OAuth endpoint, for use with dbt-fabricspark's token_credential auth method.
Project-URL: Homepage, https://github.com/pradipsodha-acceleratedata/vdstudio-dbtfabriclake-cred
Project-URL: Issues, https://github.com/pradipsodha-acceleratedata/vdstudio-dbtfabriclake-cred/issues
Author-email: Pradip Sodha <pradip.sodha@acceleratedata.ai>
License: Apache-2.0
Keywords: azure,credentials,dbt,fabric,fabricspark,vdstudio
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Database
Requires-Python: >=3.10
Requires-Dist: azure-core>=1.30.0
Requires-Dist: requests>=2.31.0
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: responses>=0.25; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

# vdstudio-dbtfabriclake-cred

An Azure `TokenCredential` that fetches Microsoft Fabric access tokens from a running vd-studio instance, for use with `dbt-fabricspark`'s `token_credential` authentication method.

## What it does

vd-studio runs a local HTTP server that handles OAuth refresh against Microsoft Fabric. This package exposes a small `TokenCredential` implementation that calls that server with a configured user id and returns a fresh access token on every request. Plug it into `dbt-fabricspark`'s `token_credential` auth path and `dbt` calls flow through vd-studio's OAuth.

## Install

```bash
pip install vdstudio-dbtfabriclake-cred
```

## Use

In `profiles.yml`:

```yaml
my_profile:
  outputs:
    dev:
      type: fabricspark
      method: livy
      authentication: token_credential
      credential_class: "vdstudio_dbtfabriclake_cred.VDStudioFabricCredential"
      # Both kwargs are optional; if omitted, the class reads
      # VD_STUDIO_TOKEN_URL and VD_STUDIO_USER_ID from the environment.
      credential_kwargs:
        endpoint_url: "{{ env_var('VD_STUDIO_TOKEN_URL') }}"
        user_id: "{{ env_var('VD_STUDIO_USER_ID') }}"
      endpoint: https://api.fabric.microsoft.com/v1
      workspaceid: "<your-workspace-uuid>"
      lakehouseid: "<your-lakehouse-uuid>"
      lakehouse: "<your-lakehouse-name>"
      schema: "<your-schema>"
```

## Environment variables

| Variable | Used as fallback for |
| --- | --- |
| `VD_STUDIO_TOKEN_URL` | `endpoint_url` constructor kwarg |
| `VD_STUDIO_USER_ID`  | `user_id` constructor kwarg |

If a kwarg is passed explicitly it wins; otherwise the env var is consulted. If neither is set, `__init__` raises `ValueError`.

## Endpoint contract

The package issues:

```
GET <endpoint_url>?scope=<scope>&user_id=<user_id>
```

with a 10-second default timeout. It expects a JSON response shaped like:

```json
{
  "access_token": "eyJ...",
  "expires_in": 3600
}
```

Non-200 responses:

| Status | Behavior |
| --- | --- |
| 401 | `RuntimeError("Token refresh failed. Please re-login in vd-studio.")` |
| 403 | `RuntimeError("Token endpoint rejected request. Must be called from localhost.")` |
| other | `requests.HTTPError` propagated from `raise_for_status()` |

`expires_in` defaults to 3600 seconds when absent.

## Development

```bash
pip install -e ".[dev]"
pytest
```

## License

Apache-2.0
