Merge pull request #2502 from betagouv/check-env-vars
initializers: check at runtime that env vars declared in env.example are present
This commit is contained in:
commit
9880546d0c
1 changed files with 13 additions and 0 deletions
13
config/initializers/env_vars.rb
Normal file
13
config/initializers/env_vars.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Ensure that the environment variables defined in the reference env vars file
|
||||||
|
# are present in the execution environment.
|
||||||
|
#
|
||||||
|
# This protects against an out-to-date environment leading to runtime errors.
|
||||||
|
|
||||||
|
if ENV['RAILS_ENV'] != 'test' && File.basename($0) != 'rake'
|
||||||
|
reference_env_file = File.join('config', 'env.example')
|
||||||
|
Dotenv::Environment.new(Rails.root.join(reference_env_file)).each do |key, value|
|
||||||
|
if !ENV.key?(key.to_s)
|
||||||
|
raise "Configuration error: `#{key}` is not present in the process’ environment variables (declared in `#{reference_env_file}`)"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue