aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/commands/secrets/secrets_command.rb
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2017-02-23 19:22:55 +0100
committerGitHub <noreply@github.com>2017-02-23 19:22:55 +0100
commit8f59a1dd878f56798f88369fa5b448f17a29679d (patch)
tree5ba674c73ffb5e2f246e7a2d0a8db579733d37f5 /railties/lib/rails/commands/secrets/secrets_command.rb
parent4734d23c74fb4193aafe7cb04256bb745680d97f (diff)
parent9fdf326a5f6f7e10594dd6205cfc8e0425fb3e67 (diff)
downloadrails-8f59a1dd878f56798f88369fa5b448f17a29679d.tar.gz
rails-8f59a1dd878f56798f88369fa5b448f17a29679d.tar.bz2
rails-8f59a1dd878f56798f88369fa5b448f17a29679d.zip
Merge pull request #28128 from rails/revert-28127-revert-28038-encrypted-secrets
Revert "Revert "Add encrypted secrets""
Diffstat (limited to 'railties/lib/rails/commands/secrets/secrets_command.rb')
-rw-r--r--railties/lib/rails/commands/secrets/secrets_command.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/railties/lib/rails/commands/secrets/secrets_command.rb b/railties/lib/rails/commands/secrets/secrets_command.rb
new file mode 100644
index 0000000000..3ba8c0c85b
--- /dev/null
+++ b/railties/lib/rails/commands/secrets/secrets_command.rb
@@ -0,0 +1,36 @@
+require "active_support"
+require "rails/secrets"
+
+module Rails
+ module Command
+ class SecretsCommand < Rails::Command::Base # :nodoc:
+ def help
+ say "Usage:\n #{self.class.banner}"
+ say ""
+ say self.class.desc
+ end
+
+ def setup
+ require "rails/generators"
+ require "rails/generators/rails/encrypted_secrets/encrypted_secrets_generator"
+
+ Rails::Generators::EncryptedSecretsGenerator.start
+ end
+
+ def edit
+ require_application_and_environment!
+
+ Rails::Secrets.read_for_editing do |tmp_path|
+ puts "Waiting for secrets file to be saved. Abort with Ctrl-C."
+ system("\$EDITOR #{tmp_path}")
+ end
+
+ puts "New secrets encrypted and saved."
+ rescue Interrupt
+ puts "Aborted changing encrypted secrets: nothing saved."
+ rescue Rails::Secrets::MissingKeyError => error
+ say error.message
+ end
+ end
+ end
+end