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

keys are inconsistent with different backends #61

Open
rogpeppe opened this issue May 9, 2019 · 4 comments
Open

keys are inconsistent with different backends #61

rogpeppe opened this issue May 9, 2019 · 4 comments
Labels

Comments

@rogpeppe
Copy link
Contributor

rogpeppe commented May 9, 2019

When using the env backend, then the only keys considered will be those with config: field tags. However, if you're using a file backend, then the entire struct is unmarshaled from the source, and all fields will be considered, even those without a config tag.

So it's possible there are some fields which are configurable only with the file backend and not with the env backend.

I think that probably that any keys that don't specify the config: tag should be ignored so backends are more consistent.

@rogpeppe
Copy link
Contributor Author

To go into a bit more detail on this:

The confita README says:

Confita scans a struct for config tags and calls all the backends one after another until the key is found. The value is then converted into the type of the field.

and then, later on:

As a special case, if the field tag is "-", the field is always omitted. This is useful if you want to populate this field on your own.

This description is true for all the backends except the file backend, which instead unmarshals the file data directly into the struct, meaning that the config tags are entirely ignored.

This has a few implications:

  • some values are only configurable in certain backends. For example, in the kafka-proxy service, it's possible to configure the proxies with the file backend but not using any of the other backends.
  • some types are not consistently treated. For example, a time.Duration field will accept 4h30m in all backends except when using JSON or TOML in the file backend, where you'd need to use 16200000000000.
  • fields that are explicitly marked with config:"-" are not ignored when using the file backend. For example, in the kafka-go component, the Consumer field is marked to be ignored, but will actually be unmarshaled when using the file backend.

This issue won't be trivial to fix in a backward compatible fashion, as making field names consistent would break some existing behaviour.

Here is some code that demonstrates some of the issues: https://play.golang.org/p/UJcNsbP6NOc

@yaziine yaziine added the bug label May 16, 2019
@yaziine
Copy link

yaziine commented May 16, 2019

Good catch @rogpeppe.

As you said it will be complicated to fix that without breaking the actual API.

Do you have any idea in mind?

@rmcodor
Copy link

rmcodor commented Sep 20, 2019

I would like to work on this issue, any guidance or directions?

@tealeg
Copy link
Contributor

tealeg commented Sep 20, 2019

@rmcodor we're actually about to branch the current codebase into a V0 branch and work on a major restructuring should make things more consistent. I'd hold off before diving into anything too big. Are you looking to work on it because it's an issue that affects you, or are you just looking for things to do? If it's the latter we can chat about that too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants