Sha256: d02b622447d152dead4c20a8a07387657806e016d1f7a4c2d8bb94801b5f050b

Contents?: true

Size: 1.5 KB

Versions: 13

Compression:

Stored size: 1.5 KB

Contents

require 'rake_factory'
require 'ruby_gpg2'

require_relative '../../home'

module RakeGPG
  module Tasks
    module Encryption
      class Decrypt < RakeFactory::Task
        default_name :decrypt
        default_description "Decrypt a file using GPG"

        parameter :key_file_path, required: true
        parameter :input_file_path, required: true
        parameter :output_file_path, required: true

        parameter :work_directory, default: '/tmp'
        parameter :home_directory, default: :temporary

        parameter :trust_mode, default: :always
        parameter :passphrase

        action do |t|
          mkdir_p(t.work_directory)

          puts "Decrypting #{t.input_file_path} with key #{t.key_file_path}..."
          Home.new(t.work_directory, t.home_directory)
              .with_resolved_directory do |home_directory|
            RubyGPG2.import(
                key_file_paths: [t.key_file_path],
                work_directory: t.work_directory,
                home_directory: home_directory)

            mkdir_p(File.dirname(t.output_file_path))

            RubyGPG2.decrypt(
                input_file_path: t.input_file_path,
                output_file_path: t.output_file_path,
                home_directory: home_directory,
                trust_mode: t.trust_mode,
                passphrase: t.passphrase,
                pinentry_mode: t.passphrase ? :loopback : nil,
                without_passphrase: !t.passphrase)
          end
          puts "Done."
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rake_gpg-0.17.0.pre.4 lib/rake_gpg/tasks/encryption/decrypt.rb
rake_gpg-0.17.0.pre.3 lib/rake_gpg/tasks/encryption/decrypt.rb
rake_gpg-0.17.0.pre.2 lib/rake_gpg/tasks/encryption/decrypt.rb
rake_gpg-0.17.0.pre.1 lib/rake_gpg/tasks/encryption/decrypt.rb
rake_gpg-0.16.0 lib/rake_gpg/tasks/encryption/decrypt.rb
rake_gpg-0.15.0.pre.1 lib/rake_gpg/tasks/encryption/decrypt.rb
rake_gpg-0.14.0 lib/rake_gpg/tasks/encryption/decrypt.rb
rake_gpg-0.13.0.pre.1 lib/rake_gpg/tasks/encryption/decrypt.rb
rake_gpg-0.12.0 lib/rake_gpg/tasks/encryption/decrypt.rb
rake_gpg-0.11.0.pre.2 lib/rake_gpg/tasks/encryption/decrypt.rb
rake_gpg-0.11.0.pre.1 lib/rake_gpg/tasks/encryption/decrypt.rb
rake_gpg-0.10.0 lib/rake_gpg/tasks/encryption/decrypt.rb
rake_gpg-0.9.0.pre.1 lib/rake_gpg/tasks/encryption/decrypt.rb