Documentation
¶
Overview ¶
Package profiles contains utility to resolve Databricks configuration profiles.
A profile is a named collection of configuration values. It is typically stored in a file called ~/.databrickscfg. Profiles can be resolved from the file and/or environment variables using the Resolve function.
Examples:
// Use defaults: default profile + env overlay.
p, err := profiles.Resolve()
// Specific profile, no env overlay.
p, err := profiles.Resolve(
profiles.WithFile("/path/to/databrickscfg"),
profiles.WithProfile("staging"),
)
// Specific profile with env overlay.
p, err := profiles.Resolve(
profiles.WithProfile("staging"),
profiles.WithEnv(),
)
// Only env vars, no config file.
p, err := profiles.Resolve(profiles.WithEnv())
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrConfigFileNotFound is returned when an explicitly requested config file // (via [WithFile] or DATABRICKS_CONFIG_FILE) does not exist. ErrConfigFileNotFound = errors.New("config file not found") // ErrProfileNotFound is returned when the requested profile (INI section) does // not exist in the config file. ErrProfileNotFound = errors.New("profile not found") // ErrEmptyPath is returned when an empty path is passed. ErrEmptyPath = errors.New("empty path") // ErrEmptyProfile is returned when an empty profile name is passed. ErrEmptyProfile = errors.New("empty profile") // ErrInvalidProfileName is returned when a profile name is reserved or // otherwise not usable. ErrInvalidProfileName = errors.New("invalid profile name") )
Functions ¶
func DefaultConfigFile ¶
func DefaultConfigFile() string
DefaultConfigFile returns the path to the default databrickscfg file. It reads DATABRICKS_CONFIG_FILE from the environment, falling back to ~/.databrickscfg. If the home directory cannot be determined, it returns an empty string.
func ListProfiles ¶
ListProfiles returns the names of all profiles (INI sections) in the given config file. The path must be non-empty; use DefaultConfigFile to obtain the conventional default path. The DEFAULT section is included if it has any keys.
Types ¶
type Profile ¶
type Profile struct {
// Name is the profile name (INI section name). Set automatically by
// [Resolve]; must be set manually when constructing a Profile for use
// with [SaveToFile].
Name string
// Host is the Databricks workspace or Accounts API endpoint URL.
Host string
// WorkspaceID is the Databricks Workspace ID, used with unified hosts.
WorkspaceID string
// AccountID is the Databricks Account ID for Accounts API.
AccountID string
// Token is the personal access token for PAT authentication.
Token Secret
// Username is the username for basic authentication.
Username string
// Password is the password for basic authentication.
Password Secret
// AuthType selects a specific auth method when multiple credentials are
// available in the environment.
AuthType string
// ClientID is the OAuth client ID for M2M authentication.
ClientID string
// ClientSecret is the OAuth client secret for M2M authentication.
ClientSecret Secret
// DatabricksCLIPath is the path to the Databricks CLI binary
// (version >= 0.100.0) used for CLI-based authentication.
DatabricksCLIPath string
// MetadataServiceURL is the URL of a metadata service that provides
// authentication credentials (e.g. Databricks VSCode extension).
MetadataServiceURL Secret
// ActionsIDTokenRequestURL is the GitHub Actions URL for requesting an
// OIDC token. Set automatically by GitHub Actions runners.
ActionsIDTokenRequestURL string
// ActionsIDTokenRequestToken is the bearer token used to authenticate
// with the GitHub Actions OIDC provider.
ActionsIDTokenRequestToken Secret
// OIDCTokenEnv is the name of an environment variable containing an
// OIDC ID token.
OIDCTokenEnv string
// OIDCTokenFilePath is the path to a file containing an OIDC ID token.
OIDCTokenFilePath string
// TokenAudience is the audience to specify when fetching an ID token
// for Workload Identity Federation.
TokenAudience string
// DiscoveryURL is an OpenID Connect discovery URL. When set, OIDC
// endpoints are fetched from this URL instead of the default
// host-based well-known endpoint.
DiscoveryURL string
// AzureClientID is the Azure AD application (client) ID for Azure
// client-secret or MSI authentication.
AzureClientID string
// AzureClientSecret is the Azure AD client secret for Azure
// client-secret authentication.
AzureClientSecret Secret
// AzureTenantID is the Azure AD tenant ID.
AzureTenantID string
// AzureResourceID is the Azure Resource Manager ID for an Azure
// Databricks workspace, exchanged for a host URL.
AzureResourceID string
// AzureEnvironment selects the Azure cloud environment (PUBLIC,
// USGOVERNMENT, CHINA). When empty, determined from the workspace host.
AzureEnvironment string
// AzureLoginAppID is the Azure Login Application ID. Deprecated: this
// field no longer has any effect and will be removed in the future.
AzureLoginAppID string
// AzureUseMSI enables Azure Managed Service Identity authentication.
AzureUseMSI *bool
// GoogleCredentials holds GCP service account credentials JSON for
// Google credentials-based authentication.
GoogleCredentials Secret
// GoogleServiceAccount is the GCP service account email for
// Google ID-based authentication.
GoogleServiceAccount string
// ClusterID is the default Databricks cluster ID for compute operations.
ClusterID string
// WarehouseID is the default Databricks SQL warehouse ID.
WarehouseID string
// ServerlessComputeID is the default serverless compute resource ID.
ServerlessComputeID string
// Extra holds INI keys that are not mapped to a known field. This is
// only populated by [WithFile]; environment variables do not contribute
// to Extra.
Extra map[string]string
}
Profile holds configuration values resolved from a databrickscfg file and/or environment variables. The zero value is meaningful: all empty strings means nothing was configured.
TODO: Consider filtering properties that are not relevant in SDK-Mod.
func Resolve ¶
func Resolve(opts ...ResolveOption) (*Profile, error)
Resolve creates a Profile from a databrickscfg file and/or environment variables.
If no options are provided, the defaults are used:
Resolve() // equivalent to Resolve(WithDefaultProfile(), WithEnv())
func (*Profile) SaveToFile ¶
SaveToFile writes the profile to the [Profile.Name] section of a databrickscfg file. Path must be non-empty; use DefaultConfigFile to obtain the conventional default path. [Profile.Name] must be non-empty. If the file exists, other sections are preserved; the named section is replaced entirely. If the file does not exist, it is created with mode 0600.
Both known fields and [Profile.Extra] entries are written, so a Resolve/SaveToFile round-trip never loses unknown keys. Fields set to the empty string are omitted from the output.
Warning: this method will save properties that might have been loaded from environment variables.
type ResolveOption ¶
type ResolveOption func(o *options) error
ResolveOption configures the behavior of Resolve.
func WithDefaultProfile ¶
func WithDefaultProfile() ResolveOption
WithDefaultProfile loads the default profile from the config file. The profile name is resolved in order from: DATABRICKS_CONFIG_PROFILE environment variable, the default_profile key in the [__settings__] section of the config file, and finally the DEFAULT section.
Note: DATABRICKS_CONFIG_PROFILE controls which profile NAME to load. This is independent of WithEnv, which controls whether profile values from environment variables are overlaid on top of the profile.
func WithEnv ¶
func WithEnv() ResolveOption
WithEnv enables overlaying environment variables (e.g. DATABRICKS_HOST) on top of config file values. When enabled, environment variables take precedence over file values.
This does not affect DATABRICKS_CONFIG_FILE or DATABRICKS_CONFIG_PROFILE, which control file and profile selection. Use WithFile and WithProfile to override those.
func WithFile ¶
func WithFile(path string) ResolveOption
WithFile overrides the path to the databrickscfg file. If not set, Resolve reads DATABRICKS_CONFIG_FILE from the environment, falling back to ~/.databrickscfg. An empty string returns ErrEmptyPath.
func WithProfile ¶
func WithProfile(profile string) ResolveOption
WithProfile loads a specific named profile (INI section) from the config file. If the profile does not exist, Resolve returns ErrProfileNotFound. An empty string returns ErrEmptyProfile.
type Secret ¶
type Secret string
Secret is a string that is obfuscated in all string representations.