Use env vars to read profile if databricks.yml is absent (#70)

Tested manually and by running sync_test.go integration test bricks sync
works
This commit is contained in:
shreyas-goenka 2022-09-21 13:55:37 +02:00 committed by GitHub
parent 731679cb4b
commit 6bcb33bf07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -77,7 +77,16 @@ func IsDatabricksProject() bool {
}
func loadProjectConf(root string) (c Config, err error) {
config, err := os.Open(filepath.Join(root, ConfigFile))
configFilePath := filepath.Join(root, ConfigFile)
if _, err := os.Stat(configFilePath); errors.Is(err, os.ErrNotExist) {
baseDir := filepath.Base(root)
// If bricks config file is missing we assume the project root dir name
// as the name of the project
return Config{Name: baseDir}, nil
}
config, err := os.Open(configFilePath)
if err != nil {
return
}

View File

@ -58,7 +58,16 @@ func Initialize(ctx context.Context, root string) (context.Context, error) {
config: &config,
}
p.wsc = workspaces.New(&databricks.Config{Profile: config.Profile})
if config.Profile == "" {
// Bricks config doesn't define the profile to use, so go sdk will figure
// out the auth credentials based on the enviroment.
// eg. DATABRICKS_CONFIG_PROFILE can be used to select which profile to use or
// DATABRICKS_HOST and DATABRICKS_TOKEN can be used to set the workspace auth creds
p.wsc = workspaces.New()
} else {
p.wsc = workspaces.New(&databricks.Config{Profile: config.Profile})
}
return context.WithValue(ctx, &projectKey, &p), nil
}