class Cyoi::Cli::KeyPair::KeyPairCliAws

Attributes

attributes[R]
hl[R]
provider_client[R]

Public Class Methods

new(provider_client, attributes, highline) click to toggle source
# File lib/cyoi/cli/provider_key_pair/key_pair_aws.rb, line 7
def initialize(provider_client, attributes, highline)
  @provider_client = provider_client
  @hl = highline
  @attributes = attributes.is_a?(Hash) ? ReadWriteSettings.new(attributes) : attributes
  raise "@attributes must be ReadWriteSettings (or Hash)" unless @attributes.is_a?(ReadWriteSettings)
  raise "@attributes.name must be set" unless @attributes["name"]
end

Public Instance Methods

display_confirmation() click to toggle source
# File lib/cyoi/cli/provider_key_pair/key_pair_aws.rb, line 33
def display_confirmation
  puts "\n"
  puts "Confirming: Using key pair #{key_pair_name}"
end
export_attributes() click to toggle source

helper to export the complete nested attributes.

# File lib/cyoi/cli/provider_key_pair/key_pair_aws.rb, line 24
def export_attributes
  attributes.to_nested_hash
end
key_pair_name() click to toggle source
# File lib/cyoi/cli/provider_key_pair/key_pair_aws.rb, line 38
def key_pair_name
  attributes.name
end
perform_and_return_attributes() click to toggle source
# File lib/cyoi/cli/provider_key_pair/key_pair_aws.rb, line 15
def perform_and_return_attributes
  unless valid?
    destroy_existing_key_pair
    provision_key_pair
  end
  export_attributes
end
valid?() click to toggle source
# File lib/cyoi/cli/provider_key_pair/key_pair_aws.rb, line 28
def valid?
  attributes["name"] && attributes["fingerprint"] && attributes["private_key"] &&
    provider_client.valid_key_pair_fingerprint?(key_pair_name, attributes.fingerprint)
end

Protected Instance Methods

destroy_existing_key_pair() click to toggle source
# File lib/cyoi/cli/provider_key_pair/key_pair_aws.rb, line 43
def destroy_existing_key_pair
  provider_client.delete_key_pair_if_exists(key_pair_name)
end
provision_key_pair() click to toggle source

provisions key pair from AWS and returns fog object KeyPair

# File lib/cyoi/cli/provider_key_pair/key_pair_aws.rb, line 48
def provision_key_pair
  if key_pair = provider_client.create_key_pair(key_pair_name)
    attributes["fingerprint"] = key_pair.fingerprint
    attributes["private_key"] = key_pair.private_key
  end
end