Skip to content
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

Merged
merged 4 commits into from
Oct 20, 2023

Conversation

pietern
Copy link
Contributor

@pietern pietern commented Oct 19, 2023

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:

  • Resolve the configuration prior to performing the check.
  • Don't treat the configuration file not existing as an error.
  • Add unit tests.

Fixes #884.

Tests

Unit tests and manual confirmation.

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)
}

Copy link
Contributor Author

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.

configFile, err := config.LoadFile(cfg.ConfigFile)
if err != nil {
if os.IsNotExist(err) {
return nil
}
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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()
Copy link
Contributor Author

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
}
Copy link
Contributor Author

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.

cmd/root/bundle_test.go Show resolved Hide resolved
configFile, err := config.LoadFile(cfg.ConfigFile)
if err != nil {
if os.IsNotExist(err) {
return nil
Copy link
Contributor

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?

Copy link
Contributor Author

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:

https://github.com/databricks/databricks-sdk-go/blob/415522e1015ea099b775ae1a89e8b5721dcc2168/config/config_file.go#L79-L83

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.

@pietern pietern added this pull request to the merge queue Oct 20, 2023
Merged via the queue into main with commit d4be405 Oct 20, 2023
4 checks passed
@pietern pietern deleted the resolve-config-before-host-check branch October 20, 2023 13:16
pietern added a commit that referenced this pull request Oct 23, 2023
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)).
@pietern pietern mentioned this pull request Oct 23, 2023
github-merge-queue bot pushed a commit that referenced this pull request Oct 23, 2023
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)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DATABRICKS_CONFIG_FILE isn't used by many commands
2 participants