Skip to content
This repository has been archived by the owner on Jan 20, 2019. It is now read-only.

Commit

Permalink
added AWS::EC2::Base#get_password_data for GetPasswordData API
Browse files Browse the repository at this point in the history
  • Loading branch information
juno authored and grempe committed Nov 21, 2010
1 parent caf8a72 commit 9fbaada
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/AWS/EC2/password.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module AWS
module EC2
class Base < AWS::Base


# The GetPasswordData operation retrieves the encrypted administrator password for the instances running Window.
#
# @option options [String] :instance_id ("") an Instance ID
#
def get_password_data( options = {} )
options = {:instance_id => ""}.merge(options)
raise ArgumentError, "No instance ID provided" if options[:instance_id].nil? || options[:instance_id].empty?
params = { "InstanceId" => options[:instance_id] }
return response_generator(:action => "GetPasswordData", :params => params)
end


end
end
end
45 changes: 45 additions & 0 deletions test/test_EC2_password.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#--
# Amazon Web Services EC2 Query API Ruby library
#
# Ruby Gem Name:: amazon-ec2
# Author:: Glenn Rempe (mailto:glenn@rempe.us)
# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
# License:: Distributes under the same terms as Ruby
# Home:: http://github.com/grempe/amazon-ec2/tree/master
#++

require File.dirname(__FILE__) + '/test_helper.rb'

context "The EC2 password " do

before do
@ec2 = AWS::EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )

@get_password_data_response_body = <<-RESPONSE
<GetPasswordDataResponse xmlns="http://ec2.amazonaws.com/doc/2010-06-15/">
<instanceId>i-2574e22a</instanceId>
<timestamp>2009-10-24 15:00:00</timestamp>
<passwordData>TGludXggdmVyc2lvbiAyLjYuMTYteGVuVSAoYnVpbGRlckBwYXRjaGJhdC5hbWF6b25zYSkgKGdj</passwordData></GetPasswordDataResponse>
RESPONSE

end


specify "should return an encrypted password encoded by base64 " do
@ec2.stubs(:make_request).with('GetPasswordData', {"InstanceId"=>"i-2574e22a"}).
returns stub(:body => @get_password_data_response_body, :is_a? => true)
@ec2.get_password_data( :instance_id => "i-2574e22a" ).should.be.an.instance_of Hash
response = @ec2.get_password_data( :instance_id => "i-2574e22a" )
response.instanceId.should.equal "i-2574e22a"
response.timestamp.should.equal "2009-10-24 15:00:00"
end


specify "method get_password_data should raise an exception when called without nil/empty string arguments" do
lambda { @ec2.get_password_data() }.should.raise(AWS::ArgumentError)
lambda { @ec2.get_password_data(:instance_id => nil) }.should.raise(AWS::ArgumentError)
lambda { @ec2.get_password_data(:instance_id => "") }.should.raise(AWS::ArgumentError)
end


end

0 comments on commit 9fbaada

Please sign in to comment.