amazon-ec2 0.3.4 → 0.3.6
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 +9 -0
- data/Rakefile +5 -0
- data/bin/ec2-gem-example.rb +10 -1
- data/bin/setup.rb +1 -2
- data/lib/EC2.rb +25 -13
- data/lib/EC2/exceptions.rb +11 -0
- data/test/test_EC2.rb +24 -8
- metadata +3 -3
data/CHANGELOG
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
=== 0.3.6 2009-03-02
|
|
2
|
+
* You can now specify any arbitrary SSL tcp port to connect to (kerryb)
|
|
3
|
+
* Added rake target to quickly install the gem without docs
|
|
4
|
+
|
|
5
|
+
=== 0.3.5 2009-02-26
|
|
6
|
+
* Honor the EC2_URL env var if provided in the main lib
|
|
7
|
+
* Some minor modifications to the exceptions raised when unknown
|
|
8
|
+
|
|
1
9
|
=== 0.3.4 2009-01-31
|
|
2
10
|
* Added support in the helper binaries for EC2_URL server url for Euro servers
|
|
11
|
+
* AWS Signature v2 support
|
|
3
12
|
|
|
4
13
|
=== 0.3.3 2009-01-24
|
|
5
14
|
* Removed docs related to the ability to get Response#xml which is deprecated
|
data/Rakefile
CHANGED
|
@@ -16,6 +16,11 @@ task :install => [:package] do
|
|
|
16
16
|
sh %{sudo gem install pkg/#{GEM}-#{VER}}
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
+
desc "Package and then install the gem locally omitting documentation"
|
|
20
|
+
task :install_nodoc => [:package] do
|
|
21
|
+
sh %{sudo gem install --no-ri --no-rdoc pkg/#{GEM}-#{VER}}
|
|
22
|
+
end
|
|
23
|
+
|
|
19
24
|
Rake::TestTask.new do |t|
|
|
20
25
|
t.libs << "test"
|
|
21
26
|
t.test_files = FileList['test/test*.rb']
|
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
|
|
@@ -106,14 +118,14 @@ module EC2
|
|
|
106
118
|
raise ArgumentError, "No :use_ssl value provided" if options[:use_ssl].nil?
|
|
107
119
|
raise ArgumentError, "Invalid :use_ssl value provided, only 'true' or 'false' allowed" unless options[:use_ssl] == true || options[:use_ssl] == false
|
|
108
120
|
raise ArgumentError, "No :server provided" if options[:server].nil? || options[:server].empty?
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
121
|
+
|
|
122
|
+
if options[:port]
|
|
123
|
+
# user-specified port
|
|
124
|
+
@port = options[:port]
|
|
125
|
+
elsif @use_ssl
|
|
114
126
|
# https
|
|
115
127
|
@port = 443
|
|
116
|
-
|
|
128
|
+
else
|
|
117
129
|
# http
|
|
118
130
|
@port = 80
|
|
119
131
|
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,47 @@ 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
|
|
|
40
|
+
specify "EC2::Base should allow specification of port" do
|
|
41
|
+
@ec2 = EC2::Base.new( :access_key_id => "not a key",
|
|
42
|
+
:secret_access_key => "not a secret",
|
|
43
|
+
:use_ssl => true,
|
|
44
|
+
:server => "foo.example.com",
|
|
45
|
+
:port => 8443 )
|
|
46
|
+
|
|
47
|
+
@ec2.use_ssl.should.equal true
|
|
48
|
+
@ec2.port.should.equal 8443
|
|
49
|
+
@ec2.server.should.equal "foo.example.com"
|
|
50
|
+
end
|
|
41
51
|
|
|
42
52
|
specify "EC2.canonical_string(path) should conform to Amazon's requirements " do
|
|
43
53
|
path = {"name1" => "value1", "name2" => "value2", "name3" => "value3"}
|
|
44
|
-
|
|
54
|
+
if ENV['EC2_URL'].nil? || ENV['EC2_URL'] == 'https://ec2.amazonaws.com'
|
|
55
|
+
EC2.canonical_string(path).should.equal "POST\nec2.amazonaws.com\n/\nname1=value1&name2=value2&name3=value3"
|
|
56
|
+
elsif ENV['EC2_URL'] == 'https://us-east-1.ec2.amazonaws.com'
|
|
57
|
+
EC2.canonical_string(path).should.equal "POST\nus-east-1.ec2.amazonaws.com\n/\nname1=value1&name2=value2&name3=value3"
|
|
58
|
+
elsif ENV['EC2_URL'] == 'https://eu-west-1.ec2.amazonaws.com'
|
|
59
|
+
EC2.canonical_string(path).should.equal "POST\neu-west-1.ec2.amazonaws.com\n/\nname1=value1&name2=value2&name3=value3"
|
|
60
|
+
end
|
|
45
61
|
end
|
|
46
62
|
|
|
47
63
|
specify "EC2.encode should return the expected string" 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.
|
|
4
|
+
version: 0.3.6
|
|
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-
|
|
12
|
+
date: 2009-03-02 00:00:00 -08:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
@@ -23,7 +23,7 @@ dependencies:
|
|
|
23
23
|
version: 1.0.11
|
|
24
24
|
version:
|
|
25
25
|
description: An interface library that allows Ruby applications to easily connect to the HTTP 'Query API' for the Amazon Web Services Elastic Compute Cloud (EC2) and manipulate cloud servers.
|
|
26
|
-
email: glenn
|
|
26
|
+
email: glenn@rempe.us
|
|
27
27
|
executables:
|
|
28
28
|
- ec2-gem-example.rb
|
|
29
29
|
- ec2sh
|