Module: Kitchen::Driver::Oci::Mixin::SshKeys

Included in:
Instance
Defined in:
lib/kitchen/driver/oci/mixin/ssh_keys.rb

Overview

SSH key generation mixins.

Author:

  • Justin Steele <justin.steele@oracle.com>

Defined Under Namespace

Modules: ED25519, RSA

Instance Method Summary collapse

Instance Method Details

#algorithmString

Algorithm used when encoding the private and public keys.

Returns:

  • (String)


60
61
62
# File 'lib/kitchen/driver/oci/mixin/ssh_keys.rb', line 60

def algorithm
  "ssh-#{config[:ssh_keytype]}"
end

#generate_keysObject

Generates the public/private key pair in the format specified in the config.



65
66
67
68
69
# File 'lib/kitchen/driver/oci/mixin/ssh_keys.rb', line 65

def generate_keys
  FileUtils.mkdir_p("#{config[:kitchen_root]}/.kitchen/.ssh")
  extend SshKeys.const_get(config[:ssh_keytype].upcase)
  generate_key_pair
end

#private_key_fileString

The location of the private ssh key.

Returns:

  • (String)


42
43
44
# File 'lib/kitchen/driver/oci/mixin/ssh_keys.rb', line 42

def private_key_file
  public_key_file.gsub(".pub", "")
end

#public_key_fileString

The location of the public ssh key.

Returns:

  • (String)


49
50
51
52
53
54
55
# File 'lib/kitchen/driver/oci/mixin/ssh_keys.rb', line 49

def public_key_file
  if config[:ssh_keygen]
    "#{config[:kitchen_root]}/.kitchen/.ssh/#{config[:instance_name]}_#{config[:ssh_keytype]}.pub"
  else
    config[:ssh_keypath]
  end
end

#read_public_keyString

Read in the public ssh key.

Returns:

  • (String)


31
32
33
34
35
36
37
# File 'lib/kitchen/driver/oci/mixin/ssh_keys.rb', line 31

def read_public_key
  if config[:ssh_keygen]
    logger.info("Generating public/private #{config[:ssh_keytype]} key pair")
    generate_keys
  end
  File.readlines(public_key_file).first.chomp
end