-
Jonathan Hefner authored
This commit changes the credentials commands (e.g. `bin/rails credentials:edit`) to load `config/environments/#{Rails.env}.rb`. Thus, `config.credentials.content_path` and `config.credentials.key_path` can be set in `config/environments/*.rb`, in addition to the currently supported `config/application.rb`. The `load_environment_config` initializer, which is run via `Rails.application.initialize!`, is responsible for loading the appropriate `config/environments/*.rb` file. Normally, when booting an app, `Rails.application.initialize!` is called without arguments by `config/environment.rb`, which is loaded via `Rails.application.require_environment!`. Doing so runs all initializers. Running all initializers is problematic for credentials commands because (1) initializers might try to access resources that aren't available (e.g. a production database), and (2) initializers might try to read credentials values that have not yet been set in the current environment's credentials (see #34789). Thus, the credentials commands call `Rails.application.initialize!` directly with a dummy group argument, so that initializers in the `:all` group -- including `load_environment_config` -- are run, but not initializers in the default group, such as `active_record.initialize_database` and `load_config_initializers`. Closes #40778. Co-authored-by Brian Thoman <>
Jonathan Hefner authoredThis commit changes the credentials commands (e.g. `bin/rails credentials:edit`) to load `config/environments/#{Rails.env}.rb`. Thus, `config.credentials.content_path` and `config.credentials.key_path` can be set in `config/environments/*.rb`, in addition to the currently supported `config/application.rb`. The `load_environment_config` initializer, which is run via `Rails.application.initialize!`, is responsible for loading the appropriate `config/environments/*.rb` file. Normally, when booting an app, `Rails.application.initialize!` is called without arguments by `config/environment.rb`, which is loaded via `Rails.application.require_environment!`. Doing so runs all initializers. Running all initializers is problematic for credentials commands because (1) initializers might try to access resources that aren't available (e.g. a production database), and (2) initializers might try to read credentials values that have not yet been set in the current environment's credentials (see #34789). Thus, the credentials commands call `Rails.application.initialize!` directly with a dummy group argument, so that initializers in the `:all` group -- including `load_environment_config` -- are run, but not initializers in the default group, such as `active_record.initialize_database` and `load_config_initializers`. Closes #40778. Co-authored-by Brian Thoman <>
Loading