diff options
author | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2017-09-12 17:06:59 +0900 |
---|---|---|
committer | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2017-09-14 07:17:25 +0900 |
commit | d5d41c82810f96ee7ab5a34aeb75b46fe407a596 (patch) | |
tree | 18911afc18ef5c8fdf7407f5767a0905bde28d13 /railties/lib | |
parent | 69f976b859cae7f9d050152103da018b7f5dda6d (diff) | |
download | rails-d5d41c82810f96ee7ab5a34aeb75b46fe407a596.tar.gz rails-d5d41c82810f96ee7ab5a34aeb75b46fe407a596.tar.bz2 rails-d5d41c82810f96ee7ab5a34aeb75b46fe407a596.zip |
Make master key added to gitignore the same value as when creating appplication
For gitignore generated by `rails new`, key with a leading slash is specified.
https://github.com/rails/rails/blob/69f976b859cae7f9d050152103da018b7f5dda6d/railties/lib/rails/generators/rails/app/templates/gitignore#L11
Therefore, when executing `credentials:edit`, also need leading slack.
In order to avoid such a difference, fixed to use same method for
`rails new` and `credentials:edit`.
Diffstat (limited to 'railties/lib')
3 files changed, 15 insertions, 17 deletions
diff --git a/railties/lib/rails/commands/credentials/credentials_command.rb b/railties/lib/rails/commands/credentials/credentials_command.rb index 39a4e3c833..88fb032d84 100644 --- a/railties/lib/rails/commands/credentials/credentials_command.rb +++ b/railties/lib/rails/commands/credentials/credentials_command.rb @@ -53,7 +53,6 @@ module Rails def ensure_master_key_has_been_added master_key_generator.add_master_key_file - master_key_generator.ignore_master_key_file end def ensure_credentials_have_been_added diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore b/railties/lib/rails/generators/rails/app/templates/gitignore index c37f01a848..83a7b211aa 100644 --- a/railties/lib/rails/generators/rails/app/templates/gitignore +++ b/railties/lib/rails/generators/rails/app/templates/gitignore @@ -7,9 +7,6 @@ # Ignore bundler config. /.bundle -# Ignore master key for decrypting credentials and more. -/config/master.key - <% if sqlite3? -%> # Ignore the default SQLite database. /db/*.sqlite3 diff --git a/railties/lib/rails/generators/rails/master_key/master_key_generator.rb b/railties/lib/rails/generators/rails/master_key/master_key_generator.rb index 36a0b69e76..a79e83495a 100644 --- a/railties/lib/rails/generators/rails/master_key/master_key_generator.rb +++ b/railties/lib/rails/generators/rails/master_key/master_key_generator.rb @@ -22,6 +22,8 @@ module Rails say "" add_master_key_file_silently key say "" + + ignore_master_key_file end end @@ -29,24 +31,24 @@ module Rails create_file MASTER_KEY_PATH, key || ActiveSupport::EncryptedFile.generate_key end - def ignore_master_key_file - if File.exist?(".gitignore") - unless File.read(".gitignore").include?(key_ignore) - say "Ignoring #{MASTER_KEY_PATH} so it won't end up in Git history:" - say "" - append_to_file ".gitignore", key_ignore + private + def ignore_master_key_file + if File.exist?(".gitignore") + unless File.read(".gitignore").include?(key_ignore) + say "Ignoring #{MASTER_KEY_PATH} so it won't end up in Git history:" + say "" + append_to_file ".gitignore", key_ignore + say "" + end + else + say "IMPORTANT: Don't commit #{MASTER_KEY_PATH}. Add this to your ignore file:" + say key_ignore, :on_green say "" end - else - say "IMPORTANT: Don't commit #{MASTER_KEY_PATH}. Add this to your ignore file:" - say key_ignore, :on_green - say "" end - end - private def key_ignore - [ "", "# Ignore master key for decrypting credentials and more.", MASTER_KEY_PATH, "" ].join("\n") + [ "", "# Ignore master key for decrypting credentials and more.", "/#{MASTER_KEY_PATH}", "" ].join("\n") end end end |