-
Notifications
You must be signed in to change notification settings - Fork 55
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
Resolve configuration before performing verification #890
Conversation
If a bundle configuration specifies a workspace host, and the user specifies a profile to use, we perform a check to confirm that the workspace host in the bundle configuration and the workspace host from the profile are identical. If they are not, we return an error. The check was introduced in #571. Previously, the code included an assumption that the client configuration was already loaded from the environment prior to performing the check. This was not the case, and as such if the user intended to use a non-default path to `.databrickscfg`, this path was not used when performing the check. The fix does the following: * Resolve the configuration prior to performing the check. * Don't treat the configuration file not existing as an error. * Add unit tests. Fixes #884.
assert.NoError(t, err) | ||
assert.Equal(t, "default", cfg.Token) | ||
} | ||
|
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.
This test is superfluous.
The same is covered by TestLoaderMatchingHost
and TestLoaderMatchingHostWithQuery
below.
libs/databrickscfg/ops.go
Outdated
configFile, err := config.LoadFile(cfg.ConfigFile) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
return nil | ||
} |
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.
This fixes the error if the configuration file doesn't exist.
@@ -59,7 +59,7 @@ func TestLoaderErrorsOnInvalidFile(t *testing.T) { | |||
assert.ErrorContains(t, err, "unclosed section: ") | |||
} | |||
|
|||
func TestLoaderSkipssNoMatchingHost(t *testing.T) { | |||
func TestLoaderSkipsNoMatchingHost(t *testing.T) { |
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.
Typo.
@@ -103,6 +103,7 @@ func (l profileFromHostLoader) Configure(cfg *config.Config) error { | |||
return fmt.Errorf("%s %s profile: %w", configFile.Path(), match.Name(), err) | |||
} | |||
|
|||
cfg.Profile = match.Name() |
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.
Write back the profile after selecting one so we can assert on it in tests.
err := cfg.EnsureResolved() | ||
if err != nil { | ||
return nil, err | ||
} |
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.
After this, all environment variables, and optionally a profile, have been loaded.
libs/databrickscfg/ops.go
Outdated
configFile, err := config.LoadFile(cfg.ConfigFile) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
return nil |
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.
Not entirely clear what happens if configuration file is not found, are we just skipping this validate and fail at a later point?
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.
Good point -- it did indeed skip validation, similar to how the SDK allows a profile to be set but doesn't error:
However, the intent here is always to use a profile if it is specified, so it should return an error if we cannot resolve the profile. Addressed this in the next commit.
CLI: * Never load authentication configuration from bundle for sync command ([#889](#889)). * Fixed requiring positional arguments for API URL parameters ([#878](#878)). Bundles: * Add support for validating CLI version when loading a jsonschema object ([#883](#883)). * Do not emit wheel wrapper error when python_wheel_wrapper setting is true ([#894](#894)). * Resolve configuration before performing verification ([#890](#890)). * Fix wheel task not working with with 13.x clusters ([#898](#898)). Internal: * Skip prompt on completion hook ([#888](#888)). * New YAML loader to support configuration location ([#828](#828)). Dependency updates: * Bump github.com/mattn/go-isatty from 0.0.19 to 0.0.20 ([#896](#896)).
CLI: * Never load authentication configuration from bundle for sync command ([#889](#889)). * Fixed requiring positional arguments for API URL parameters ([#878](#878)). Bundles: * Add support for validating CLI version when loading a jsonschema object ([#883](#883)). * Do not emit wheel wrapper error when python_wheel_wrapper setting is true ([#894](#894)). * Resolve configuration before performing verification ([#890](#890)). * Fix wheel task not working with with 13.x clusters ([#898](#898)). Internal: * Skip prompt on completion hook ([#888](#888)). * New YAML loader to support configuration location ([#828](#828)). Dependency updates: * Bump github.com/mattn/go-isatty from 0.0.19 to 0.0.20 ([#896](#896)).
Changes
If a bundle configuration specifies a workspace host, and the user specifies a profile to use, we perform a check to confirm that the workspace host in the bundle configuration and the workspace host from the profile are identical. If they are not, we return an error. The check was introduced in #571.
Previously, the code included an assumption that the client configuration was already loaded from the environment prior to performing the check. This was not the case, and as such if the user intended to use a non-default path to
.databrickscfg
, this path was not used when performing the check.The fix does the following:
Fixes #884.
Tests
Unit tests and manual confirmation.