Sha256: a29ed77baa5bbfff95b0e202b2ecb88989d332160a209ce7527c781390760c8a

Contents?: true

Size: 977 Bytes

Versions: 3

Compression:

Stored size: 977 Bytes

Contents

module WebTranslateIt
  module Safe
    class Gpg < Pipe

      def active?
        raise RuntimeError, "can't use both gpg password and pubkey" if key && password

        !!(password || key)
      end

      protected

      def post_process
        @backup.compressed = true
      end

      def pipe
        command = config[:gpg, :command] || 'gpg'
        if key
          "|#{command} #{config[:gpg, :options]} -e -r #{key}"
        elsif password
          "|#{command} #{config[:gpg, :options]} -c --passphrase-file #{gpg_password_file(password)}"
        end
      end

      def extension
        '.gpg'
      end

      private

      def password
        @password ||= config[:gpg, :password]
      end

      def key
        @key ||= config[:gpg, :key]
      end

      def gpg_password_file(pass)
        return 'TEMP_GENERATED_FILENAME' if dry_run?
        WebTranslateIt::Safe::TmpFile.create('gpg-pass') { |file| file.write(pass) }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
webtranslateit-safe-0.4.3 lib/webtranslateit/safe/gpg.rb
webtranslateit-safe-0.4.2 lib/webtranslateit/safe/gpg.rb
webtranslateit-safe-0.4.1 lib/webtranslateit/safe/gpg.rb