Sha256: 16f797cf30783a0b55985e24f29f3d159e47bc075636b57b4e34a6fe7001d188

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

require 'rake_factory'
require 'ruby_gpg2'

module RakeGPG
  module Tasks
    module Keys
      class Import < RakeFactory::Task
        default_name :import
        default_description "Import a GPG key"

        parameter :key_file_path, required: true
        parameter :work_directory, default: 'build/gpg'
        parameter :home_directory, default: :temporary

        action do |t|
          mkdir_p(t.work_directory)
          if t.home_directory == :temporary
            Dir.mktmpdir(
                'home', t.work_directory) do |home_directory|
              do_import_key(t, home_directory)
            end
          else
            do_import_key(t, t.home_directory)
          end

        end

        private

        def do_import_key(t, home_directory)
          puts "Importing GPG key from #{t.key_file_path} " +
              "into #{home_directory}..."
          RubyGPG2.import(
              key_file_paths: [t.key_file_path],
              home_directory: home_directory)
          puts "Done."
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rake_gpg-0.6.0 lib/rake_gpg/tasks/keys/import.rb
rake_gpg-0.5.0.pre.1 lib/rake_gpg/tasks/keys/import.rb