diff options
Diffstat (limited to 'railties/lib/rails/commands/secrets/secrets_command.rb')
-rw-r--r-- | railties/lib/rails/commands/secrets/secrets_command.rb | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/railties/lib/rails/commands/secrets/secrets_command.rb b/railties/lib/rails/commands/secrets/secrets_command.rb index 03a640bd65..45e02fa730 100644 --- a/railties/lib/rails/commands/secrets/secrets_command.rb +++ b/railties/lib/rails/commands/secrets/secrets_command.rb @@ -1,5 +1,5 @@ require "active_support" -require "rails/secrets" +require_relative "../../secrets" module Rails module Command @@ -13,10 +13,7 @@ module Rails end def setup - require "rails/generators" - require "rails/generators/rails/encrypted_secrets/encrypted_secrets_generator" - - Rails::Generators::EncryptedSecretsGenerator.start + generator.start end def edit @@ -34,8 +31,7 @@ module Rails require_application_and_environment! Rails::Secrets.read_for_editing do |tmp_path| - say "Waiting for secrets file to be saved. Abort with Ctrl-C." - system("\$EDITOR #{tmp_path}") + system("#{ENV["EDITOR"]} #{tmp_path}") end say "New secrets encrypted and saved." @@ -43,7 +39,26 @@ module Rails say "Aborted changing encrypted secrets: nothing saved." rescue Rails::Secrets::MissingKeyError => error say error.message + rescue Errno::ENOENT => error + raise unless error.message =~ /secrets\.yml\.enc/ + + Rails::Secrets.read_template_for_editing do |tmp_path| + system("#{ENV["EDITOR"]} #{tmp_path}") + generator.skip_secrets_file { setup } + end + end + + def show + say Rails::Secrets.read end + + private + def generator + require_relative "../../generators" + require_relative "../../generators/rails/encrypted_secrets/encrypted_secrets_generator" + + Rails::Generators::EncryptedSecretsGenerator + end end end end |