From 6bcb33bf0752ac48d50b4ce3b736aaae1e1e3f84 Mon Sep 17 00:00:00 2001 From: shreyas-goenka <88374338+shreyas-goenka@users.noreply.github.com> Date: Wed, 21 Sep 2022 13:55:37 +0200 Subject: [PATCH] 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 --- project/config.go | 11 ++++++++++- project/project.go | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/project/config.go b/project/config.go index 344a2221..4b28f7f7 100644 --- a/project/config.go +++ b/project/config.go @@ -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 } diff --git a/project/project.go b/project/project.go index cdf2ade6..3a9dd24b 100644 --- a/project/project.go +++ b/project/project.go @@ -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 }