Sha256: 97ff46beeca26c4462fd7bf084ec44a605f7173347ae9e8ccb24e6e8f8334d52

Contents?: true

Size: 1.22 KB

Versions: 15

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require 'rake_factory'
require 'sshkey'

module RakeSSH
  module Tasks
    module Key
      class Generate < RakeFactory::Task
        default_name :generate
        default_description(RakeFactory::DynamicValue.new do |t|
          "Generates an SSH key pair in #{t.path}"
        end)

        parameter :path, required: true
        parameter :name_prefix, default: 'ssh'
        parameter :type, default: 'RSA'
        parameter :bits, default: 4096
        parameter :comment
        parameter :passphrase

        action do |t|
          $stdout.print(
            "Generating SSH key '#{t.name_prefix}' in '#{t.path}'..."
          )
          key = SSHKey.generate(
            type: t.type,
            bits: t.bits,
            comment: t.comment,
            passphrase: t.passphrase
          )
          verbose(false) do
            mkdir_p(t.path)
          end
          File.open("#{t.path}/#{t.name_prefix}.private", 'w') do |f|
            f.write(key.private_key)
          end
          File.open("#{t.path}/#{t.name_prefix}.public", 'w') do |f|
            f.write(key.ssh_public_key)
          end
          puts 'Done.'

          $stdout.puts 'Done.'
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rake_ssh-0.13.0.pre.2 lib/rake_ssh/tasks/key/generate.rb
rake_ssh-0.13.0.pre.1 lib/rake_ssh/tasks/key/generate.rb
rake_ssh-0.12.0 lib/rake_ssh/tasks/key/generate.rb
rake_ssh-0.11.0.pre.5 lib/rake_ssh/tasks/key/generate.rb
rake_ssh-0.11.0.pre.4 lib/rake_ssh/tasks/key/generate.rb
rake_ssh-0.11.0.pre.3 lib/rake_ssh/tasks/key/generate.rb
rake_ssh-0.11.0.pre.2 lib/rake_ssh/tasks/key/generate.rb
rake_ssh-0.11.0.pre.1 lib/rake_ssh/tasks/key/generate.rb
rake_ssh-0.10.0 lib/rake_ssh/tasks/key/generate.rb
rake_ssh-0.9.0.pre.2 lib/rake_ssh/tasks/key/generate.rb
rake_ssh-0.9.0.pre.1 lib/rake_ssh/tasks/key/generate.rb
rake_ssh-0.8.0 lib/rake_ssh/tasks/key/generate.rb
rake_ssh-0.7.0.pre.9 lib/rake_ssh/tasks/key/generate.rb
rake_ssh-0.7.0.pre.8 lib/rake_ssh/tasks/key/generate.rb
rake_ssh-0.7.0.pre.7 lib/rake_ssh/tasks/key/generate.rb