Sha256: 6aad65c44dbfc67aaea442030cfe438a8b5642ed0d93493b079526b82a98fd7b
Contents?: true
Size: 1.19 KB
Versions: 14
Compression:
Stored size: 1.19 KB
Contents
require 'tempfile' module Heirloom module Cipher class Data include Heirloom::Cipher::Shared def initialize(args) @config = args[:config] @logger = @config.logger end def decrypt_data(args) @data = args[:data] @secret = args[:secret] return @data unless args[:secret] return false unless gpg_in_path? @encrypted_file = Tempfile.new('archive.tar.gz.gpg') @decrypted_file = Tempfile.new('archive.tar.gz') ::File.open(@encrypted_file, 'w') { |f| f.write @data } decrypt end private def decrypt @logger.info "Secret provided. Decrypting with: '#{command}'" output = `#{command(@secret)}` @logger.debug "Decryption output: '#{output}'" if $?.success? @decrypted_file.read else @logger.error "Decryption failed with output: '#{output}'" false end end def command(secret='XXXXXXXX') "gpg --batch --yes --cipher-algo AES256 --passphrase #{secret} --output #{@decrypted_file.path} #{@encrypted_file.path} 2>&1" end def logger @logger end end end end
Version data entries
14 entries across 14 versions & 1 rubygems