Module: Idlc::Deploy::Keypair

Defined in:
lib/idlc-sdk-deploy/keypair.rb

Class Method Summary collapse

Class Method Details

.generate(outdir) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/idlc-sdk-deploy/keypair.rb', line 5

def generate(outdir)
  raise ArgumentError, 'Must specify output directory' if outdir.nil?

  FileUtils.mkdir_p outdir unless File.directory? outdir

  private_key_file = "#{outdir}/private_key.pem"
  public_key_file = "#{outdir}/public_key.pem"

  return if File.exist? private_key_file

  rsa_key = SSHKey.generate
  private_key = rsa_key.private_key
  public_key = rsa_key.ssh_public_key

  File.open(private_key_file, 'w') { |file| file.write(private_key) }
  File.open(public_key_file, 'w') { |file| file.write(public_key) }
end