-
Notifications
You must be signed in to change notification settings - Fork 112
Added env.UserHomeDir(ctx) for parallel-friendly tests
#955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [DEFAULT] | ||
| host = https://default | ||
| token = default | ||
|
|
||
| [acc] | ||
| host = https://accounts.cloud.databricks.com | ||
| account_id = abc | ||
pietern marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package env | |
| import ( | ||
| "context" | ||
| "os" | ||
| "runtime" | ||
| "strings" | ||
| ) | ||
|
|
||
|
|
@@ -63,6 +64,21 @@ func Set(ctx context.Context, key, value string) context.Context { | |
| return setMap(ctx, m) | ||
| } | ||
|
|
||
| func homeEnvVar() string { | ||
| if runtime.GOOS == "windows" { | ||
| return "USERPROFILE" | ||
| } | ||
| return "HOME" | ||
| } | ||
|
|
||
| func WithUserHomeDir(ctx context.Context, value string) context.Context { | ||
| return Set(ctx, homeEnvVar(), value) | ||
| } | ||
|
|
||
| func UserHomeDir(ctx context.Context) string { | ||
| return Get(ctx, homeEnvVar()) | ||
|
||
| } | ||
|
|
||
| // All returns environment variables that are defined in both os.Environ | ||
| // and this package. `env.Set(ctx, x, y)` will override x from os.Environ. | ||
| func All(ctx context.Context) map[string]string { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package env | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/databricks/databricks-sdk-go/config" | ||
| ) | ||
|
|
||
| // NewConfigLoader creates Databricks SDK Config loader that is aware of env.Set variables: | ||
| // | ||
| // ctx = env.Set(ctx, "DATABRICKS_WAREHOUSE_ID", "...") | ||
| // | ||
| // Usage: | ||
| // | ||
| // &config.Config{ | ||
| // Loaders: []config.Loader{ | ||
| // env.NewConfigLoader(ctx), | ||
| // config.ConfigAttributes, | ||
| // config.ConfigFile, | ||
| // }, | ||
| // } | ||
| func NewConfigLoader(ctx context.Context) *configLoader { | ||
| return &configLoader{ | ||
| ctx: ctx, | ||
| } | ||
| } | ||
|
|
||
| type configLoader struct { | ||
| ctx context.Context | ||
| } | ||
|
|
||
| func (le *configLoader) Name() string { | ||
| return "cli-env" | ||
| } | ||
|
|
||
| func (le *configLoader) Configure(cfg *config.Config) error { | ||
| for _, a := range config.ConfigAttributes { | ||
| if !a.IsZero(cfg) { | ||
| continue | ||
| } | ||
| for _, k := range a.EnvVars { | ||
| v := Get(le.ctx, k) | ||
| if v == "" { | ||
| continue | ||
| } | ||
| a.Set(cfg, v) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
nfx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.