diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2017-12-18 19:57:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-18 19:57:35 +0100 |
commit | 053a4c699043ea5449effaba0549b2f8a5821228 (patch) | |
tree | 9cfd7534cd26773698584e981dd1858b13c9bc53 /railties/lib/rails/commands | |
parent | 1d047235b0cefcb80d4e18fed732cbe2bd32a8ee (diff) | |
parent | 35373219c91ea8096ef2f8e7f3c62bcd46f436be (diff) | |
download | rails-053a4c699043ea5449effaba0549b2f8a5821228.tar.gz rails-053a4c699043ea5449effaba0549b2f8a5821228.tar.bz2 rails-053a4c699043ea5449effaba0549b2f8a5821228.zip |
Merge pull request #31348 from y-yagi/fix_31283
Raise an error only when `require_master_key` is specified
Diffstat (limited to 'railties/lib/rails/commands')
-rw-r--r-- | railties/lib/rails/commands/credentials/credentials_command.rb | 11 | ||||
-rw-r--r-- | railties/lib/rails/commands/encrypted/encrypted_command.rb | 12 |
2 files changed, 19 insertions, 4 deletions
diff --git a/railties/lib/rails/commands/credentials/credentials_command.rb b/railties/lib/rails/commands/credentials/credentials_command.rb index 8085f07c2b..385d3976da 100644 --- a/railties/lib/rails/commands/credentials/credentials_command.rb +++ b/railties/lib/rails/commands/credentials/credentials_command.rb @@ -33,8 +33,7 @@ module Rails def show require_application_and_environment! - say Rails.application.credentials.read.presence || - "No credentials have been added yet. Use bin/rails credentials:edit to change that." + say Rails.application.credentials.read.presence || missing_credentials_message end private @@ -67,6 +66,14 @@ module Rails Rails::Generators::CredentialsGenerator.new end + + def missing_credentials_message + if Rails.application.credentials.key.nil? + "Missing master key to decrypt credentials. See bin/rails credentials:help" + else + "No credentials have been added yet. Use bin/rails credentials:edit to change that." + end + end end end end diff --git a/railties/lib/rails/commands/encrypted/encrypted_command.rb b/railties/lib/rails/commands/encrypted/encrypted_command.rb index 898094f1a4..912c453f09 100644 --- a/railties/lib/rails/commands/encrypted/encrypted_command.rb +++ b/railties/lib/rails/commands/encrypted/encrypted_command.rb @@ -37,9 +37,9 @@ module Rails def show(file_path) require_application_and_environment! + encrypted = Rails.application.encrypted(file_path, key_path: options[:key]) - say Rails.application.encrypted(file_path, key_path: options[:key]).read.presence || - "File '#{file_path}' does not exist. Use bin/rails encrypted:edit #{file_path} to change that." + say encrypted.read.presence || missing_encrypted_message(key: encrypted.key, key_path: options[:key], file_path: file_path) end private @@ -72,6 +72,14 @@ module Rails Rails::Generators::EncryptedFileGenerator.new end + + def missing_encrypted_message(key:, key_path:, file_path:) + if key.nil? + "Missing '#{key_path}' to decrypt data. See bin/rails encrypted:help" + else + "File '#{file_path}' does not exist. Use bin/rails encrypted:edit #{file_path} to change that." + end + end end end end |