kerryb-amazon-ec2 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/EC2.rb +9 -6
  2. data/test/test_EC2.rb +16 -5
  3. metadata +1 -1
data/lib/EC2.rb CHANGED
@@ -25,8 +25,8 @@ module EC2
25
25
  #
26
26
  if ENV['EC2_URL']
27
27
  EC2_URL = ENV['EC2_URL']
28
- VALID_HOSTS = ['https://ec2.amazonaws.com', 'https://us-east-1.ec2.amazonaws.com', 'https://eu-west-1.ec2.amazonaws.com']
29
- raise ArgumentError, "Invalid EC2_URL environment variable : #{EC2_URL}" unless VALID_HOSTS.include?(EC2_URL)
28
+ # VALID_HOSTS = ['https://ec2.amazonaws.com', 'https://us-east-1.ec2.amazonaws.com', 'https://eu-west-1.ec2.amazonaws.com']
29
+ # raise ArgumentError, "Invalid EC2_URL environment variable : #{EC2_URL}" unless VALID_HOSTS.include?(EC2_URL)
30
30
  DEFAULT_HOST = URI.parse(EC2_URL).host
31
31
  else
32
32
  # default US host
@@ -97,7 +97,7 @@ module EC2
97
97
  #
98
98
  class Base
99
99
 
100
- attr_reader :use_ssl, :server, :proxy_server, :port, :base_path
100
+ attr_reader :use_ssl, :server, :proxy_server, :port, :base_path, :http_method
101
101
 
102
102
  def initialize( options = {} )
103
103
 
@@ -106,13 +106,15 @@ module EC2
106
106
  :use_ssl => true,
107
107
  :server => DEFAULT_HOST,
108
108
  :proxy_server => nil,
109
- :base_path => '/'
109
+ :base_path => '/',
110
+ :http_method => 'POST'
110
111
  }.merge(options)
111
112
 
112
113
  @server = options[:server]
113
114
  @proxy_server = options[:proxy_server]
114
115
  @use_ssl = options[:use_ssl]
115
116
  @base_path = options[:base_path]
117
+ @http_method = options[:http_method]
116
118
 
117
119
  raise ArgumentError, "No :access_key_id provided" if options[:access_key_id].nil? || options[:access_key_id].empty?
118
120
  raise ArgumentError, "No :secret_access_key provided" if options[:secret_access_key].nil? || options[:secret_access_key].empty?
@@ -189,7 +191,8 @@ module EC2
189
191
  CGI::escape(param[0]) + "=" + CGI::escape(param[1])
190
192
  end.join("&") + "&Signature=" + sig
191
193
 
192
- req = Net::HTTP::Post.new(@base_path)
194
+ http_class = (@http_method == 'POST') ? Net::HTTP::Post : Net::HTTP::Get
195
+ req = http_class.new(@base_path)
193
196
  req.content_type = 'application/x-www-form-urlencoded'
194
197
  req['User-Agent'] = "github-amazon-ec2-ruby-gem"
195
198
 
@@ -207,7 +210,7 @@ module EC2
207
210
 
208
211
  # Set the Authorization header using AWS signed header authentication
209
212
  def get_aws_auth_param(params, secret_access_key)
210
- canonical_string = EC2.canonical_string(params, @server, 'GET', @base_path)
213
+ canonical_string = EC2.canonical_string(params, @server, @http_method, @base_path)
211
214
  encoded_canonical = EC2.encode(secret_access_key, canonical_string)
212
215
  end
213
216
 
data/test/test_EC2.rb CHANGED
@@ -50,8 +50,6 @@ context "The EC2 method " do
50
50
  specify "EC2::Base should allow specification of base path" do
51
51
  @ec2 = EC2::Base.new( :access_key_id => "not a key",
52
52
  :secret_access_key => "not a secret",
53
- :use_ssl => false,
54
- :server => "foo.example.com",
55
53
  :base_path => '/services/Eucalyptus' )
56
54
 
57
55
  @ec2.base_path.should.equal '/services/Eucalyptus'
@@ -59,13 +57,26 @@ context "The EC2 method " do
59
57
 
60
58
  specify "EC2::Base should default base path to /" do
61
59
  @ec2 = EC2::Base.new( :access_key_id => "not a key",
62
- :secret_access_key => "not a secret",
63
- :use_ssl => false,
64
- :server => "foo.example.com" )
60
+ :secret_access_key => "not a secret" )
65
61
 
66
62
  @ec2.base_path.should.equal '/'
67
63
  end
68
64
 
65
+ specify "EC2::Base should allow specification of http method" do
66
+ @ec2 = EC2::Base.new( :access_key_id => "not a key",
67
+ :secret_access_key => "not a secret",
68
+ :http_method => 'GET' )
69
+
70
+ @ec2.http_method.should.equal 'GET'
71
+ end
72
+
73
+ specify "EC2::Base should default http method to POST" do
74
+ @ec2 = EC2::Base.new( :access_key_id => "not a key",
75
+ :secret_access_key => "not a secret" )
76
+
77
+ @ec2.http_method.should.equal 'POST'
78
+ end
79
+
69
80
  specify "EC2.canonical_string(path) should conform to Amazon's requirements " do
70
81
  path = {"name1" => "value1", "name2" => "value2", "name3" => "value3"}
71
82
  if ENV['EC2_URL'].nil? || ENV['EC2_URL'] == 'https://ec2.amazonaws.com'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kerryb-amazon-ec2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glenn Rempe