module Amber::Configuration::EnvOverride

Defined in:

amber/configuration/env_override.cr

Class Method Summary

Class Method Detail

def self.apply_all(config : AppConfig) : AppConfig #

Apply environment variable overrides to an AppConfig instance, checking for AMBER_{SECTION}_{KEY} environment variables for each property in each subsection.

Environment variables always take highest priority, overriding both YAML file values and compiled-in defaults.


[View source]
def self.apply_custom(config : AppConfig) : Nil #

Apply AMBER_{SECTION}_{KEY} overrides to every registered custom section in config, loaded or not, the same way the built-in sections are overridden. Nested sections extend the name, as with AMBER_SERVER_SSL_KEY_FILE: AMBER_{SECTION}_{SUBSECTION}_{KEY}, and a nested section that is nil or absent is created to hold it.

Section and key names are upper-cased, and any character other than a letter or digit becomes _. Values follow the field's type, as in the built-in pass: String fields keep the text as given (an empty value stays empty), Bool fields accept true, 1 or yes, Float fields accept any number, and other fields read the value as a plain YAML scalar, so 8080 fills an Int32. A Hash field takes a variable for each key it already has, AMBER_{SECTION}_{FIELD}_{KEY}; the environment cannot add keys to it.

The section is rebuilt from its raw YAML: the mapping in the environment file, the values read for a credentials section, or, when neither exists, the registered default written as YAML. The result is stored back only when a variable was applied, after it has been read as the section's type.

Raises Amber::Exceptions::ConfigurationError naming the variable when its value does not fit the field's type. The value itself is left out of the message because it may be a secret.


[View source]
def self.apply_params(config : ParamsConfig) : Nil #

Applies AMBER_PARAMS_* overrides. Public so the V1 settings path can apply the same overrides to its parameter limits.


[View source]