-
Notifications
You must be signed in to change notification settings - Fork 186
Detect mismatch between host defined in config and env variable #2549
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 5 commits
eec36ef
32e4600
7296a7f
d74786d
80c6d9f
8678ebf
c7ddaab
3bd5782
01192f7
d404bc6
d2eab7d
3e1dfce
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 |
|---|---|---|
|
|
@@ -149,3 +149,34 @@ func TestWorkspaceVerifyProfileForHost(t *testing.T) { | |
| assert.ErrorContains(t, err, "config host mismatch") | ||
| }) | ||
| } | ||
|
|
||
| func TestWorkspaceValidateConfigAndEnvHost(t *testing.T) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you instead convert this to acceptance test? |
||
| t.Run("host from env mismatch", func(t *testing.T) { | ||
| w := Workspace{ | ||
| Host: "https://abc.cloud.databricks.com", | ||
| } | ||
| setupWorkspaceTest(t) | ||
| t.Setenv("DATABRICKS_HOST", "https://def.cloud.databricks.com") | ||
| _, err := w.Client() | ||
| assert.ErrorContains(t, err, "config host mismatch: DATABRICKS_HOST is defined as https://def.cloud.databricks.com, but CLI configured to use https://abc.cloud.databricks.com") | ||
| }) | ||
|
|
||
| t.Run("with profile defined", func(t *testing.T) { | ||
| w := Workspace{ | ||
| Host: "https://abc.cloud.databricks.com", | ||
| Profile: "abc", | ||
| } | ||
|
|
||
| setupWorkspaceTest(t) | ||
| // This works if there is a config file with a matching profile. | ||
| err := databrickscfg.SaveToProfile(context.Background(), &config.Config{ | ||
| Profile: "abc", | ||
| Host: "https://abc.cloud.databricks.com", | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| t.Setenv("DATABRICKS_HOST", "https://def.cloud.databricks.com") | ||
| _, err = w.Client() | ||
| require.NoError(t, err) | ||
| }) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |
| "context" | ||
|
|
||
| "github.com/databricks/cli/bundle" | ||
| "github.com/databricks/cli/bundle/config/validate" | ||
| "github.com/databricks/cli/bundle/env" | ||
| "github.com/databricks/cli/bundle/phases" | ||
| "github.com/databricks/cli/libs/cmdctx" | ||
|
|
@@ -94,6 +95,8 @@ func configureBundle(cmd *cobra.Command, b *bundle.Bundle) (*bundle.Bundle, diag | |
| return b, diags | ||
| } | ||
|
|
||
| diags = diags.Extend(bundle.Apply(ctx, b, validate.NoInterpolationInAuthConfig())) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can actually convert the whole |
||
|
|
||
| // Set the auth configuration in the command context. This can be used | ||
| // downstream to initialize a API client. | ||
| // | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package workspace | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestNormalizeHost(t *testing.T) { | ||
| assert.Equal(t, "invalid", NormalizeHost("invalid")) | ||
|
|
||
| // With port. | ||
| assert.Equal(t, "http://foo:123", NormalizeHost("http://foo:123")) | ||
|
|
||
| // With trailing slash. | ||
| assert.Equal(t, "http://foo", NormalizeHost("http://foo/")) | ||
|
|
||
| // With path. | ||
| assert.Equal(t, "http://foo", NormalizeHost("http://foo/bar")) | ||
|
|
||
| // With query string. | ||
| assert.Equal(t, "http://foo", NormalizeHost("http://foo?bar")) | ||
|
|
||
| // With anchor. | ||
| assert.Equal(t, "http://foo", NormalizeHost("http://foo#bar")) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just in case - we have a warning displayed above that explains incorrect usage of variables in auth-related fields