kerryb-amazon-ec2 0.3.6 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/EC2.rb +5 -4
  2. data/test/test_EC2.rb +25 -2
  3. metadata +1 -1
data/lib/EC2.rb CHANGED
@@ -57,7 +57,6 @@ module EC2
57
57
  host + "\n" +
58
58
  base + "\n" +
59
59
  sigquery
60
-
61
60
  end
62
61
 
63
62
  # Encodes the given string with the secret_access_key, by taking the
@@ -98,7 +97,7 @@ module EC2
98
97
  #
99
98
  class Base
100
99
 
101
- attr_reader :use_ssl, :server, :proxy_server, :port
100
+ attr_reader :use_ssl, :server, :proxy_server, :port, :base_path
102
101
 
103
102
  def initialize( options = {} )
104
103
 
@@ -106,12 +105,14 @@ module EC2
106
105
  :secret_access_key => "",
107
106
  :use_ssl => true,
108
107
  :server => DEFAULT_HOST,
109
- :proxy_server => nil
108
+ :proxy_server => nil,
109
+ :base_path => '/'
110
110
  }.merge(options)
111
111
 
112
112
  @server = options[:server]
113
113
  @proxy_server = options[:proxy_server]
114
114
  @use_ssl = options[:use_ssl]
115
+ @base_path = options[:base_path]
115
116
 
116
117
  raise ArgumentError, "No :access_key_id provided" if options[:access_key_id].nil? || options[:access_key_id].empty?
117
118
  raise ArgumentError, "No :secret_access_key provided" if options[:secret_access_key].nil? || options[:secret_access_key].empty?
@@ -206,7 +207,7 @@ module EC2
206
207
 
207
208
  # Set the Authorization header using AWS signed header authentication
208
209
  def get_aws_auth_param(params, secret_access_key)
209
- canonical_string = EC2.canonical_string(params)
210
+ canonical_string = EC2.canonical_string(params, @server, 'GET', @base_path)
210
211
  encoded_canonical = EC2.encode(secret_access_key, canonical_string)
211
212
  end
212
213
 
data/test/test_EC2.rb CHANGED
@@ -44,9 +44,26 @@ context "The EC2 method " do
44
44
  :server => "foo.example.com",
45
45
  :port => 8443 )
46
46
 
47
- @ec2.use_ssl.should.equal true
48
47
  @ec2.port.should.equal 8443
49
- @ec2.server.should.equal "foo.example.com"
48
+ end
49
+
50
+ specify "EC2::Base should allow specification of base path" do
51
+ @ec2 = EC2::Base.new( :access_key_id => "not a key",
52
+ :secret_access_key => "not a secret",
53
+ :use_ssl => false,
54
+ :server => "foo.example.com",
55
+ :base_path => '/services/Eucalyptus' )
56
+
57
+ @ec2.base_path.should.equal '/services/Eucalyptus'
58
+ end
59
+
60
+ specify "EC2::Base should default base path to /" do
61
+ @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" )
65
+
66
+ @ec2.base_path.should.equal '/'
50
67
  end
51
68
 
52
69
  specify "EC2.canonical_string(path) should conform to Amazon's requirements " do
@@ -59,6 +76,12 @@ context "The EC2 method " do
59
76
  EC2.canonical_string(path).should.equal "POST\neu-west-1.ec2.amazonaws.com\n/\nname1=value1&name2=value2&name3=value3"
60
77
  end
61
78
  end
79
+
80
+ specify 'EC2.canonical_string(path) should allow specification of host, base path and method' do
81
+ path = {"name1" => "value1", "name2" => "value2", "name3" => "value3"}
82
+ EC2.canonical_string(path, 'foo.example.com', 'GET', '/services/Eucalyptus').should.
83
+ equal "GET\nfoo.example.com\n/services/Eucalyptus\nname1=value1&name2=value2&name3=value3"
84
+ end
62
85
 
63
86
  specify "EC2.encode should return the expected string" do
64
87
  EC2.encode("secretaccesskey", "foobar123", urlencode=true).should.equal "e3jeuDc3DIX2mW8cVqWiByj4j5g%3D"
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.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glenn Rempe