class Deltacloud::Key

Attributes

credential_type[RW]
fingerprint[RW]
password[RW]
pem_rsa_key[RW]
state[RW]
username[RW]

Public Class Methods

generate_mock_fingerprint() click to toggle source

Mock fingerprint generator 1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f

# File lib/deltacloud/models/key.rb, line 41
def self.generate_mock_fingerprint
  (0..19).map { "%02x" % (rand * 0xff) }.join(':')
end
generate_mock_pem() click to toggle source

Mock PEM file NOTE: This is a fake PEM file, it will not work against SSH

# File lib/deltacloud/models/key.rb, line 47
def self.generate_mock_pem
  chars = (('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a + %w(= / + ))
  pem_material = (1..21).map do
    (1..75).collect{|a| chars[rand(chars.size)] }.join
  end.join("\n") + "\n" + (1..68).collect{|a| chars[rand(chars.size)] }.join
  "-----BEGIN RSA PRIVATE KEY-----\n"+pem_material+"-----END RSA PRIVATE KEY-----"
end

Public Instance Methods

is_key?() click to toggle source
# File lib/deltacloud/models/key.rb, line 35
def is_key?
  @credential_type.eql?(:key)
end
is_password?() click to toggle source
# File lib/deltacloud/models/key.rb, line 31
def is_password?
  @credential_type.eql?(:password)
end
name() click to toggle source
# File lib/deltacloud/models/key.rb, line 27
def name
  super || @id
end
to_hash(context) click to toggle source
# File lib/deltacloud/models/key.rb, line 55
def to_hash(context)
  r = {
    :id => self.id,
    :href => context.key_url(self.id),
    :credential_type => credential_type,
    :username => username,
    :password => password,
    :state => state
  }
  r[:pem_rsa_key] = pem_rsa_key if pem_rsa_key
  r[:fingerprint] = fingerprint if fingerprint
  r[:username] = username if username
  r[:password] = password if password
  r
end