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 IsNotFound(err error) bool
- func IsPermissionError(err error) bool
- func IsUnavailableError(err error) bool
- func NewQuerier[T any](conn *FabricExecutor) querier.Querier[T]
- type APIClient
- func (c *APIClient) GetMirroringDefinition(ctx context.Context, workspaceID, itemID string) (*MirroringDefinition, error)
- func (c *APIClient) ListItemConnections(ctx context.Context, workspaceID, itemID string) ([]*ItemConnection, error)
- func (c *APIClient) ListShortcuts(ctx context.Context, workspaceID, itemID string) ([]*Shortcut, error)
- func (c *APIClient) ListStorageItems(ctx context.Context, workspaceID string) ([]*StorageItem, error)
- func (c *APIClient) ListWorkspaceRoleAssignments(ctx context.Context, workspaceID string) ([]*WorkspaceRoleAssignment, error)
- type APIError
- type FabricConf
- type FabricExecutor
- type HostIdentity
- type ItemConnection
- type MirroredTable
- type MirroringDefinition
- type OneLakeTarget
- type Shortcut
- type StorageItem
- type WorkspacePrincipal
- type WorkspaceRoleAssignment
Constants ¶
const ( ItemTypeLakehouse = "Lakehouse" ItemTypeWarehouse = "Warehouse" ItemTypeMirroredDatabase = "MirroredDatabase" ItemTypeSQLDatabase = "SQLDatabase" )
The Fabric item types that the SQL analytics endpoint shows as a database.
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 ErrDefinitionWithoutMirroring = errors.New("the definition of the mirrored database has no mirroring.json part")
ErrDefinitionWithoutMirroring is the error of a mirrored database definition with no mirroring.json part.
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 IsNotFound ¶ added in v0.28.0
IsNotFound is true for an answer that the API does not find the workspace or the item: a 404, or a 400 for a workspace id that it does not know.
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) GetMirroringDefinition ¶ added in v0.28.0
func (c *APIClient) GetMirroringDefinition(ctx context.Context, workspaceID, itemID string) (*MirroringDefinition, error)
GetMirroringDefinition reads the definition of a mirrored database. It needs the Contributor role in the workspace, and Fabric refuses it for a Viewer with 403. Fabric answers with a long running operation, which the call waits for.
func (*APIClient) ListItemConnections ¶ added in v0.28.0
func (c *APIClient) ListItemConnections(ctx context.Context, workspaceID, itemID string) ([]*ItemConnection, error)
ListItemConnections lists the Fabric connections that an item uses.
func (*APIClient) ListShortcuts ¶ added in v0.28.0
func (c *APIClient) ListShortcuts(ctx context.Context, workspaceID, itemID string) ([]*Shortcut, error)
ListShortcuts lists the OneLake shortcuts of an item. Fabric gives the path of a shortcut with a leading slash in the listing and without it in a single read, so the paths here have neither.
func (*APIClient) ListStorageItems ¶ added in v0.28.0
func (c *APIClient) ListStorageItems(ctx context.Context, workspaceID string) ([]*StorageItem, error)
ListStorageItems lists the Lakehouses, Warehouses, mirrored databases and SQL databases of a workspace. It needs the Viewer role in the workspace. It returns an error if any page fails, never a part of the listing.
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 NewFabricExecutorFromDb ¶ added in v0.22.1
func NewFabricExecutorFromDb(conf *FabricConf, db *sqlx.DB) *FabricExecutor
NewFabricExecutorFromDb wraps a connection the caller already opened, such as one over a fake driver in a test. It does not ping it.
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 ItemConnection ¶ added in v0.28.0
type ItemConnection struct {
ID string
DisplayName string
// Type is `connectionDetails.type`, such as "Snowflake".
Type string
// Path is `connectionDetails.path`. For Snowflake it is
// "<account>.snowflakecomputing.com;<warehouse>".
Path string
}
ItemConnection is a Fabric connection that an item uses.
type MirroredTable ¶ added in v0.28.0
MirroredTable is one source table of a mirrored database.
type MirroringDefinition ¶ added in v0.28.0
type MirroringDefinition struct {
// SourceType is `properties.source.type`, such as "Snowflake",
// "AzureSqlDatabase" or "GenericMirror" (open mirroring).
SourceType string
// ConnectionID is the GUID of the Fabric connection to the source
// (`properties.source.typeProperties.connection`). Empty for open mirroring.
ConnectionID string
// Database is the source database (`properties.source.typeProperties.database`).
Database string
// Tables are the source tables of `properties.mountedTables`. It is empty if
// the mirrored database mirrors every table of the source, as the definition
// then names none.
Tables []MirroredTable
}
MirroringDefinition is what the mirroring.json part of the definition of a mirrored database says about its source.
func ParseMirroringDefinition ¶ added in v0.28.0
func ParseMirroringDefinition(payload []byte) (*MirroringDefinition, error)
ParseMirroringDefinition reads the mirroring.json part of a mirrored database definition. A mounted table with no schema or no table name is left out.
type OneLakeTarget ¶ added in v0.28.0
type OneLakeTarget struct {
WorkspaceID string
ItemID string
// Path is the folder in the target item, with no leading or trailing slash,
// such as "Tables/sales/orders".
Path string
}
OneLakeTarget is the item and the folder that a OneLake shortcut points to.
type Shortcut ¶ added in v0.28.0
type Shortcut struct {
// Name is the name of the shortcut, the last segment of its OneLake path.
Name string
// Path is the folder that holds the shortcut, with no leading or trailing
// slash: "Tables", "Tables/<schema>" or a folder below "Files".
Path string
// TargetType is the kind of target, such as "OneLake", "AdlsGen2" or
// "AmazonS3".
TargetType string
// OneLake is the target of a shortcut to OneLake. Nil for the other targets.
OneLake *OneLakeTarget
}
Shortcut is a OneLake shortcut of a Lakehouse.
type StorageItem ¶ added in v0.28.0
type StorageItem struct {
ID string
WorkspaceID string
// Type is one of the ItemType constants.
Type string
DisplayName string
Description string
// SQLEndpointHost is the host of the SQL analytics endpoint of the item. It is
// empty for a SQL database, whose listing does not give it.
SQLEndpointHost string
// SQLEndpointID is the GUID of the SQL analytics endpoint of a Lakehouse or a
// mirrored database. A Warehouse is its own endpoint, so it is empty there.
SQLEndpointID string
// SQLEndpointStatus is the provisioning status of the SQL analytics endpoint of
// a Lakehouse or a mirrored database, such as "Success", "InProgress" or
// "Failed". It is empty for the other types.
SQLEndpointStatus string
// DefaultSchema is the default schema of a Lakehouse with schemas. It is empty
// for a Lakehouse with no schemas, which keeps every table in dbo.
DefaultSchema string
}
StorageItem is a Fabric item that the SQL analytics endpoint shows as a database: a Lakehouse, a Warehouse, a mirrored database or a SQL database. Its display name is the name of that database.
func (*StorageItem) HasSchemas ¶ added in v0.28.0
func (i *StorageItem) HasSchemas() bool
HasSchemas is true if the tables of the item are below a schema in OneLake (Tables/<schema>/<table>): a Warehouse, a mirrored database, and a Lakehouse with schemas. A Lakehouse with no schemas keeps its tables at Tables/<table>.
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.