grempe-amazon-ec2 0.3.4 → 0.3.5
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 +1 -0
- data/bin/ec2-gem-example.rb +10 -1
- data/bin/setup.rb +1 -2
- data/lib/EC2.rb +19 -7
- data/lib/EC2/exceptions.rb +11 -0
- data/test/test_EC2.rb +13 -9
- metadata +3 -2
data/CHANGELOG
CHANGED
data/bin/ec2-gem-example.rb
CHANGED
|
@@ -30,7 +30,16 @@ if ACCESS_KEY_ID.nil? || ACCESS_KEY_ID.empty?
|
|
|
30
30
|
exit
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
ec2
|
|
33
|
+
# us-east-1.ec2.amazonaws.com == ec2.amazonaws.com
|
|
34
|
+
# eu-west-1.ec2.amazonaws.com for the european region
|
|
35
|
+
# test different servers by running something like:
|
|
36
|
+
# export EC2_URL='https://ec2.amazonaws.com';./bin/ec2-gem-example.rb
|
|
37
|
+
if ENV['EC2_URL']
|
|
38
|
+
ec2 = EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY, :server => URI.parse(ENV['EC2_URL']).host )
|
|
39
|
+
else
|
|
40
|
+
# default server is US ec2.amazonaws.com
|
|
41
|
+
ec2 = EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY )
|
|
42
|
+
end
|
|
34
43
|
|
|
35
44
|
puts "----- ec2.methods.sort -----"
|
|
36
45
|
p ec2.methods.sort
|
data/bin/setup.rb
CHANGED
data/lib/EC2.rb
CHANGED
|
@@ -19,7 +19,19 @@ Dir[File.join(File.dirname(__FILE__), 'EC2/**/*.rb')].sort.each { |lib| require
|
|
|
19
19
|
module EC2
|
|
20
20
|
|
|
21
21
|
# Which host FQDN will we connect to for all API calls to AWS?
|
|
22
|
-
|
|
22
|
+
# If EC2_URL is defined in the users ENV we can use that. It is
|
|
23
|
+
# expected that this var is set with something like:
|
|
24
|
+
# export EC2_URL='https://ec2.amazonaws.com'
|
|
25
|
+
#
|
|
26
|
+
if ENV['EC2_URL']
|
|
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)
|
|
30
|
+
DEFAULT_HOST = URI.parse(EC2_URL).host
|
|
31
|
+
else
|
|
32
|
+
# default US host
|
|
33
|
+
DEFAULT_HOST = 'ec2.amazonaws.com'
|
|
34
|
+
end
|
|
23
35
|
|
|
24
36
|
# This is the version of the API as defined by Amazon Web Services
|
|
25
37
|
API_VERSION = '2008-12-01'
|
|
@@ -32,7 +44,7 @@ module EC2
|
|
|
32
44
|
# Sort, and encode parameters into a canonical string.
|
|
33
45
|
sorted_params = params.sort {|x,y| x[0] <=> y[0]}
|
|
34
46
|
encoded_params = sorted_params.collect do |p|
|
|
35
|
-
encoded = (CGI::escape(p[0].to_s) +
|
|
47
|
+
encoded = (CGI::escape(p[0].to_s) +
|
|
36
48
|
"=" + CGI::escape(p[1].to_s))
|
|
37
49
|
# Ensure spaces are encoded as '%20', not '+'
|
|
38
50
|
encoded.gsub('+', '%20')
|
|
@@ -40,10 +52,10 @@ module EC2
|
|
|
40
52
|
sigquery = encoded_params.join("&")
|
|
41
53
|
|
|
42
54
|
# Generate the request description string
|
|
43
|
-
req_desc =
|
|
44
|
-
method + "\n" +
|
|
45
|
-
host + "\n" +
|
|
46
|
-
base + "\n" +
|
|
55
|
+
req_desc =
|
|
56
|
+
method + "\n" +
|
|
57
|
+
host + "\n" +
|
|
58
|
+
base + "\n" +
|
|
47
59
|
sigquery
|
|
48
60
|
|
|
49
61
|
end
|
|
@@ -248,7 +260,7 @@ module EC2
|
|
|
248
260
|
if EC2.const_defined?(error_code)
|
|
249
261
|
raise EC2.const_get(error_code), error_message
|
|
250
262
|
else
|
|
251
|
-
raise Error,
|
|
263
|
+
raise EC2::Error, error_message
|
|
252
264
|
end
|
|
253
265
|
|
|
254
266
|
end
|
data/lib/EC2/exceptions.rb
CHANGED
|
@@ -32,6 +32,14 @@ module EC2
|
|
|
32
32
|
class AuthFailure < Error #:nodoc:
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
+
# Invalid AWS Account
|
|
36
|
+
class InvalidClientTokenId < Error #:nodoc:
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Invalid Parameters for Value
|
|
40
|
+
class InvalidParameterValue < Error #:nodoc:
|
|
41
|
+
end
|
|
42
|
+
|
|
35
43
|
# Specified AMI has an unparsable manifest.
|
|
36
44
|
class InvalidManifest < Error #:nodoc:
|
|
37
45
|
end
|
|
@@ -133,4 +141,7 @@ module EC2
|
|
|
133
141
|
class Unavailable < Error #:nodoc:
|
|
134
142
|
end
|
|
135
143
|
|
|
144
|
+
class SignatureDoesNotMatch < Error #:nodoc:
|
|
145
|
+
end
|
|
146
|
+
|
|
136
147
|
end
|
data/test/test_EC2.rb
CHANGED
|
@@ -17,31 +17,35 @@ context "The EC2 method " do
|
|
|
17
17
|
|
|
18
18
|
specify "EC2::Base attribute readers should be available" do
|
|
19
19
|
@ec2 = EC2::Base.new( :access_key_id => "not a key",
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
:secret_access_key => "not a secret",
|
|
21
|
+
:use_ssl => true,
|
|
22
|
+
:server => "foo.example.com" )
|
|
23
23
|
|
|
24
24
|
@ec2.use_ssl.should.equal true
|
|
25
25
|
@ec2.port.should.equal 443
|
|
26
26
|
@ec2.server.should.equal "foo.example.com"
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
|
|
30
29
|
specify "EC2::Base should work with insecure connections as well" do
|
|
31
30
|
@ec2 = EC2::Base.new( :access_key_id => "not a key",
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
:secret_access_key => "not a secret",
|
|
32
|
+
:use_ssl => false,
|
|
33
|
+
:server => "foo.example.com" )
|
|
35
34
|
|
|
36
35
|
@ec2.use_ssl.should.equal false
|
|
37
36
|
@ec2.port.should.equal 80
|
|
38
37
|
@ec2.server.should.equal "foo.example.com"
|
|
39
38
|
end
|
|
40
39
|
|
|
41
|
-
|
|
42
40
|
specify "EC2.canonical_string(path) should conform to Amazon's requirements " do
|
|
43
41
|
path = {"name1" => "value1", "name2" => "value2", "name3" => "value3"}
|
|
44
|
-
|
|
42
|
+
if ENV['EC2_URL'].nil? || ENV['EC2_URL'] == 'https://ec2.amazonaws.com'
|
|
43
|
+
EC2.canonical_string(path).should.equal "POST\nec2.amazonaws.com\n/\nname1=value1&name2=value2&name3=value3"
|
|
44
|
+
elsif ENV['EC2_URL'] == 'https://us-east-1.ec2.amazonaws.com'
|
|
45
|
+
EC2.canonical_string(path).should.equal "POST\nus-east-1.ec2.amazonaws.com\n/\nname1=value1&name2=value2&name3=value3"
|
|
46
|
+
elsif ENV['EC2_URL'] == 'https://eu-west-1.ec2.amazonaws.com'
|
|
47
|
+
EC2.canonical_string(path).should.equal "POST\neu-west-1.ec2.amazonaws.com\n/\nname1=value1&name2=value2&name3=value3"
|
|
48
|
+
end
|
|
45
49
|
end
|
|
46
50
|
|
|
47
51
|
specify "EC2.encode should return the expected string" do
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: grempe-amazon-ec2
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Glenn Rempe
|
|
@@ -9,11 +9,12 @@ autorequire: EC2
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-
|
|
12
|
+
date: 2009-02-25 00:00:00 -08:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: xml-simple
|
|
17
|
+
type: :runtime
|
|
17
18
|
version_requirement:
|
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
|
19
20
|
requirements:
|