mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[ibm] Fix key model for passing public_key, add setting/testing whether key is default
This commit is contained in:
parent
aad19e2ca4
commit
23f3bcaf2e
3 changed files with 26 additions and 10 deletions
|
@ -7,13 +7,14 @@ module Fog
|
||||||
identity :name, :aliases => 'keyName'
|
identity :name, :aliases => 'keyName'
|
||||||
attribute :default
|
attribute :default
|
||||||
attribute :public_key, :aliases => 'keyMaterial'
|
attribute :public_key, :aliases => 'keyMaterial'
|
||||||
attribute :last_modified, :aliases => 'lastModifiedTime'
|
attribute :instance_ids, :aliases => 'instanceIds'
|
||||||
|
attribute :modified_at, :aliases => 'lastModifiedTime'
|
||||||
|
|
||||||
def save
|
def save
|
||||||
requires :name, :public_key
|
requires :name
|
||||||
data = connection.create_key(name, public_key)
|
data = connection.create_key(name, public_key)
|
||||||
merge_attributes(data.body)
|
merge_attributes(data.body)
|
||||||
data.body['success']
|
data.body['keyName'] == name
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
@ -21,6 +22,13 @@ module Fog
|
||||||
data.body['success']
|
data.body['success']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def default?
|
||||||
|
default
|
||||||
|
end
|
||||||
|
|
||||||
|
def instances
|
||||||
|
instance_ids.map { Fog::Compute[:ibm].servers.get(instance_id) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,6 +21,14 @@ module Fog
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def default
|
||||||
|
find {|key| key.default? }
|
||||||
|
end
|
||||||
|
|
||||||
|
def default=(key_name)
|
||||||
|
connection.modify_key(key_name, 'default' => true)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,14 +44,14 @@ module Fog
|
||||||
"instanceIds" => [],
|
"instanceIds" => [],
|
||||||
}
|
}
|
||||||
if public_key.nil?
|
if public_key.nil?
|
||||||
private_key = Fog::IBM::Mock.key_material
|
private_key = Fog::IBM::Mock.key_material
|
||||||
public_key = private_key.public_key
|
public_key = private_key.public_key
|
||||||
public_key = { "keyMaterial" => public_key.to_s }.merge(attributes.dup)
|
|
||||||
self.data[:keys][name] = public_key
|
|
||||||
private_key = { "keyMaterial" => private_key.to_s }.merge(attributes.dup)
|
|
||||||
self.data[:private_keys][name] = private_key
|
|
||||||
response.body = private_key
|
|
||||||
end
|
end
|
||||||
|
public_key = { "keyMaterial" => public_key.to_s }.merge(attributes.dup)
|
||||||
|
private_key = { "keyMaterial" => private_key.to_s }.merge(attributes.dup)
|
||||||
|
response.body = private_key
|
||||||
|
self.data[:keys][name] = public_key
|
||||||
|
self.data[:private_keys][name] = private_key
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue