fabric

package
v0.28.0-rc3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 20 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	ItemTypeLakehouse        = "Lakehouse"
	ItemTypeWarehouse        = "Warehouse"
	ItemTypeMirroredDatabase = "MirroredDatabase"
	ItemTypeSQLDatabase      = "SQLDatabase"
)

The Fabric item types that the SQL analytics endpoint shows as a database.

View Source
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).

View Source
const FabricAPIBaseURL = "https://api.fabric.microsoft.com/v1"

FabricAPIBaseURL is the Fabric REST API root.

View Source
const OneLakeBaseURL = "https://onelake.dfs.fabric.microsoft.com"

OneLakeBaseURL is the OneLake endpoint of the ADLS Gen2 (DFS) API. Each Fabric workspace is a file system of it, and each item a directory named by the item GUID.

Variables

View Source
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.

View Source
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

func CanonicalAuthType(s string) string

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

func IsNotFound(err error) bool

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 IsOneLakeNotFound added in v0.28.0

func IsOneLakeNotFound(err error) bool

IsOneLakeNotFound reports whether err is a OneLake answer that the path does not exist.

func IsPermissionError

func IsPermissionError(err error) bool

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, and so is a OneLake refusal (OneLakeError 401/403).

func IsUnavailableError added in v0.21.0

func IsUnavailableError(err error) bool

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) Error added in v0.21.0

func (e *APIError) Error() string

func (*APIError) IsPermissionError added in v0.21.0

func (e *APIError) IsPermissionError() bool

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 ListOptions added in v0.28.0

type ListOptions struct {
	// BeginFrom starts the listing at the first child whose name sorts at or
	// after it. The children are in the byte order of their names.
	BeginFrom string
}

ListOptions narrows a directory listing.

type MirroredTable added in v0.28.0

type MirroredTable struct {
	Schema string
	Table  string
}

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 OneLakeClient added in v0.28.0

type OneLakeClient struct {
	// contains filtered or unexported fields
}

OneLakeClient reads files of a workspace from OneLake with the connection's own identity. OneLake is the storage API, so its calls do not count against the quota of the Fabric REST API.

func NewOneLakeClient added in v0.28.0

func NewOneLakeClient(conf *FabricConf) (*OneLakeClient, error)

NewOneLakeClient builds a OneLake client from the same identity the SQL connection uses. It returns ErrNoAPICredential when the configuration holds only a pre-acquired SQL token.

func NewOneLakeClientWith added in v0.28.0

func NewOneLakeClientWith(cred azcore.TokenCredential, baseURL string, httpClient *http.Client) *OneLakeClient

NewOneLakeClientWith 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 (*OneLakeClient) ListDirectory added in v0.28.0

func (c *OneLakeClient) ListDirectory(ctx context.Context, workspaceID, itemID, directory string, opts ListOptions) ([]*OneLakePath, error)

ListDirectory lists the direct children of directory, a path inside the item (for example "Tables/sales/orders/_delta_log"), in the order of their names. It follows the continuation of a listing that spans several pages.

func (*OneLakeClient) ReadFile added in v0.28.0

func (c *OneLakeClient) ReadFile(ctx context.Context, workspaceID, itemID, path string) ([]byte, error)

ReadFile reads the whole file at path, a path inside the item.

type OneLakeError added in v0.28.0

type OneLakeError struct {
	StatusCode int
	// Code is the storage error code, e.g. PathNotFound or AuthorizationPermissionMismatch.
	Code    string
	Message string
}

OneLakeError is a refusal or failure answered by OneLake.

func (*OneLakeError) Error added in v0.28.0

func (e *OneLakeError) Error() string

func (*OneLakeError) IsNotFound added in v0.28.0

func (e *OneLakeError) IsNotFound() bool

IsNotFound reports whether the path, the item or the workspace does not exist.

func (*OneLakeError) IsPermissionError added in v0.28.0

func (e *OneLakeError) IsPermissionError() bool

IsPermissionError reports whether OneLake refused the identity: 403 for an identity without access to the item, 401 for one it does not accept.

type OneLakePath added in v0.28.0

type OneLakePath struct {
	// Name is the last segment of the path.
	Name        string
	IsDirectory bool
	// LastModified is the time the file was last written, to the second.
	LastModified  time.Time
	ContentLength int64
}

OneLakePath is one entry of a directory listing.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL