Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Precedence of Configuration options: Environment, Registry, Configuration file and Commandline In What Order?

So this is a funny little thing I thing Stack Overflow has not discussed before. Not really a life and death question, but something I'd like to hear your input.

In short: my program is a bit over engineered in this regard: it takes configuration options from four different places:

  • Command line parameters
  • Configuration file
  • Environment variable
  • Windows Registry
  • (And hardcoded default values)

The question is, in what order should these be evaluated? I think it's clear that the command line options have the last say, but what about the three others? If the same option is set in both environment and ini-file, which should take precedence?

What about registry, does registry override the ini assuming I use that to change the runtime settings of the program, should I rewrite changes applied to registry into the configuration file as well? Should I set it so that registry settings can't override settings read from environment?

(If you wonder how on earth this is possible, one word: X-macro.)

like image 837
VITTUIX-MAN Avatar asked Aug 28 '15 14:08

VITTUIX-MAN


People also ask

What is environment configuration file?

A configuration file, often shortened to config file, defines the parameters, options, settings and preferences applied to operating systems (OSes), infrastructure devices and applications in an IT context.

What are environment variables in spring boot?

At application startup, Spring Boot will look for an environment variable called SPRING_APPLICATION_JSON . It can be used to provide a set of application properties using inline JSON. For example, you can set ec2. public. url property as follows.

Does Yaml support environment variables?

Environment variable substitution is supported in both the great_expectations. yml and config variables config_variables.


1 Answers

Ordered by priority i would go this way: cli > envvars > registry > config > defaults

  • cli: it takes the options that you surely want to use when you manually start the program
  • envvar: generaly used to manually override configuration file options at runtime (often also used today to manage configuration options in containers environments, cf. 12factor app)
  • registry: specific to Microsoft Windows world, but according to what you said it have almost the same purpose that environment variables
  • config: defined at installation/configuration time so these are the "user wanted default options"
  • defaults: minimal config to run securely (for example listen on localhost only) when nothing else is provided
like image 196
Nicolas Karolak Avatar answered Sep 18 '22 14:09

Nicolas Karolak