Class: Deltacloud::Key
- Defined in:
- lib/deltacloud/models/key.rb
Instance Attribute Summary collapse
-
#credential_type ⇒ Object
Returns the value of attribute credential_type.
-
#fingerprint ⇒ Object
Returns the value of attribute fingerprint.
-
#password ⇒ Object
Returns the value of attribute password.
-
#pem_rsa_key ⇒ Object
Returns the value of attribute pem_rsa_key.
-
#state ⇒ Object
Returns the value of attribute state.
-
#username ⇒ Object
Returns the value of attribute username.
Attributes inherited from BaseModel
Class Method Summary collapse
-
.generate_mock_fingerprint ⇒ Object
Mock fingerprint generator 1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f.
-
.generate_mock_pem ⇒ Object
Mock PEM file NOTE: This is a fake PEM file, it will not work against SSH.
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_type ⇒ Object
Returns the value of attribute credential_type.
20 21 22 |
# File 'lib/deltacloud/models/key.rb', line 20 def credential_type @credential_type end |
#fingerprint ⇒ Object
Returns the value of attribute fingerprint.
21 22 23 |
# File 'lib/deltacloud/models/key.rb', line 21 def fingerprint @fingerprint end |
#password ⇒ Object
Returns the value of attribute password.
23 24 25 |
# File 'lib/deltacloud/models/key.rb', line 23 def password @password end |
#pem_rsa_key ⇒ Object
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 |
#state ⇒ Object
Returns the value of attribute state.
25 26 27 |
# File 'lib/deltacloud/models/key.rb', line 25 def state @state end |
#username ⇒ Object
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_fingerprint ⇒ Object
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_pem ⇒ Object
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
35 36 37 |
# File 'lib/deltacloud/models/key.rb', line 35 def is_key? @credential_type.eql?(:key) end |
#is_password? ⇒ Boolean
31 32 33 |
# File 'lib/deltacloud/models/key.rb', line 31 def is_password? @credential_type.eql?(:password) end |
#name ⇒ Object
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 |