aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/encrypted_file.rb
diff options
context:
space:
mode:
authoryuuji.yaginuma <yuuji.yaginuma@gmail.com>2017-12-05 21:41:19 +0900
committeryuuji.yaginuma <yuuji.yaginuma@gmail.com>2017-12-18 08:04:15 +0900
commit35373219c91ea8096ef2f8e7f3c62bcd46f436be (patch)
tree568eddd5f7ef943f297c8cfe56d1087d371d5122 /activesupport/lib/active_support/encrypted_file.rb
parentdaf15f58b943d85d8fb726590ae94f77ca0a5d5f (diff)
downloadrails-35373219c91ea8096ef2f8e7f3c62bcd46f436be.tar.gz
rails-35373219c91ea8096ef2f8e7f3c62bcd46f436be.tar.bz2
rails-35373219c91ea8096ef2f8e7f3c62bcd46f436be.zip
Raise an error only when `require_master_key` is specified
To prevent errors from being raise in environments where credentials is unnecessary. Context: https://github.com/rails/rails/issues/31283#issuecomment-348801489 Fixes #31283
Diffstat (limited to 'activesupport/lib/active_support/encrypted_file.rb')
-rw-r--r--activesupport/lib/active_support/encrypted_file.rb10
1 files changed, 5 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/encrypted_file.rb b/activesupport/lib/active_support/encrypted_file.rb
index 3d1455fb95..671b6b6a69 100644
--- a/activesupport/lib/active_support/encrypted_file.rb
+++ b/activesupport/lib/active_support/encrypted_file.rb
@@ -26,11 +26,11 @@ module ActiveSupport
end
- attr_reader :content_path, :key_path, :env_key
+ attr_reader :content_path, :key_path, :env_key, :raise_if_missing_key
- def initialize(content_path:, key_path:, env_key:)
+ def initialize(content_path:, key_path:, env_key:, raise_if_missing_key:)
@content_path, @key_path = Pathname.new(content_path), Pathname.new(key_path)
- @env_key = env_key
+ @env_key, @raise_if_missing_key = env_key, raise_if_missing_key
end
def key
@@ -38,7 +38,7 @@ module ActiveSupport
end
def read
- if content_path.exist?
+ if !key.nil? && content_path.exist?
decrypt content_path.binread
else
raise MissingContentError, content_path
@@ -93,7 +93,7 @@ module ActiveSupport
end
def handle_missing_key
- raise MissingKeyError, key_path: key_path, env_key: env_key
+ raise MissingKeyError, key_path: key_path, env_key: env_key if raise_if_missing_key
end
end
end