grempe-amazon-ec2 0.3.3 → 0.3.4
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.
- data/CHANGELOG +7 -0
- data/README.rdoc +6 -0
- data/Rakefile +2 -1
- data/bin/setup.rb +9 -2
- data/lib/EC2.rb +24 -13
- data/test/test_EC2.rb +3 -3
- metadata +1 -1
data/CHANGELOG
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
=== 0.3.4 2009-01-31
|
2
|
+
* Added support in the helper binaries for EC2_URL server url for Euro servers
|
3
|
+
|
4
|
+
=== 0.3.3 2009-01-24
|
5
|
+
* Removed docs related to the ability to get Response#xml which is deprecated
|
6
|
+
* Fixed conflict when aws/s3 gem was included in user code
|
7
|
+
|
1
8
|
=== 0.3.2 2008-12-11
|
2
9
|
* Updated API version to 2008-12-01
|
3
10
|
* Note : The new European EC2 zone should just work if you specify ':server => "eu-west-1.ec2.amazonaws.com"' when initializing EC2::Base.new(). Please report any issues you have with using this new service.
|
data/README.rdoc
CHANGED
@@ -74,6 +74,12 @@ Edit the file ~/.bash_login and add the following to the existing contents:
|
|
74
74
|
export AMAZON_ACCESS_KEY_ID="YOUR_ACCESS_KEY_ID"
|
75
75
|
export AMAZON_SECRET_ACCESS_KEY="YOUR_SECRET_ACCESS_KEY_ID"
|
76
76
|
|
77
|
+
If you are using EC2 in the EU region, make sure you also set:
|
78
|
+
|
79
|
+
export EC2_URL="https://eu-west-1.ec2.amazonaws.com"
|
80
|
+
|
81
|
+
(which you have already if you configured standard EC2 command line tools to work with this region).
|
82
|
+
|
77
83
|
Once you save the file you should close and re-open your terminal so the new variables are made available. You’ll need to do this close/re-open step for each terminal window you have open (or issue the ‘source ~/.bash_login’ command in each). Make sure that this file is only readable by your user so you don’t inadvertently expose your credentials to other users on your system.
|
78
84
|
|
79
85
|
You can verify that this setup is complete by running the ‘set’ in a command window and seeing that your credentials are in the list of shell variables.
|
data/Rakefile
CHANGED
@@ -11,8 +11,9 @@ Rake::GemPackageTask.new(spec) do |pkg|
|
|
11
11
|
pkg.gem_spec = spec
|
12
12
|
end
|
13
13
|
|
14
|
+
desc "Package and then install the gem locally"
|
14
15
|
task :install => [:package] do
|
15
|
-
sh %{sudo gem install pkg/#{GEM}-#{
|
16
|
+
sh %{sudo gem install pkg/#{GEM}-#{VER}}
|
16
17
|
end
|
17
18
|
|
18
19
|
Rake::TestTask.new do |t|
|
data/bin/setup.rb
CHANGED
@@ -10,10 +10,17 @@
|
|
10
10
|
#++
|
11
11
|
|
12
12
|
if ENV['AMAZON_ACCESS_KEY_ID'] && ENV['AMAZON_SECRET_ACCESS_KEY']
|
13
|
-
|
13
|
+
opts = {
|
14
14
|
:access_key_id => ENV['AMAZON_ACCESS_KEY_ID'],
|
15
15
|
:secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY']
|
16
|
-
|
16
|
+
}
|
17
|
+
if ENV['EC2_URL']
|
18
|
+
opts[:server] = URI.parse(ENV['EC2_URL']).host
|
19
|
+
end
|
20
|
+
@ec2 = EC2::Base.new(opts)
|
17
21
|
end
|
18
22
|
|
23
|
+
puts "Current Options:"
|
24
|
+
pp opts
|
25
|
+
|
19
26
|
include EC2
|
data/lib/EC2.rb
CHANGED
@@ -28,12 +28,24 @@ module EC2
|
|
28
28
|
# from the query string to be signed.
|
29
29
|
# Note: The parameters in the path passed in must already be sorted in
|
30
30
|
# case-insensitive alphabetical order and must not be url encoded.
|
31
|
-
def EC2.canonical_string(
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
def EC2.canonical_string(params, host = DEFAULT_HOST, method="POST", base="/")
|
32
|
+
# Sort, and encode parameters into a canonical string.
|
33
|
+
sorted_params = params.sort {|x,y| x[0] <=> y[0]}
|
34
|
+
encoded_params = sorted_params.collect do |p|
|
35
|
+
encoded = (CGI::escape(p[0].to_s) +
|
36
|
+
"=" + CGI::escape(p[1].to_s))
|
37
|
+
# Ensure spaces are encoded as '%20', not '+'
|
38
|
+
encoded.gsub('+', '%20')
|
39
|
+
end
|
40
|
+
sigquery = encoded_params.join("&")
|
41
|
+
|
42
|
+
# Generate the request description string
|
43
|
+
req_desc =
|
44
|
+
method + "\n" +
|
45
|
+
host + "\n" +
|
46
|
+
base + "\n" +
|
47
|
+
sigquery
|
48
|
+
|
37
49
|
end
|
38
50
|
|
39
51
|
# Encodes the given string with the secret_access_key, by taking the
|
@@ -44,7 +56,7 @@ module EC2
|
|
44
56
|
digest = OpenSSL::Digest::Digest.new('sha1')
|
45
57
|
b64_hmac =
|
46
58
|
Base64.encode64(
|
47
|
-
OpenSSL::HMAC.digest(digest, secret_access_key, str)).
|
59
|
+
OpenSSL::HMAC.digest(digest, secret_access_key, str)).gsub("\n","")
|
48
60
|
|
49
61
|
if urlencode
|
50
62
|
return CGI::escape(b64_hmac)
|
@@ -152,14 +164,13 @@ module EC2
|
|
152
164
|
params.reject! { |key, value| value.nil? or value.empty?}
|
153
165
|
|
154
166
|
params.merge!( {"Action" => action,
|
155
|
-
"SignatureVersion" => "
|
167
|
+
"SignatureVersion" => "2",
|
168
|
+
"SignatureMethod" => 'HmacSHA1',
|
156
169
|
"AWSAccessKeyId" => @access_key_id,
|
157
170
|
"Version" => API_VERSION,
|
158
171
|
"Timestamp"=>Time.now.getutc.iso8601} )
|
159
172
|
|
160
|
-
|
161
|
-
|
162
|
-
sig = get_aws_auth_param(sigquery, @secret_access_key)
|
173
|
+
sig = get_aws_auth_param(params, @secret_access_key)
|
163
174
|
|
164
175
|
query = params.sort.collect do |param|
|
165
176
|
CGI::escape(param[0]) + "=" + CGI::escape(param[1])
|
@@ -182,8 +193,8 @@ module EC2
|
|
182
193
|
end
|
183
194
|
|
184
195
|
# Set the Authorization header using AWS signed header authentication
|
185
|
-
def get_aws_auth_param(
|
186
|
-
canonical_string = EC2.canonical_string(
|
196
|
+
def get_aws_auth_param(params, secret_access_key)
|
197
|
+
canonical_string = EC2.canonical_string(params)
|
187
198
|
encoded_canonical = EC2.encode(secret_access_key, canonical_string)
|
188
199
|
end
|
189
200
|
|
data/test/test_EC2.rb
CHANGED
@@ -39,9 +39,9 @@ context "The EC2 method " do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
|
42
|
-
specify "EC2.canonical_string(path) should
|
43
|
-
path = "
|
44
|
-
EC2.canonical_string(path).should.equal "
|
42
|
+
specify "EC2.canonical_string(path) should conform to Amazon's requirements " do
|
43
|
+
path = {"name1" => "value1", "name2" => "value2", "name3" => "value3"}
|
44
|
+
EC2.canonical_string(path).should.equal "POST\nec2.amazonaws.com\n/\nname1=value1&name2=value2&name3=value3"
|
45
45
|
end
|
46
46
|
|
47
47
|
specify "EC2.encode should return the expected string" do
|