Class: Deltacloud::Key

Inherits:
BaseModel show all
Defined in:
lib/deltacloud/models/key.rb

Instance Attribute Summary collapse

Attributes inherited from BaseModel

#description

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

attr_accessor, attributes, #attributes, #id, #initialize, #to_entity

Constructor Details

This class inherits a constructor from Deltacloud::BaseModel

Instance Attribute Details

#credential_typeObject

Returns the value of attribute credential_type.



20
21
22
# File 'lib/deltacloud/models/key.rb', line 20

def credential_type
  @credential_type
end

#fingerprintObject

Returns the value of attribute fingerprint.



21
22
23
# File 'lib/deltacloud/models/key.rb', line 21

def fingerprint
  @fingerprint
end

#passwordObject

Returns the value of attribute password.



23
24
25
# File 'lib/deltacloud/models/key.rb', line 23

def password
  @password
end

#pem_rsa_keyObject

Returns the value of attribute pem_rsa_key.



24
25
26
# File 'lib/deltacloud/models/key.rb', line 24

def pem_rsa_key
  @pem_rsa_key
end

#stateObject

Returns the value of attribute state.



25
26
27
# File 'lib/deltacloud/models/key.rb', line 25

def state
  @state
end

#usernameObject

Returns the value of attribute username.



22
23
24
# File 'lib/deltacloud/models/key.rb', line 22

def username
  @username
end

Class Method Details

.generate_mock_fingerprintObject

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



41
42
43
# File 'lib/deltacloud/models/key.rb', line 41

def self.generate_mock_fingerprint
  (0..19).map { "%02x" % (rand * 0xff) }.join(':')
end

.generate_mock_pemObject

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



47
48
49
50
51
52
53
# 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

Instance Method Details

#is_key?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/deltacloud/models/key.rb', line 35

def is_key?
  @credential_type.eql?(:key)
end

#is_password?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/deltacloud/models/key.rb', line 31

def is_password?
  @credential_type.eql?(:password)
end

#nameObject



27
28
29
# File 'lib/deltacloud/models/key.rb', line 27

def name
  super || @id
end

#to_hash(context) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 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