Class: Key

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

Overview

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Instance Attribute Summary collapse

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 BaseModel

Instance Attribute Details

#credential_typeObject

Returns the value of attribute credential_type.



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

def credential_type
  @credential_type
end

#fingerprintObject

Returns the value of attribute fingerprint.



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

def fingerprint
  @fingerprint
end

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#pem_rsa_keyObject

Returns the value of attribute pem_rsa_key.



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

def pem_rsa_key
  @pem_rsa_key
end

#stateObject

Returns the value of attribute state.



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

def state
  @state
end

#usernameObject

Returns the value of attribute username.



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

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



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

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



46
47
48
49
50
51
52
# File 'lib/deltacloud/models/key.rb', line 46

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)


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

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

#is_password?Boolean

Returns:

  • (Boolean)


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

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

#nameObject



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

def name
  @name || @id
end

#to_hash(context) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/deltacloud/models/key.rb', line 54

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