Skip to content

Do not allow config attributes to be set multiple times#170

Closed
pietern wants to merge 2 commits intomainfrom
test-profile-and-host-token
Closed

Do not allow config attributes to be set multiple times#170
pietern wants to merge 2 commits intomainfrom
test-profile-and-host-token

Conversation

@pietern
Copy link
Copy Markdown
Contributor

@pietern pietern commented Nov 23, 2022

Doing so results in ambiguity; e.g. does it pick up the configuration from the
profile in ~/.databrickscfg, the environment, or the constructed struct.

Doing so results in ambiguity; e.g. does it pick up the configuration from the
profile in ~/.databrickscfg, the environment, or the constructed struct.
@pietern
Copy link
Copy Markdown
Contributor Author

pietern commented Nov 23, 2022

@nfx This needs discussion.

The premise of this PR would actively deny the following because it's ambiguous.

func TestConfig_AttributePrecedence(t *testing.T) {
	configFixture{
		host: "y",
		env: map[string]string{
			"DATABRICKS_HOST":     "x",
			"DATABRICKS_USERNAME": "x",
			"DATABRICKS_PASSWORD": "x",
		},
		assertAuth: "basic",
		assertHost: "https://y",
	}.apply(t)
}

The first commit only does this for overrides from the profile. I think we should also disallow overriding through environment variable if the struct already contains a host.

@pietern
Copy link
Copy Markdown
Contributor Author

pietern commented Nov 23, 2022

The test fails because I want to discuss prior to changing the tests.

for _, attr := range alreadySet {
names = append(names, attr.Name)
}
return fmt.Errorf("attributes already set: %s", strings.Join(names, ", "))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the failing tests are considered configuration contracts in the Terraform provider - e.g. "Public API". we cannot fail those.

I agree that configuration precedence can be tuned/changed, but only in a way that doesn't break the configuration contract.

Common sense is:

  • Environment variable can override whatever was in the configuration file
  • Directly configured value probably should not be overridable via env vars

Perhaps it could be best addressed via splitting ConfigAttributes into two different loaders

c.Loaders = []Loader{
ConfigAttributes,
KnownConfigLoader{},
}
: one before known config file, one after.

@pietern
Copy link
Copy Markdown
Contributor Author

pietern commented Nov 24, 2022

Superseded by #185.

@pietern pietern closed this Nov 24, 2022
@pietern pietern deleted the test-profile-and-host-token branch November 24, 2022 19:53
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.

2 participants