Class: Envault::CLI
- Inherits:
-
Thor
- Object
- Thor
- Envault::CLI
- Defined in:
- lib/envault/cli.rb
Instance Method Summary collapse
- #decrypt ⇒ Object
- #decrypt_file ⇒ Object
- #encrypt ⇒ Object
- #encrypt_file ⇒ Object
-
#initialize(args = [], options = {}, config = {}) ⇒ CLI
constructor
A new instance of CLI.
- #load ⇒ Object
- #reencrypt_file ⇒ Object
Constructor Details
#initialize(args = [], options = {}, config = {}) ⇒ CLI
Returns a new instance of CLI.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/envault/cli.rb', line 16 def initialize(args = [], = {}, config = {}) super(args, , config) @class_options = config[:shell].base. current_command = config[:current_command].name unless SKIP_INITIALIZE_COMMANDS.include?(current_command) @core = Core.new( config: @class_options[:config], profile: @class_options[:profile], prefix: @class_options[:prefix], debug: @class_options[:debug] ) @logger = @core.logger end end |
Instance Method Details
#decrypt ⇒ Object
39 40 41 |
# File 'lib/envault/cli.rb', line 39 def decrypt puts @core.cryptor.decrypt([:source]) end |
#decrypt_file ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/envault/cli.rb', line 99 def decrypt_file result = {} [:plain_text].each do |plain_text_path| result = result.merge(YAML.load(ERB.new(File.read(plain_text_path)).result)) end [:source].each do |encrypt_yaml_path| result = result.merge(@core.decrypt_yaml(encrypt_yaml_path)) end if [:output] Formatter.write_escape_yaml([:output], result, [:quote]) else puts Formatter.escape_yaml(result, [:quote]) end end |
#encrypt ⇒ Object
33 34 35 |
# File 'lib/envault/cli.rb', line 33 def encrypt puts @core.cryptor.encrypt([:source]) end |
#encrypt_file ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/envault/cli.rb', line 79 def encrypt_file result = {} [:plain_text].each do |plain_text_path| result = result.merge(YAML.load(ERB.new(File.read(plain_text_path)).result)) end [:source].each do |secret_yaml_path| result = result.merge(@core.encrypt_yaml(secret_yaml_path, [:keys])) end if [:output] Formatter.write_escape_yaml([:output], result, [:quote]) else puts Formatter.escape_yaml(result, [:quote]) end end |
#load ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/envault/cli.rb', line 117 def load [:sources].each do |source| begin @core.load(source) rescue => e raise "error => [#{source}]\n#{e.}\n#{e.backtrace.join("\n")}" end end @logger.debug(ENV) exec([:command]) if [:command] end |
#reencrypt_file ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/envault/cli.rb', line 49 def reencrypt_file yaml = YAML.load_file([:source]) from = Core.new( config: @class_options[:config], profile: [:from_profile], prefix: @class_options[:prefix], debug: @class_options[:debug] ) cipher_keys = from.get_cipher_keys(yaml).map{ |cipher_key| cipher_key.gsub(/^#{from.prefix}/, '') } decrypted = from.decrypt_yaml([:source]) to = Core.new( config: @class_options[:config], profile: [:to_profile], prefix: @class_options[:prefix], debug: @class_options[:debug] ) output = to.encrypt_process(decrypted, cipher_keys) if [:overwrite] Formatter.write_escape_yaml([:source], output, [:quote]) else puts Formatter.escape_yaml(output, [:quote]) end end |