class Envault::CLI
Public Class Methods
new(args = [], options = {}, config = {})
click to toggle source
Calls superclass method
# File lib/envault/cli.rb, line 16 def initialize(args = [], options = {}, config = {}) super(args, options, config) @class_options = config[:shell].base.options 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
Public Instance Methods
decrypt()
click to toggle source
# File lib/envault/cli.rb, line 39 def decrypt puts @core.cryptor.decrypt(options[:source]) end
decrypt_file()
click to toggle source
# File lib/envault/cli.rb, line 99 def decrypt_file result = {} options[:plain_text].each do |plain_text_path| result = result.merge(YAML.load(ERB.new(File.read(plain_text_path)).result)) end options[:source].each do |encrypt_yaml_path| result = result.merge(@core.decrypt_yaml(encrypt_yaml_path)) end if options[:output] Formatter.write_escape_yaml(options[:output], result, options[:quote]) else puts Formatter.escape_yaml(result, options[:quote]) end end
encrypt()
click to toggle source
# File lib/envault/cli.rb, line 33 def encrypt puts @core.cryptor.encrypt(options[:source]) end
encrypt_file()
click to toggle source
# File lib/envault/cli.rb, line 79 def encrypt_file result = {} options[:plain_text].each do |plain_text_path| result = result.merge(YAML.load(ERB.new(File.read(plain_text_path)).result)) end options[:source].each do |secret_yaml_path| result = result.merge(@core.encrypt_yaml(secret_yaml_path, options[:keys])) end if options[:output] Formatter.write_escape_yaml(options[:output], result, options[:quote]) else puts Formatter.escape_yaml(result, options[:quote]) end end
load()
click to toggle source
# File lib/envault/cli.rb, line 117 def load options[:sources].each do |source| begin @core.load(source) rescue => e raise "error => [#{source}]\n#{e.message}\n#{e.backtrace.join("\n")}" end end @logger.debug(ENV) exec(options[:command]) if options[:command] end
reencrypt_file()
click to toggle source
# File lib/envault/cli.rb, line 49 def reencrypt_file yaml = YAML.load_file(options[:source]) from = Core.new( config: @class_options[:config], profile: options[: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(options[:source]) to = Core.new( config: @class_options[:config], profile: options[:to_profile], prefix: @class_options[:prefix], debug: @class_options[:debug] ) output = to.encrypt_process(decrypted, cipher_keys) if options[:overwrite] Formatter.write_escape_yaml(options[:source], output, options[:quote]) else puts Formatter.escape_yaml(output, options[:quote]) end end