diff options
author | Wojciech Wnętrzak <w.wnetrzak@gmail.com> | 2017-11-14 11:44:23 +0100 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2017-11-15 21:29:15 +0100 |
commit | 7a8728a03986489e1c843ed850afc2c16fb6eb06 (patch) | |
tree | 697428ddbb785a4ce32a77a43a5487914d28d3d1 /railties/lib/rails/command/helpers | |
parent | ed100166874fb4a542c5aaba933a4cca5ed72269 (diff) | |
download | rails-7a8728a03986489e1c843ed850afc2c16fb6eb06.tar.gz rails-7a8728a03986489e1c843ed850afc2c16fb6eb06.tar.bz2 rails-7a8728a03986489e1c843ed850afc2c16fb6eb06.zip |
Add CLI to manage encrypted files/configs.
To edit/show encrypted file:
```
bin/rails encrypted:edit config/staging_tokens.yml.enc
bin/rails encrypted:edit config/staging_tokens.yml.enc --key config/staging.key
bin/rails encrypted:show config/staging_tokens.yml.enc
```
Also provides a backing Rails.application.encrypted API for Ruby access:
```ruby
Rails.application.encrypted("config/staging_tokens.yml.enc").read
Rails.application.encrypted("config/staging_tokens.yml.enc").config
Rails.application.encrypted("config/staging_tokens.yml.enc", key: "config/staging.key")
```
Diffstat (limited to 'railties/lib/rails/command/helpers')
-rw-r--r-- | railties/lib/rails/command/helpers/editor.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/railties/lib/rails/command/helpers/editor.rb b/railties/lib/rails/command/helpers/editor.rb new file mode 100644 index 0000000000..5e9ecc05e7 --- /dev/null +++ b/railties/lib/rails/command/helpers/editor.rb @@ -0,0 +1,33 @@ +require "active_support/encrypted_file" + +module Rails + module Command + module Helpers + module Editor + private + def ensure_editor_available(command:) + if ENV["EDITOR"].to_s.empty? + say "No $EDITOR to open file in. Assign one like this:" + say "" + say %(EDITOR="mate --wait" #{command}) + say "" + say "For editors that fork and exit immediately, it's important to pass a wait flag," + say "otherwise the credentials will be saved immediately with no chance to edit." + + false + else + true + end + end + + def catch_editing_exceptions + yield + rescue Interrupt + say "Aborted changing file: nothing saved." + rescue ActiveSupport::EncryptedFile::MissingKeyError => error + say error.message + end + end + end + end +end |