Documentation
¶
Overview ¶
Package fabric provides a Microsoft Fabric executor. Fabric Warehouses (and Lakehouse SQL analytics endpoints) speak T-SQL over TDS, so this is a thin, opinionated wrapper over the MSSQL executor: it exposes only the knobs a Fabric connection actually needs and hard-codes the rest (port 1433, TLS on, Entra service-principal federated auth) so callers never have to guess which MSSQL auth flag combination Fabric requires.
Fabric rejects SQL logins entirely — the only headless identity is a Microsoft Entra ID service principal (app registration + secret). That maps onto the go-mssqldb azuread driver's ActiveDirectoryServicePrincipal workflow, where the username is the application (client) ID and the password is the client secret.
Index ¶
- Constants
- Variables
- func CanonicalAuthType(s string) string
- func IsPermissionError(err error) bool
- func IsUnavailableError(err error) bool
- func NewQuerier[T any](conn *FabricExecutor) querier.Querier[T]
- type APIClient
- type APIError
- type FabricConf
- type FabricExecutor
- type HostIdentity
- type WorkspacePrincipal
- type WorkspaceRoleAssignment
Constants ¶
const ( // AuthTypeServicePrincipal authenticates with an Entra service principal // (ClientID + ClientSecret). This is the default when AuthType is empty. // Aliases: "ServicePrincipal" (dbt-fabric), // "ActiveDirectoryServicePrincipal" (Microsoft ODBC). AuthTypeServicePrincipal = "service_principal" // AuthTypeAzureCLI reuses the host's interactive `az login` session — the // local-execution / developer-machine case. Aliases: "CLI" (dbt-fabric), // "ActiveDirectoryAzCli" (Microsoft ODBC), "az_cli". AuthTypeAzureCLI = "azure_cli" // AuthTypeDefault uses Azure's DefaultAzureCredential chain (managed // identity → environment → workload identity → az CLI). Aliases: "auto" // (dbt-fabric), "ActiveDirectoryDefault" (Microsoft ODBC), // "DefaultAzureCredential" (Azure SDK). AuthTypeDefault = "default" // AuthTypeManagedIdentity authenticates with an Azure managed identity; set // ClientID for a user-assigned identity, leave empty for system-assigned. // Aliases: "MSI", "ActiveDirectoryManagedIdentity" / "ActiveDirectoryMSI" // (Microsoft ODBC). AuthTypeManagedIdentity = "managed_identity" )
Canonical AuthType values for FabricConf.AuthType. Each method is recognized under several industry spellings (dbt-fabric, Microsoft's ODBC `Authentication=` keyword, the Azure SDK credential names, and our own snake_case) — see authTypeAliases — but these constants are the single canonical names to use when generating or suggesting config, so our output stays consistent. Matching is done via CanonicalAuthType (case- and separator-insensitive).
const FabricAPIBaseURL = "https://api.fabric.microsoft.com/v1"
FabricAPIBaseURL is the Fabric REST API root.
Variables ¶
var ErrNoAPICredential = errors.New("the Fabric connection has no credential for the Fabric REST API (a pre-acquired SQL access token)")
ErrNoAPICredential is returned by NewAPIClient when the configuration can only reach the SQL endpoint: a pre-acquired AccessToken is scoped to SQL and cannot be exchanged for a Fabric API token.
Functions ¶
func CanonicalAuthType ¶
CanonicalAuthType maps any accepted auth spelling (dbt-fabric, Microsoft ODBC, Azure SDK, or our own snake_case) to the single canonical AuthType* value. Empty input stays empty (interpreted as the service-principal default); unrecognized non-empty input is returned unchanged so callers can surface it. Use it whenever generating or suggesting config so the auth method reads the same everywhere.
func IsPermissionError ¶
IsPermissionError reports whether err indicates the connection's identity lacks privileges. Fabric surfaces the same SQL Server permission messages as MSSQL, so it delegates to the single source of truth. A Fabric REST API refusal (APIError 401/403) is one too.
func IsUnavailableError ¶ added in v0.21.0
IsUnavailableError reports whether err says the Fabric SQL surface has no such object, column or function: what SQL Server reports for a missing one (dwhexecmssql.IsUnavailableError), and Fabric's own "... is not supported" for the parts of T-SQL it leaves out (ORIGINAL_LOGIN, for one).
func NewQuerier ¶
func NewQuerier[T any](conn *FabricExecutor) querier.Querier[T]
NewQuerier builds a type-safe querier over the executor's connection. It mirrors mssql.NewQuerier but is provided here so the Fabric scrapper depends only on the fabric package.
Types ¶
type APIClient ¶ added in v0.21.0
type APIClient struct {
// contains filtered or unexported fields
}
APIClient calls the Fabric REST API with the connection's own identity.
func NewAPIClient ¶ added in v0.21.0
func NewAPIClient(conf *FabricConf) (*APIClient, error)
NewAPIClient builds a Fabric REST API client from the same identity the SQL connection uses: the service principal, or the ambient Azure identity of an on-prem agent. It returns ErrNoAPICredential when the configuration holds only a pre-acquired SQL token.
func NewAPIClientWith ¶ added in v0.21.0
func NewAPIClientWith(cred azcore.TokenCredential, baseURL string, httpClient *http.Client) *APIClient
NewAPIClientWith builds a client against baseURL with an explicit credential and HTTP client (nil for a default one); tests point it at a fake server.
func (*APIClient) ListWorkspaceRoleAssignments ¶ added in v0.21.0
func (c *APIClient) ListWorkspaceRoleAssignments(ctx context.Context, workspaceID string) ([]*WorkspaceRoleAssignment, error)
ListWorkspaceRoleAssignments lists who holds a role in the workspace. The caller needs the Member or Admin role in it; anything less is refused with 403 InsufficientWorkspaceRole.
type APIError ¶ added in v0.21.0
type APIError struct {
StatusCode int
// ErrorCode is the API's own code, e.g. InsufficientWorkspaceRole.
ErrorCode string
Message string
}
APIError is a refusal or failure answered by the Fabric REST API.
func (*APIError) IsPermissionError ¶ added in v0.21.0
IsPermissionError reports whether the API refused the identity: a missing workspace role (InsufficientWorkspaceRole) or a missing tenant setting both answer 403, an identity the API does not accept answers 401.
type FabricConf ¶
type FabricConf struct {
// Host is the workspace SQL analytics endpoint, e.g.
// "<workspace-id>.datawarehouse.fabric.microsoft.com".
Host string
// Database is the default execution database — the context in which
// *unqualified* ad-hoc/monitor SQL resolves (e.g. `FROM sales.products`).
// Optional: defaults to "master" (the always-present workspace entry point),
// which is sufficient because metadata scrapping and generated metrics SQL
// are fully database-qualified via cross-database three-part names. Set it
// only when unqualified queries should resolve against a specific database.
//
// Which databases to *scrape* is a separate, scrapper-level concern — see
// FabricScrapperConf.Databases — so it is deliberately not on this
// connection config (mirroring TrinoScrapperConf.Catalogs /
// BigQueryScrapperConf.Datasets).
Database string
// AuthType selects the authentication method. It accepts any of the
// spellings in authTypeAliases — dbt-fabric ("ServicePrincipal", "CLI",
// "auto"), Microsoft's ODBC "Authentication=" keyword
// ("ActiveDirectoryServicePrincipal", ...), the Azure SDK names, or our own
// AuthType* constants — collapsed to a canonical value via CanonicalAuthType.
// Empty defaults to a service principal (ClientID + ClientSecret), unless
// AccessToken is set (a non-empty AccessToken always wins). The ambient modes
// (AuthTypeAzureCLI/Default/ManagedIdentity) authenticate as the host's own
// Azure identity with no stored credential and are intended for on-prem
// agents. They are opt-in — engaged only when AuthType names one — so a
// hosted caller that leaves AuthType empty with no credentials fails closed
// rather than silently inheriting the host process identity.
AuthType string
// ClientID is the Entra application (client) ID of the service principal
// (default auth), or the user-assigned identity client ID for
// AuthTypeManagedIdentity.
ClientID string
// ClientSecret is the service principal's client secret.
ClientSecret string
// TenantID is the Entra tenant (directory) ID. Optional: when empty the
// tenant is inferred from the Fabric endpoint. Provide it for tenants where
// the server-supplied authority is not the SP's home tenant.
TenantID string
// AccessToken is a pre-acquired Entra OAuth access token for the SQL scope
// (https://database.windows.net/.default). When set it takes precedence over
// all other authentication methods — used by hosts that acquire the token
// out of band (managed identity, workload identity federation, certificate).
AccessToken string
}
FabricConf configures a connection to a Microsoft Fabric Warehouse or Lakehouse SQL analytics endpoint.
Authentication is via a Microsoft Entra ID service principal by default (ClientID + ClientSecret). For hosted deployments that mint their own token (managed identity / workload-identity federation), set AccessToken instead and leave the client credentials empty. On-prem agents running on a user's own machine can instead set AuthType to an ambient mode (see below) to reuse the host's Azure identity (az login / managed identity) with no stored secret.
func (*FabricConf) ToMSSQLConf ¶
func (c *FabricConf) ToMSSQLConf() *dwhexecmssql.MSSQLConf
ToMSSQLConf translates the simplified Fabric configuration into the MSSQL executor configuration, fixing the settings Fabric always requires: TLS encryption on and the standard TDS port. The authentication method is derived from AuthType (with a pre-acquired AccessToken always taking precedence).
type FabricExecutor ¶
type FabricExecutor struct {
*dwhexecmssql.MSSQLExecutor
// contains filtered or unexported fields
}
FabricExecutor is a Fabric-flavoured MSSQL executor. It embeds the MSSQL executor so all query execution (SQL comment enrichment, query stats, row scanning) is shared, and exists as its own type so Fabric has a distinct surface from raw MSSQL.
func NewFabricExecutor ¶
func NewFabricExecutor(ctx context.Context, conf *FabricConf) (*FabricExecutor, error)
func (*FabricExecutor) Conf ¶
func (e *FabricExecutor) Conf() *FabricConf
Conf returns the Fabric configuration this executor was built from.
type HostIdentity ¶
type HostIdentity struct {
// TenantID is the Entra tenant GUID.
TenantID string
// WorkspaceID is the Fabric workspace GUID — the Fabric REST API key for
// /v1/workspaces/{id}/ items (warehouses, pipelines, notebooks, jobs …).
WorkspaceID string
}
HostIdentity is the tenant and workspace identity encoded in a Fabric SQL analytics endpoint hostname.
func ParseHostIdentity ¶
func ParseHostIdentity(host string) (*HostIdentity, error)
ParseHostIdentity decodes the tenant and workspace GUIDs from a Fabric SQL analytics endpoint hostname of the form
<base32(tenant)>-<base32(workspace)>.datawarehouse.fabric.microsoft.com
Each label is the Base32 (RFC 4648, lower-cased, unpadded) encoding of the 16 GUID bytes in .NET little-endian layout. This lets callers derive the workspace id — the join key to Fabric REST API resources — from the connection host alone, with no live connection. It is why the scrapper uses the host as the row Instance: the host is present in every connection profile (including third-party ones such as dbt's `server`/`host`) and still carries the workspace id for API linking. Returns an error if the host is not a recognisable Fabric endpoint.
type WorkspacePrincipal ¶ added in v0.21.0
type WorkspacePrincipal struct {
// ID is the Entra object id of the principal.
ID string `json:"id"`
DisplayName string `json:"displayName"`
// Type is User, Group, ServicePrincipal or ServicePrincipalProfile.
Type string `json:"type"`
UserDetails *struct {
UserPrincipalName string `json:"userPrincipalName"`
} `json:"userDetails,omitempty"`
ServicePrincipalDetails *struct {
AadAppID string `json:"aadAppId"`
} `json:"servicePrincipalDetails,omitempty"`
GroupDetails *struct {
GroupType string `json:"groupType"`
} `json:"groupDetails,omitempty"`
}
WorkspacePrincipal is the principal of a workspace role assignment.
type WorkspaceRoleAssignment ¶ added in v0.21.0
type WorkspaceRoleAssignment struct {
ID string `json:"id"`
Principal WorkspacePrincipal `json:"principal"`
Role string `json:"role"`
}
WorkspaceRoleAssignment grants a principal a workspace role: Admin, Member, Contributor or Viewer.