amazon-ec2 0.3.6 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.3.8 2009-04-16
2
+ * Applied patch, with updated tests to fix issue with base64 encoded user data (rsanheim).
3
+ * Applied patch, fixing an issue with EU Signature version 2 creation (delano).
4
+
1
5
  === 0.3.6 2009-03-02
2
6
  * You can now specify any arbitrary SSL tcp port to connect to (kerryb)
3
7
  * Added rake target to quickly install the gem without docs
data/Rakefile CHANGED
@@ -33,3 +33,5 @@ Rake::RDocTask.new do |rd|
33
33
  rd.rdoc_dir = 'doc'
34
34
  rd.options = spec.rdoc_options
35
35
  end
36
+
37
+ task :default => :test
data/lib/EC2.rb CHANGED
@@ -182,7 +182,7 @@ module EC2
182
182
  "Version" => API_VERSION,
183
183
  "Timestamp"=>Time.now.getutc.iso8601} )
184
184
 
185
- sig = get_aws_auth_param(params, @secret_access_key)
185
+ sig = get_aws_auth_param(params, @secret_access_key, @server)
186
186
 
187
187
  query = params.sort.collect do |param|
188
188
  CGI::escape(param[0]) + "=" + CGI::escape(param[1])
@@ -205,8 +205,8 @@ module EC2
205
205
  end
206
206
 
207
207
  # Set the Authorization header using AWS signed header authentication
208
- def get_aws_auth_param(params, secret_access_key)
209
- canonical_string = EC2.canonical_string(params)
208
+ def get_aws_auth_param(params, secret_access_key, server)
209
+ canonical_string = EC2.canonical_string(params, server)
210
210
  encoded_canonical = EC2.encode(secret_access_key, canonical_string)
211
211
  end
212
212
 
@@ -90,18 +90,7 @@ module EC2
90
90
  raise ArgumentError, ":instance_type must be 'm1.small', 'm1.large', 'm1.xlarge', 'c1.medium', or 'c1.xlarge'" unless options[:instance_type] == "m1.small" || options[:instance_type] == "m1.large" || options[:instance_type] == "m1.xlarge" || options[:instance_type] == "c1.medium" || options[:instance_type] == "c1.xlarge"
91
91
  raise ArgumentError, ":base64_encoded must be 'true' or 'false'" unless options[:base64_encoded] == true || options[:base64_encoded] == false
92
92
 
93
- # If :user_data is passed in then URL escape and Base64 encode it
94
- # as needed. Need for URL Escape + Base64 encoding is determined
95
- # by :base64_encoded param.
96
- if options[:user_data]
97
- if options[:base64_encoded]
98
- user_data = options[:user_data]
99
- else
100
- user_data = Base64.encode64(options[:user_data]).gsub(/\n/,"").strip()
101
- end
102
- else
103
- user_data = nil
104
- end
93
+ user_data = extract_user_data(options)
105
94
 
106
95
  params = {
107
96
  "ImageId" => options[:image_id],
@@ -119,6 +108,20 @@ module EC2
119
108
  return response_generator(:action => "RunInstances", :params => params)
120
109
 
121
110
  end
111
+
112
+ # If :user_data is passed in then URL escape and Base64 encode it
113
+ # as needed. Need for URL Escape + Base64 encoding is determined
114
+ # by :base64_encoded param.
115
+ def extract_user_data(options)
116
+ return unless options[:user_data]
117
+ if options[:user_data]
118
+ if options[:base64_encoded]
119
+ Base64.encode64(options[:user_data]).gsub(/\n/,"").strip()
120
+ else
121
+ options[:user_data]
122
+ end
123
+ end
124
+ end
122
125
 
123
126
 
124
127
  #Amazon Developer Guide Docs:
@@ -221,28 +221,40 @@ context "EC2 instances " do
221
221
 
222
222
 
223
223
  specify "should be able specify an availability_zone" do
224
- @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "Placement.AvailabilityZone" => "zone123", "UserData" => "foo", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
224
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "Placement.AvailabilityZone" => "zone123", "UserData" => "Zm9v", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
225
225
  returns stub(:body => @run_instances_response_body, :is_a? => true)
226
226
  @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :availability_zone => "zone123", :group_id => [], :user_data => "foo", :base64_encoded => true ).should.be.an.instance_of Hash
227
227
  end
228
228
 
229
229
  specify "should be able to call run_instances with :user_data and :base64_encoded => true (default is false)" do
230
- @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "foo", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
230
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "Zm9v", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
231
231
  returns stub(:body => @run_instances_response_body, :is_a? => true)
232
232
  @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :group_id => [], :user_data => "foo", :base64_encoded => true ).should.be.an.instance_of Hash
233
233
  end
234
234
 
235
235
  specify "should be able specify an kernel_id" do
236
- @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "Placement.AvailabilityZone" => "zone123", "UserData" => "foo", "AddressingType" => 'public', 'InstanceType' => 'm1.small', 'KernelId' => 'kernfoo').
236
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "Placement.AvailabilityZone" => "zone123", "UserData" => "Zm9v", "AddressingType" => 'public', 'InstanceType' => 'm1.small', 'KernelId' => 'kernfoo').
237
237
  returns stub(:body => @run_instances_response_body, :is_a? => true)
238
238
  @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :availability_zone => "zone123", :group_id => [], :user_data => "foo", :base64_encoded => true, :kernel_id => 'kernfoo' ).should.be.an.instance_of Hash
239
239
  end
240
240
 
241
241
  specify "should be able to call run_instances with :user_data and :base64_encoded => false" do
242
- @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "Zm9v", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
242
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "foo", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
243
243
  returns stub(:body => @run_instances_response_body, :is_a? => true)
244
244
  @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :group_id => [], :user_data => "foo", :base64_encoded => false ).should.be.an.instance_of Hash
245
245
  end
246
+
247
+ specify "should get no user data for when options has no user_data key" do
248
+ @ec2.extract_user_data({}).should == nil
249
+ end
250
+
251
+ specify "should get plain string user data when options has user_data and no base64 key" do
252
+ @ec2.extract_user_data({:user_data => "foo\nbar"}).should == "foo\nbar"
253
+ end
254
+
255
+ specify "should strip new lines and base64 encode when options has both user_data and base64" do
256
+ @ec2.extract_user_data({:user_data => "binary\ndata\nhere\n", :base64_encoded => true}).should == "YmluYXJ5CmRhdGEKaGVyZQo="
257
+ end
246
258
 
247
259
 
248
260
  specify "should be able to be described and return the correct Ruby response class" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amazon-ec2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glenn Rempe
@@ -9,7 +9,7 @@ autorequire: EC2
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-02 00:00:00 -08:00
12
+ date: 2009-04-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency