2022-11-18 09:57:31 +00:00
|
|
|
package config
|
|
|
|
|
2022-11-23 14:20:03 +00:00
|
|
|
import (
|
2023-03-08 15:14:24 +00:00
|
|
|
"os"
|
|
|
|
|
2022-11-24 20:41:57 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go"
|
2022-12-01 10:17:29 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go/service/scim"
|
2022-11-23 14:20:03 +00:00
|
|
|
)
|
|
|
|
|
2022-11-30 13:15:22 +00:00
|
|
|
type PathLike struct {
|
|
|
|
// Workspace contains a WSFS path.
|
2022-12-01 10:17:29 +00:00
|
|
|
Workspace string `json:"workspace,omitempty"`
|
2022-11-30 13:15:22 +00:00
|
|
|
|
|
|
|
// DBFS contains a DBFS path.
|
2022-12-01 10:17:29 +00:00
|
|
|
DBFS string `json:"dbfs,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsSet returns whether either path is non-nil.
|
|
|
|
func (p PathLike) IsSet() bool {
|
|
|
|
return p.Workspace != "" || p.DBFS != ""
|
2022-11-30 13:15:22 +00:00
|
|
|
}
|
|
|
|
|
2022-11-18 09:57:31 +00:00
|
|
|
// Workspace defines configurables at the workspace level.
|
|
|
|
type Workspace struct {
|
2022-11-23 14:20:03 +00:00
|
|
|
// Unified authentication attributes.
|
|
|
|
//
|
|
|
|
// We omit sensitive attributes as they should never be hardcoded.
|
|
|
|
// They must be specified through environment variables instead.
|
|
|
|
//
|
|
|
|
// For example: token, password, Google credentials, Azure client secret, etc.
|
|
|
|
//
|
|
|
|
|
|
|
|
// Generic attributes.
|
2022-11-18 09:57:31 +00:00
|
|
|
Host string `json:"host,omitempty"`
|
|
|
|
Profile string `json:"profile,omitempty"`
|
2022-11-23 14:20:03 +00:00
|
|
|
|
|
|
|
// Google specific attributes.
|
|
|
|
GoogleServiceAccount string `json:"google_service_account,omitempty"`
|
|
|
|
|
|
|
|
// Azure specific attributes.
|
|
|
|
AzureResourceID string `json:"azure_workspace_resource_id,omitempty"`
|
|
|
|
AzureUseMSI bool `json:"azure_use_msi,omitempty"`
|
|
|
|
AzureClientID string `json:"azure_client_id,omitempty"`
|
|
|
|
AzureTenantID string `json:"azure_tenant_id,omitempty"`
|
|
|
|
AzureEnvironment string `json:"azure_environment,omitempty"`
|
|
|
|
AzureLoginAppID string `json:"azure_login_app_id,omitempty"`
|
2022-11-30 13:15:22 +00:00
|
|
|
|
2022-12-01 10:17:29 +00:00
|
|
|
// CurrentUser holds the current user.
|
|
|
|
// This is set after configuration initialization.
|
|
|
|
CurrentUser *scim.User `json:"current_user,omitempty"`
|
|
|
|
|
2023-01-26 18:55:38 +00:00
|
|
|
// Remote base path for deployment state, for artifacts, as synchronization target.
|
|
|
|
// This defaults to "~/.bundle/${bundle.name}/${bundle.environment}" where "~" expands to
|
|
|
|
// the current user's home directory in the workspace (e.g. `/Users/jane@doe.com`).
|
2023-02-17 01:49:39 +00:00
|
|
|
Root string `json:"root,omitempty"`
|
2023-01-26 18:55:38 +00:00
|
|
|
|
|
|
|
// Remote path to synchronize local files to.
|
|
|
|
// This defaults to "${workspace.root}/files".
|
2023-02-17 01:49:39 +00:00
|
|
|
FilePath PathLike `json:"file_path,omitempty"`
|
2023-01-26 18:55:38 +00:00
|
|
|
|
|
|
|
// Remote path for build artifacts.
|
|
|
|
// This defaults to "${workspace.root}/artifacts".
|
2023-02-17 01:49:39 +00:00
|
|
|
ArtifactPath PathLike `json:"artifact_path,omitempty"`
|
2023-01-26 18:55:38 +00:00
|
|
|
|
|
|
|
// Remote path for deployment state.
|
|
|
|
// This defaults to "${workspace.root}/state".
|
2023-02-17 01:49:39 +00:00
|
|
|
StatePath PathLike `json:"state_path,omitempty"`
|
2022-11-23 14:20:03 +00:00
|
|
|
}
|
|
|
|
|
2022-11-24 20:41:57 +00:00
|
|
|
func (w *Workspace) Client() (*databricks.WorkspaceClient, error) {
|
2022-11-23 14:20:03 +00:00
|
|
|
config := databricks.Config{
|
|
|
|
// Generic
|
|
|
|
Host: w.Host,
|
|
|
|
Profile: w.Profile,
|
|
|
|
|
|
|
|
// Google
|
|
|
|
GoogleServiceAccount: w.GoogleServiceAccount,
|
|
|
|
|
|
|
|
// Azure
|
|
|
|
AzureResourceID: w.AzureResourceID,
|
|
|
|
AzureUseMSI: w.AzureUseMSI,
|
|
|
|
AzureClientID: w.AzureClientID,
|
|
|
|
AzureTenantID: w.AzureTenantID,
|
|
|
|
AzureEnvironment: w.AzureEnvironment,
|
|
|
|
AzureLoginAppID: w.AzureLoginAppID,
|
|
|
|
}
|
|
|
|
|
2022-11-24 20:41:57 +00:00
|
|
|
return databricks.NewWorkspaceClient(&config)
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|
2023-03-08 15:14:24 +00:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
os.Setenv("BRICKS_CLI_PATH", os.Args[0])
|
|
|
|
}
|