Class: Key

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

Overview

Copyright © 2009, 2010 Red Hat, Inc.

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_hash, #to_json

Constructor Details

This class inherits a constructor from BaseModel

Instance Attribute Details

#credential_typeObject

Returns the value of attribute credential_type.



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

def credential_type
  @credential_type
end

#fingerprintObject

Returns the value of attribute fingerprint.



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

def fingerprint
  @fingerprint
end

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#pem_rsa_keyObject

Returns the value of attribute pem_rsa_key.



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

def pem_rsa_key
  @pem_rsa_key
end

#stateObject

Returns the value of attribute state.



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

def state
  @state
end

#usernameObject

Returns the value of attribute username.



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

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



38
39
40
# File 'lib/deltacloud/models/key.rb', line 38

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



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

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)


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

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

#is_password?Boolean

Returns:

  • (Boolean)


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

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