Skip to content

dnsproviders: Implement NewConfigFromEnv() #1058

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

Closed
wants to merge 2 commits into from

Conversation

mholt
Copy link
Contributor

@mholt mholt commented Feb 9, 2020

This allows getting a config populated from env variables.
Without this, the only way to do this is to copy/duplicate all the env var logic.

NewConfigFromEnv() treats env variables as optional defaults.
Since the config struct is returned, its values can still be set/changed/read by the caller, which is immensely useful during application setup/config.

In practice, this allows us to keep credentials out of config files, while still being able to configure other elements of the DNS provider in code without relying on global env vars (which we can't do in Caddy 2, since we don't really have much/any global state -- so using a global value would lead to incorrect results).

Fixes #1054

I am just starting out with a few providers of my choice, but I am sure there will be more to follow!

This allows getting a config populated from env variables. Without this,
the only way to do this is to copy/duplicate all the env var logic.
NewConfigFromEnv() treats env variables as optional defaults. Since the
config struct is returned, its values can still be set/changed/read by
the caller, which is immensely useful during application setup/config.

See go-acme#1054
@ldez ldez changed the title cloudflare, digitalocean, dnsimple: Implement NewConfigFromEnv() dnsproviders: Implement NewConfigFromEnv() Feb 9, 2020
@ldez ldez self-requested a review February 9, 2020 20:31
@ldez
Copy link
Member

ldez commented Feb 9, 2020

You have to allow maintainers to modify your PR.

@mholt
Copy link
Contributor Author

mholt commented Feb 9, 2020

What do you want to change?

@ldez
Copy link
Member

ldez commented Feb 9, 2020

The behavior is not good: NewConfigFromEnv() must return error.

@mholt
Copy link
Contributor Author

mholt commented Feb 9, 2020

Hmm, why is that? NewDefaultConfig() does not return an error.

I do not think this function should return an error.

Env vars aren't required since the config is being returned so the caller can further populate its fields. If we want to verify a config and return errors, that should be done in NewDNSProviderConfig().

@ldez
Copy link
Member

ldez commented Feb 9, 2020

Do you have run the tests?

This function must return errors.

@ldez
Copy link
Member

ldez commented Feb 9, 2020

I understand what you want to do but it is not compatible with the behavior that I want.

So we need to find another solution.

@mholt
Copy link
Contributor Author

mholt commented Feb 9, 2020

go test ./... passes on my machine. How do I view what failed in the CI? I see thousands of lines of output in the Travis logs and https://github.com/go-acme/lego/pull/1058/checks?check_run_id=434919480 doesn't actually say what the failure is.

I understand what you want to do but it is not compatible with the behavior that I want.

What behavior do you want, exactly?

@ldez
Copy link
Member

ldez commented Feb 9, 2020

the tests fail on my computer, it's not related to the CI.

https://travis-ci.com/go-acme/lego/builds/148108650

@mholt
Copy link
Contributor Author

mholt commented Feb 9, 2020

Ah, I found it. (I've been having major issues with VS Code + gopls and modules lately for some reason.) One moment, will submit a corrective commit for the test.

@ldez
Copy link
Member

ldez commented Feb 9, 2020

Don't fix the tests for now.

I repeat I don't agree with your changes.

@mholt
Copy link
Contributor Author

mholt commented Feb 9, 2020

@ldez Too late 😄 These tests assume that env variables are required, which is not the case since the struct can be filled out by the caller.

@ldez
Copy link
Member

ldez commented Feb 9, 2020

You cannot remove the tests. Also I don't agree with that.

@mholt
Copy link
Contributor Author

mholt commented Feb 9, 2020

You cannot remove the tests. Also I don't agree with that.

Well, I did remove the tests, because with this refactor they are no longer relevant. The remaining tests cover NewConfigFromEnv because NewDNSProvider calls it directly.

Er, what don't you agree with, exactly?

@ldez
Copy link
Member

ldez commented Feb 9, 2020

I think we did not understand each other in the issue, we do not have the same vision of the behavior of the method.

Now I see what do you want, and I'm reconsidering your request.

@ldez
Copy link
Member

ldez commented Feb 9, 2020

I cannot accept your PR, the error from NewConfigFromEnv() must be kept.

There are several thing that can produce those errors (not only missing env vars) and message details (in the missing env var case) are important.

I refuse to change the behavior only for another application (even if it's Traefik or Caddy).

As solution, I think we can expose the env vars names to help you.

So for now, I will close this PR and continue to discuss on the issue #1054.

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

Successfully merging this pull request may close these issues.

DNS providers: Don't return half-populated configs from environment
2 participants