Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added AWS::EC2::Base#get_password_data for GetPasswordData API

  • Loading branch information...
commit 9fbaadafa89465d7af63d6021ac57fa1a41288f0 1 parent caf8a72
@juno juno authored committed
Showing with 65 additions and 0 deletions.
  1. +20 −0 lib/AWS/EC2/password.rb
  2. +45 −0 test/test_EC2_password.rb
View
20 lib/AWS/EC2/password.rb
@@ -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
View
45 test/test_EC2_password.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.