Sha256: cf4f79db7c14a77a6b7cae2c5646cc7b983f1b7e2161586a75c3054c6345df4b

Contents?: true

Size: 1.33 KB

Versions: 8

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

require 'rake_factory'
require 'ruby_gpg2'

require_relative '../../home'

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: '/tmp'
        parameter :home_directory, default: :temporary

        action do
          make_work_directory
          log_importing_key
          in_home_directory do |home_directory|
            import(home_directory)
          end
          log_done
        end

        private

        def in_home_directory(&block)
          Home.new(work_directory, home_directory)
              .with_resolved_directory do |home_directory|
            block.call(home_directory)
          end
        end

        def make_work_directory
          mkdir_p(work_directory)
        end

        def import(home_directory)
          RubyGPG2.import(
            key_file_paths: [key_file_path],
            home_directory: home_directory
          )
        end

        def log_importing_key
          $stdout.puts(
            "Importing GPG key from #{key_file_path} into #{home_directory}..."
          )
        end

        def log_done
          $stdout.puts 'Done.'
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rake_gpg-0.19.0.pre.4 lib/rake_gpg/tasks/keys/import.rb
rake_gpg-0.19.0.pre.3 lib/rake_gpg/tasks/keys/import.rb
rake_gpg-0.19.0.pre.2 lib/rake_gpg/tasks/keys/import.rb
rake_gpg-0.19.0.pre.1 lib/rake_gpg/tasks/keys/import.rb
rake_gpg-0.18.0 lib/rake_gpg/tasks/keys/import.rb
rake_gpg-0.17.0.pre.7 lib/rake_gpg/tasks/keys/import.rb
rake_gpg-0.17.0.pre.6 lib/rake_gpg/tasks/keys/import.rb
rake_gpg-0.17.0.pre.5 lib/rake_gpg/tasks/keys/import.rb