From f27319a72a4ccfbffc575b752e4d91136f23725e Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Thu, 16 Nov 2017 07:41:14 +0900 Subject: Add master key to `gitignore` on `rails new` We generate master key on `rails new`. Therefore, if do not add master key to `.gitginore` on `rails new`as well, there is a possibility that the master key will be committed accidentally. --- railties/lib/rails/generators/rails/app/app_generator.rb | 4 +++- .../rails/encryption_key_file/encryption_key_file_generator.rb | 4 ++++ .../lib/rails/generators/rails/master_key/master_key_generator.rb | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails/generators') diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index a99037576d..1fdfc3ca52 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -162,7 +162,9 @@ module Rails return if options[:pretend] || options[:dummy_app] require "rails/generators/rails/master_key/master_key_generator" - Rails::Generators::MasterKeyGenerator.new([], quiet: options[:quiet]).add_master_key_file_silently + master_key_generator = Rails::Generators::MasterKeyGenerator.new([], quiet: options[:quiet]) + master_key_generator.add_master_key_file_silently + master_key_generator.ignore_master_key_file_silently end def credentials diff --git a/railties/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb b/railties/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb index dd0d0c6c66..a396a9661f 100644 --- a/railties/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +++ b/railties/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb @@ -44,6 +44,10 @@ module Rails end end + def ignore_key_file_silently(key_path, ignore: key_ignore(key_path)) + append_to_file ".gitignore", ignore if File.exist?(".gitignore") + end + private def key_ignore(key_path) [ "", "/#{key_path}", "" ].join("\n") 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 de65146a8e..7f57340c11 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 @@ -34,6 +34,10 @@ module Rails key_file_generator.ignore_key_file(MASTER_KEY_PATH, ignore: key_ignore) end + def ignore_master_key_file_silently + key_file_generator.ignore_key_file_silently(MASTER_KEY_PATH, ignore: key_ignore) + end + private def key_file_generator EncryptionKeyFileGenerator.new([], options) -- cgit v1.2.3