Skip to content

Commit 6bcb33b

Browse files
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
1 parent 731679c commit 6bcb33b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

project/config.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,16 @@ func IsDatabricksProject() bool {
7777
}
7878

7979
func loadProjectConf(root string) (c Config, err error) {
80-
config, err := os.Open(filepath.Join(root, ConfigFile))
80+
configFilePath := filepath.Join(root, ConfigFile)
81+
82+
if _, err := os.Stat(configFilePath); errors.Is(err, os.ErrNotExist) {
83+
baseDir := filepath.Base(root)
84+
// If bricks config file is missing we assume the project root dir name
85+
// as the name of the project
86+
return Config{Name: baseDir}, nil
87+
}
88+
89+
config, err := os.Open(configFilePath)
8190
if err != nil {
8291
return
8392
}

project/project.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,16 @@ func Initialize(ctx context.Context, root string) (context.Context, error) {
5858
config: &config,
5959
}
6060

61-
p.wsc = workspaces.New(&databricks.Config{Profile: config.Profile})
61+
if config.Profile == "" {
62+
// Bricks config doesn't define the profile to use, so go sdk will figure
63+
// out the auth credentials based on the enviroment.
64+
// eg. DATABRICKS_CONFIG_PROFILE can be used to select which profile to use or
65+
// DATABRICKS_HOST and DATABRICKS_TOKEN can be used to set the workspace auth creds
66+
p.wsc = workspaces.New()
67+
} else {
68+
p.wsc = workspaces.New(&databricks.Config{Profile: config.Profile})
69+
}
70+
6271
return context.WithValue(ctx, &projectKey, &p), nil
6372
}
6473

0 commit comments

Comments
 (0)