1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Pass params necessary to upload key pairs.

The original implementation did not pass the required attributes to upload
an existing key pair up to the API. This commit addresses that problem
while maintaining backwards compatibility. The 2nd argument was changed
from a string to a hash, a deprecation warning is generated.
This commit is contained in:
Joshua Schairbaum 2014-01-07 16:26:36 -06:00
parent 2560ac10a5
commit c55f5e2158

View file

@ -18,11 +18,18 @@ module Fog
# @raise [Fog::Compute::RackspaceV2::InternalServerError]
# @raise [Fog::Compute::RackspaceV2::ServiceError]
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/CreateKeyPair.html
def create_keypair(key_name, public_key=nil)
def create_keypair(key_name, attributes = nil)
key_data = { 'name' => key_name }
if attributes.is_a?(String)
Fog::Logger.deprecation "Passing the public key as the 2nd arg is deprecated, please pass a hash of attributes."
key_data.merge!("public_key" => attributes)
end
key_data.merge!(attributes) unless attributes.nil?
data = {
'keypair' => {
'name' => key_name
}
'keypair' => key_data
}
request(
@ -35,10 +42,14 @@ module Fog
end
class Mock
def create_keypair(key_name, public_key=nil)
def create_keypair(key_name, attributes = nil)
# 409 response when already existing
raise Fog::Compute::RackspaceV2::ServiceError if not self.data[:keypairs].select { |k| key_name.include? k['keypair']['name'] }.first.nil?
if attributes.is_a?(String)
Fog::Logger.deprecation "Passing the public key as the 2nd arg is deprecated, please pass a hash of attributes."
end
k = self.data[:keypair]
k['name'] = key_name
self.data[:keypairs] << { 'keypair' => k }