Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add possibility to set custom
Rails.application.credentials
object.
In multi environment application one can set custom file by: ``` config.before_initialize do self.credentials = encrypted("config/custom-credentials.yml.enc") end ```
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
require "isolation/abstract_unit" | ||
|
||
module ApplicationTests | ||
class CredentialsTest < ActiveSupport::TestCase | ||
include ActiveSupport::Testing::Isolation | ||
|
||
setup :build_app | ||
teardown :teardown_app | ||
|
||
test "sets custom application credentials" do | ||
Dir.chdir(app_path) do | ||
File.write("config/master.key", ActiveSupport::EncryptedFile.generate_key) | ||
|
||
file = ActiveSupport::EncryptedFile.new( | ||
content_path: "config/custom-credentials.yml.enc", | ||
key_path: "config/master.key", | ||
env_key: "RAILS_MASTER_KEY" | ||
) | ||
|
||
file.write("aws_access_key_id: secret-key") | ||
end | ||
|
||
add_to_config <<-RUBY | ||
config.before_initialize do | ||
self.credentials = encrypted("config/custom-credentials.yml.enc") | ||
end | ||
RUBY | ||
|
||
require "#{app_path}/config/environment" | ||
|
||
assert_equal "secret-key", Rails.application.credentials.aws_access_key_id | ||
end | ||
end | ||
end |