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

Feature Suggestion — Check arbitrary keys/values #126

Closed
rossmcf opened this issue Jul 5, 2018 · 5 comments
Closed

Feature Suggestion — Check arbitrary keys/values #126

rossmcf opened this issue Jul 5, 2018 · 5 comments

Comments

@rossmcf
Copy link

rossmcf commented Jul 5, 2018

I work in a team that uses docker-compose. Commonly, we have docker-compose.yml files for each of our environments. It's a fairly common issue that we define new environment variables for a service, but forget to include them in the production environment's compose file, since it doesn't tend to be used locally.

I don't propose to make envconfig aware of docker compose, but I would like a way to 'check' an arbitrary set of keys/values against a spec. I can put together a tool to get the environment variables from the docker-compose file, but I can't currently pass those in to envconfig. Would you be open to adding a Check(prefix string, spec interface{}, kvs map[string]string) method? I'd be happy to submit a PR for it.

@rossmcf
Copy link
Author

rossmcf commented Jul 16, 2018

PR submitted. Suggestions welcome.

@CAFxX
Copy link
Contributor

CAFxX commented Sep 3, 2018

I don't understand the requirement. If you want to protect against forgetting to add the environment variables in production, can't you simply mark the fields as required?

@rossmcf
Copy link
Author

rossmcf commented Oct 19, 2018

@CAFxX We do that, but the issue we have is that we have to start up the service with each environment's config file in order to see the missing values. And in some cases we'd rather not start a service with production config, as it might start consuming from queues, for example.

@CAFxX
Copy link
Contributor

CAFxX commented Oct 19, 2018

Wouldn't having a dry-run/config validation flag that instructs the process to exit immediately after parsing its configuration be the simple and easy solution, then?

func main() {
  cfg := &Config{}
  if err := envconfig.Parse(cfg); err != nil {
    // Fatal(err)
  }

  // perform here any additional config validation, erroring out if it fails...

  if cfg.DryRun {
    os.Exit(0)
  }

  // actual program logic...
}

Alternatively, why can't you produce a parseable dump of the list of known envvars using Usagef/Usaget, and then use it during your build process to validate whatever preconditions have to be met for a successful build?

@teepark
Copy link
Collaborator

teepark commented May 24, 2019

I had some feedback on the PR, but @CAFxX you're way ahead of me here. Great suggestions, thank you.

@teepark teepark closed this as completed May 24, 2019
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 a pull request may close this issue.

3 participants