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

first pass for create/delete key pairs

This commit is contained in:
Wesley Beary 2009-07-06 09:21:21 -07:00
parent d3721ef0bc
commit b6f88cb511
4 changed files with 84 additions and 0 deletions

View file

@ -48,6 +48,25 @@ module Fog
}, Fog::Parsers::AWS::EC2::AllocateAddress.new)
end
# Create a new key pair
#
# ==== Parameters
# :key_name<~String>:: Unique name for key pair.
#
# ==== Returns
# response::
# body<~Hash>::
# :key_name<~String>:: Name of key
# :key_fingerprint<~String>:: SHA-1 digest of DER encoded private key
# :key_material<~String>:: Unencrypted encoded PEM private key
# :request_id<~String>:: Id of request
def create_key_pair(key_name)
request({
'Action' => 'CreateKeyPair',
'KeyName' => key_name
}, Fog::Parsers::AWS::EC2::CreateKeyPair.new)
end
# Create a new security group
#
# ==== Parameters
@ -91,6 +110,22 @@ module Fog
}, Fog::Parsers::AWS::EC2::CreateVolume.new)
end
# Delete a key pair that you own
#
# ==== Parameters
# :key_name<~String>:: Name of the key pair.
#
# ==== Returns
# response::
# body<~Hash>::
# :return<~Boolean>:: success?
def delete_key_pair(key_name)
request({
'Action' => 'DeleteKeyPair',
'KeyName' => key_name
}, Fog::Parsers::AWS::EC2::Basic.new)
end
# Delete a security group that you own
#
# ==== Parameters

View file

@ -35,6 +35,23 @@ module Fog
end
class CreateKeyPair < Fog::Parsers::Base
def end_element(name)
case name
when 'keyFingerprint'
@response[:key_fingerprint] = @value
when 'keyMaterial'
@response[:key_material] = @value
when 'keyName'
@response[:key_name] = @value
when 'requestId'
@response[:request_id]
end
end
end
class CreateVolume < Fog::Parsers::Base
def end_element(name)

View file

@ -0,0 +1,17 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe 'EC2.create_key_pair' do
after(:all) do
ec2.delete_key_pair('fog_key_pair')
end
it "should return proper attributes" do
actual = ec2.create_key_pair('fog_key_pair')
actual.body[:key_fingerprint].should be_a(String)
actual.body[:key_material].should be_a(String)
actual.body[:key_name].should be_a(String)
actual.body[:request_id].should be_a(String)
end
end

View file

@ -0,0 +1,15 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe 'EC2.delete_key_pair' do
before(:all) do
ec2.create_key_pair('fog_key_pair')
end
it "should return proper attributes" do
actual = ec2.delete_key_pair('fog_key_pair')
actual.body[:request_id].should be_a(String)
[false, true].should include(actual.body[:return])
end
end