Skip to content
Newer
Older
100644 376 lines (313 sloc) 14.9 KB
ffc499d @grempe Updated all docs to use YARD doc generator and meta tags.
authored Aug 20, 2009
1 #--
2 # Amazon Web Services EC2 + ELB API Ruby library
3 #
4 # Ruby Gem Name:: amazon-ec2
5 # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6 # Copyright:: Copyright (c) 2007-2009 Glenn Rempe
7 # License:: Distributes under the same terms as Ruby
8 # Home:: http://github.com/grempe/amazon-ec2/tree/master
9 #++
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
10
a698c37 @grempe URI seems to be included in some rubies, and not in others.
authored May 23, 2010
11 %w[ base64 cgi openssl digest/sha1 net/https net/http rexml/document time ostruct ].each { |f| require f }
12
13 begin
14 require 'URI' unless defined? URI
15 rescue Exception => e
16 # nothing
17 end
7a7f0d0 refactored library so that it can encompass multiple apis, and added …
Kris Rasmussen authored Jul 1, 2009
18
ffc499d @grempe Updated all docs to use YARD doc generator and meta tags.
authored Aug 21, 2009
19 begin
20 require 'xmlsimple' unless defined? XmlSimple
21 rescue Exception => e
22 require 'xml-simple' unless defined? XmlSimple
23 end
24
25
26 # A custom implementation of Hash that allows us to access hash values using dot notation
27 #
28 # @example Access the hash keys in the standard way or using dot notation
29 # foo[:bar] => "baz"
30 # foo.bar => "baz"
31 class Hash
32 def method_missing(meth, *args, &block)
33 if args.size == 0
34 self[meth.to_s] || self[meth.to_sym]
35 end
36 end
fd20977 @grempe Whitespace and RDS_URL.
authored Oct 29, 2009
37
96c4265 @nirvdrum Added ability to describe spot instance requests.
nirvdrum authored Jan 3, 2010
38 def type
39 self['type']
40 end
41
0534b67 @auser Adding beginning to RDS Query API methods
auser authored Oct 27, 2009
42 def has?(key)
43 self[key] && !self[key].to_s.empty?
44 end
fd20977 @grempe Whitespace and RDS_URL.
authored Oct 30, 2009
45
0534b67 @auser Adding beginning to RDS Query API methods
auser authored Oct 28, 2009
46 def does_not_have?(key)
47 self[key].nil? || self[key].to_s.empty?
48 end
ffc499d @grempe Updated all docs to use YARD doc generator and meta tags.
authored Aug 21, 2009
49 end
50
51
7a7f0d0 refactored library so that it can encompass multiple apis, and added …
Kris Rasmussen authored Jul 2, 2009
52 module AWS
6b0b723 @sgonyea Changed the env variable naming, IRB, etc.
sgonyea authored Mar 5, 2011
53 ACCESS_KEY_ID = ENV['AWS_ACCESS_KEY_ID'] || ENV['AMAZON_ACCESS_KEY_ID'] || ""
54 SECRET_ACCESS_KEY = ENV['AWS_SECRET_ACCESS_KEY'] || ENV['AMAZON_SECRET_ACCESS_KEY'] || ""
ffc499d @grempe Updated all docs to use YARD doc generator and meta tags.
authored Aug 21, 2009
55
56 # Builds the canonical string for signing requests. This strips out all '&', '?', and '='
57 # from the query string to be signed. The parameters in the path passed in must already
58 # be sorted in case-insensitive alphabetical order and must not be url encoded.
59 #
60 # @param [String] params the params that will be sorted and encoded as a canonical string.
61 # @param [String] host the hostname of the API endpoint.
62 # @param [String] method the HTTP method that will be used to submit the params.
63 # @param [String] base the URI path that this information will be submitted to.
64 # @return [String] the canonical request description string.
7a7f0d0 refactored library so that it can encompass multiple apis, and added …
Kris Rasmussen authored Jul 2, 2009
65 def AWS.canonical_string(params, host, method="POST", base="/")
dd4e2c4 @cstar Version 2 signature
cstar authored Jan 27, 2009
66 # Sort, and encode parameters into a canonical string.
67 sorted_params = params.sort {|x,y| x[0] <=> y[0]}
68 encoded_params = sorted_params.collect do |p|
cf9bb66 @grempe Honor the EC2_URL env var if provided in the main lib. Whitespace cle…
authored Jan 31, 2009
69 encoded = (CGI::escape(p[0].to_s) +
dd4e2c4 @cstar Version 2 signature
cstar authored Jan 27, 2009
70 "=" + CGI::escape(p[1].to_s))
71 # Ensure spaces are encoded as '%20', not '+'
aa52268 @wlach Fix small bug in encoding of canonical string
wlach authored Mar 19, 2010
72 encoded = encoded.gsub('+', '%20')
3d7a3d3 @wlach Don't encode '~' character for values while creating canonical string
wlach authored Mar 19, 2010
73 # According to RFC3986 (the scheme for values expected by signing requests), '~'
74 # should not be encoded
75 encoded = encoded.gsub('%7E', '~')
dd4e2c4 @cstar Version 2 signature
cstar authored Jan 27, 2009
76 end
77 sigquery = encoded_params.join("&")
78
79 # Generate the request description string
cf9bb66 @grempe Honor the EC2_URL env var if provided in the main lib. Whitespace cle…
authored Jan 31, 2009
80 req_desc =
81 method + "\n" +
82 host + "\n" +
83 base + "\n" +
dd4e2c4 @cstar Version 2 signature
cstar authored Jan 27, 2009
84 sigquery
85
2679389 r962@mac: glenn | 2006-12-14 10:24:38 -0800
grempe authored Dec 14, 2006
86 end
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
87
ffc499d @grempe Updated all docs to use YARD doc generator and meta tags.
authored Aug 21, 2009
88 # Encodes the given string with the secret_access_key by taking the
2679389 r962@mac: glenn | 2006-12-14 10:24:38 -0800
grempe authored Dec 14, 2006
89 # hmac-sha1 sum, and then base64 encoding it. Optionally, it will also
90 # url encode the result of that to protect the string if it's going to
91 # be used as a query string parameter.
ffc499d @grempe Updated all docs to use YARD doc generator and meta tags.
authored Aug 21, 2009
92 #
93 # @param [String] secret_access_key the user's secret access key for signing.
94 # @param [String] str the string to be hashed and encoded.
95 # @param [Boolean] urlencode whether or not to url encode the result., true or false
96 # @return [String] the signed and encoded string.
7a7f0d0 refactored library so that it can encompass multiple apis, and added …
Kris Rasmussen authored Jul 2, 2009
97 def AWS.encode(secret_access_key, str, urlencode=true)
c1d3fd1 Switched from HMAC-SHA1 to HMAC-SHA256 signature
Mike Bailey authored May 17, 2010
98 digest = OpenSSL::Digest::Digest.new('sha256')
2679389 r962@mac: glenn | 2006-12-14 10:24:38 -0800
grempe authored Dec 14, 2006
99 b64_hmac =
100 Base64.encode64(
dd4e2c4 @cstar Version 2 signature
cstar authored Jan 27, 2009
101 OpenSSL::HMAC.digest(digest, secret_access_key, str)).gsub("\n","")
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
102
2679389 r962@mac: glenn | 2006-12-14 10:24:38 -0800
grempe authored Dec 14, 2006
103 if urlencode
104 return CGI::escape(b64_hmac)
105 else
106 return b64_hmac
107 end
108 end
716d60b @grempe Whitespace.
authored Aug 10, 2009
109
ffc499d @grempe Updated all docs to use YARD doc generator and meta tags.
authored Aug 21, 2009
110 # This class provides all the methods for using the EC2 or ELB service
111 # including the handling of header signing and other security concerns.
112 # This class uses the Net::HTTP library to interface with the AWS Query API
113 # interface. You should not instantiate this directly, instead
114 # you should setup an instance of 'AWS::EC2::Base' or 'AWS::ELB::Base'.
0e0470e r1285@mac-mini: glenn | 2007-06-19 17:19:37 -0700
grempe authored Jun 20, 2007
115 class Base
53ae17b @grempe Updated to add http proxy support. Based on patch by Mathias Dalheimer.
authored Feb 17, 2008
116 attr_reader :use_ssl, :server, :proxy_server, :port
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
117
ffc499d @grempe Updated all docs to use YARD doc generator and meta tags.
authored Aug 21, 2009
118 # @option options [String] :access_key_id ("") The user's AWS Access Key ID
119 # @option options [String] :secret_access_key ("") The user's AWS Secret Access Key
120 # @option options [Boolean] :use_ssl (true) Connect using SSL?
121 # @option options [String] :server ("ec2.amazonaws.com") The server API endpoint host
122 # @option options [String] :proxy_server (nil) An HTTP proxy server FQDN
123 # @return [Object] the object.
ce3d401 r1612@macbook-pro: glenn | 2007-06-09 16:22:17 -0700
grempe authored Jun 9, 2007
124 def initialize( options = {} )
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
125
6b0b723 @sgonyea Changed the env variable naming, IRB, etc.
sgonyea authored Mar 5, 2011
126 options = { :access_key_id => ACCESS_KEY_ID,
127 :secret_access_key => SECRET_ACCESS_KEY,
5b4ab60 r1619@macbook-pro: glenn | 2007-06-10 16:43:54 -0700
grempe authored Jun 10, 2007
128 :use_ssl => true,
7a7f0d0 refactored library so that it can encompass multiple apis, and added …
Kris Rasmussen authored Jul 2, 2009
129 :server => default_host,
14fc69c @grempe Whitespace
authored Nov 21, 2010
130 :path => "/",
53ae17b @grempe Updated to add http proxy support. Based on patch by Mathias Dalheimer.
authored Feb 17, 2008
131 :proxy_server => nil
ce3d401 r1612@macbook-pro: glenn | 2007-06-09 16:22:17 -0700
grempe authored Jun 9, 2007
132 }.merge(options)
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
133
eaa2444 r1623@macbook-pro: glenn | 2007-06-10 18:54:27 -0700
grempe authored Jun 11, 2007
134 @server = options[:server]
53ae17b @grempe Updated to add http proxy support. Based on patch by Mathias Dalheimer.
authored Feb 17, 2008
135 @proxy_server = options[:proxy_server]
eaa2444 r1623@macbook-pro: glenn | 2007-06-10 18:54:27 -0700
grempe authored Jun 11, 2007
136 @use_ssl = options[:use_ssl]
748ec4d patches for eucalyptus compatibility
Sang-Min Park authored Nov 12, 2010
137 @path = options[:path]
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
138
5b4ab60 r1619@macbook-pro: glenn | 2007-06-10 16:43:54 -0700
grempe authored Jun 10, 2007
139 raise ArgumentError, "No :access_key_id provided" if options[:access_key_id].nil? || options[:access_key_id].empty?
140 raise ArgumentError, "No :secret_access_key provided" if options[:secret_access_key].nil? || options[:secret_access_key].empty?
141 raise ArgumentError, "No :use_ssl value provided" if options[:use_ssl].nil?
b39433b r1336@mac-mini: glenn | 2007-07-03 13:57:13 -0700
grempe authored Jul 3, 2007
142 raise ArgumentError, "Invalid :use_ssl value provided, only 'true' or 'false' allowed" unless options[:use_ssl] == true || options[:use_ssl] == false
ce3d401 r1612@macbook-pro: glenn | 2007-06-09 16:22:17 -0700
grempe authored Jun 9, 2007
143 raise ArgumentError, "No :server provided" if options[:server].nil? || options[:server].empty?
b2508fb @grempe Ruby 1.9.1 compatibility fix. Tested with Ruby 1.8.6, 1.8.7, 1.9.1, O…
authored Aug 9, 2009
144
ca59df0 @kerryb Allow specification of port
kerryb authored Mar 2, 2009
145 if options[:port]
146 # user-specified port
147 @port = options[:port]
148 elsif @use_ssl
ce3d401 r1612@macbook-pro: glenn | 2007-06-09 16:22:17 -0700
grempe authored Jun 9, 2007
149 # https
150 @port = 443
ca59df0 @kerryb Allow specification of port
kerryb authored Mar 2, 2009
151 else
ce3d401 r1612@macbook-pro: glenn | 2007-06-09 16:22:17 -0700
grempe authored Jun 9, 2007
152 # http
153 @port = 80
154 end
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
155
5b4ab60 r1619@macbook-pro: glenn | 2007-06-10 16:43:54 -0700
grempe authored Jun 10, 2007
156 @access_key_id = options[:access_key_id]
157 @secret_access_key = options[:secret_access_key]
53ae17b @grempe Updated to add http proxy support. Based on patch by Mathias Dalheimer.
authored Feb 17, 2008
158
159 # Use proxy server if defined
160 # Based on patch by Mathias Dalheimer. 20070217
161 proxy = @proxy_server ? URI.parse(@proxy_server) : OpenStruct.new
162 @http = Net::HTTP::Proxy( proxy.host,
163 proxy.port,
164 proxy.user,
165 proxy.password).new(options[:server], @port)
166
eaa2444 r1623@macbook-pro: glenn | 2007-06-10 18:54:27 -0700
grempe authored Jun 11, 2007
167 @http.use_ssl = @use_ssl
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
168
ce3d401 r1612@macbook-pro: glenn | 2007-06-09 16:22:17 -0700
grempe authored Jun 9, 2007
169 # Don't verify the SSL certificates. Avoids SSL Cert warning in log on every GET.
fc5e7ec r970@mac: glenn | 2006-12-16 14:33:36 -0800
grempe authored Dec 16, 2006
170 @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
171
2679389 r962@mac: glenn | 2006-12-14 10:24:38 -0800
grempe authored Dec 14, 2006
172 end
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
173
9d38efe @nirvdrum Finished implementing spot instance support (I think, at least).
nirvdrum authored Jan 3, 2010
174 # If :user_data is passed in then URL escape and Base64 encode it
175 # as needed. Need for URL Escape + Base64 encoding is determined
176 # by :base64_encoded param.
177 def extract_user_data( options = {} )
178 return unless options[:user_data]
179 if options[:user_data]
180 if options[:base64_encoded]
181 Base64.encode64(options[:user_data]).gsub(/\n/, "").strip()
182 else
183 options[:user_data]
184 end
185 end
186 end
187
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
188
7a7f0d0 refactored library so that it can encompass multiple apis, and added …
Kris Rasmussen authored Jul 2, 2009
189 protected
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
190
fc5e7ec r970@mac: glenn | 2006-12-16 14:33:36 -0800
grempe authored Dec 16, 2006
191 # pathlist is a utility method which takes a key string and and array as input.
192 # It converts the array into a Hash with the hash key being 'Key.n' where
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
193 # 'n' increments by 1 for each iteration. So if you pass in args
194 # ("ImageId", ["123", "456"]) you should get
fc5e7ec r970@mac: glenn | 2006-12-16 14:33:36 -0800
grempe authored Dec 16, 2006
195 # {"ImageId.1"=>"123", "ImageId.2"=>"456"} returned.
196 def pathlist(key, arr)
197 params = {}
b2508fb @grempe Ruby 1.9.1 compatibility fix. Tested with Ruby 1.8.6, 1.8.7, 1.9.1, O…
authored Aug 9, 2009
198
199 # ruby 1.9 will barf if we pass in a string instead of the array expected.
200 # it will fail on each_with_index below since string is not enumerable.
201 if arr.is_a? String
202 new_arr = []
203 new_arr << arr
204 arr = new_arr
205 end
206
fc5e7ec r970@mac: glenn | 2006-12-16 14:33:36 -0800
grempe authored Dec 16, 2006
207 arr.each_with_index do |value, i|
208 params["#{key}.#{i+1}"] = value
2679389 r962@mac: glenn | 2006-12-14 10:24:38 -0800
grempe authored Dec 14, 2006
209 end
fc5e7ec r970@mac: glenn | 2006-12-16 14:33:36 -0800
grempe authored Dec 16, 2006
210 params
2679389 r962@mac: glenn | 2006-12-14 10:24:38 -0800
grempe authored Dec 14, 2006
211 end
716d60b @grempe Whitespace.
authored Aug 11, 2009
212
7a7f0d0 refactored library so that it can encompass multiple apis, and added …
Kris Rasmussen authored Jul 2, 2009
213 # Same as _pathlist_ except it deals with arrays of hashes.
214 # So if you pass in args
215 # ("People", [{:name=>'jon', :age=>'22'}, {:name=>'chris'}], {:name => 'Name', :age => 'Age'}) you should get
216 # {"People.1.Name"=>"jon", "People.1.Age"=>'22', 'People.2.Name'=>'chris'}
217 def pathhashlist(key, arr_of_hashes, mappings)
dfdf2d6 @grempe New refreshed EC2 run_instances, start_instances, and stop_instances …
authored Dec 5, 2009
218 raise ArgumentError, "expected a key that is a String" unless key.is_a? String
219 raise ArgumentError, "expected a arr_of_hashes that is an Array" unless arr_of_hashes.is_a? Array
220 arr_of_hashes.each{|h| raise ArgumentError, "expected each element of arr_of_hashes to be a Hash" unless h.is_a?(Hash)}
221 raise ArgumentError, "expected a mappings that is an Hash" unless mappings.is_a? Hash
222 params = {}
7a7f0d0 refactored library so that it can encompass multiple apis, and added …
Kris Rasmussen authored Jul 2, 2009
223 arr_of_hashes.each_with_index do |hash, i|
224 hash.each do |attribute, value|
a5eb3b5 First version of describe_tags
Thomas Dudziak authored Oct 15, 2010
225 if value.is_a? Array
226 params["#{key}.#{i+1}.Name"] = mappings[attribute]
227 value.each_with_index do |item, j|
228 params["#{key}.#{i+1}.Value.#{j+1}"] = item.to_s
229 end
230 else
231 params["#{key}.#{i+1}.#{mappings[attribute]}"] = value.to_s
232 end
7a7f0d0 refactored library so that it can encompass multiple apis, and added …
Kris Rasmussen authored Jul 2, 2009
233 end
234 end
235 params
236 end
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
237
8cd676b Created separate function for the key-value parameter structure that …
Thomas Dudziak authored Oct 15, 2010
238 # Same as _pathhashlist_ except it generates explicit <prefix>.Key= and <prefix>.Value or <prefix>.Value.1, <prefix>.Value.2
239 # depending on whether the value is a scalar or an array.
240 #
241 # So if you pass in args
242 # ("People", [{:name=>'jon'}, {:names=>['chris', 'bob']} with key_name = 'Key' and value_name = 'Value',
243 # you should get
244 # {"People.1.Key"=>"name", "People.1.Value"=>'jon', "People.2.Key"=>'names', 'People.2.Value.1'=>'chris', 'People.2.Value.2'=>'bob'}
245 def pathkvlist(key, arr_of_hashes, key_name, value_name, mappings)
246 raise ArgumentError, "expected a key that is a String" unless key.is_a? String
247 raise ArgumentError, "expected a arr_of_hashes that is an Array" unless arr_of_hashes.is_a? Array
248 arr_of_hashes.each{|h| raise ArgumentError, "expected each element of arr_of_hashes to be a Hash" unless h.is_a?(Hash)}
249 raise ArgumentError, "expected a key_nam that is a String" unless key_name.is_a? String
250 raise ArgumentError, "expected a value_name that is a String" unless value_name.is_a? String
251 raise ArgumentError, "expected a mappings that is an Hash" unless mappings.is_a? Hash
252 params = {}
253 arr_of_hashes.each_with_index do |hash, i|
254 hash.each do |attribute, value|
255 params["#{key}.#{i+1}.#{key_name}"] = mappings.fetch(attribute, attribute)
256 if !value.nil?
257 if value.is_a? Array
258 value.each_with_index do |item, j|
259 params["#{key}.#{i+1}.#{value_name}.#{j+1}"] = item.to_s
260 end
261 else
262 params["#{key}.#{i+1}.#{value_name}"] = value.to_s
263 end
264 end
265 end
266 end
267 params
268 end
269
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
270 # Make the connection to AWS EC2 passing in our request. This is generally called from
fc5e7ec r970@mac: glenn | 2006-12-16 14:33:36 -0800
grempe authored Dec 16, 2006
271 # within a 'Response' class object or one of its sub-classes so the response is interpreted
272 # in its proper context. See lib/EC2/responses.rb
273 def make_request(action, params, data='')
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
274
fc5e7ec r970@mac: glenn | 2006-12-16 14:33:36 -0800
grempe authored Dec 16, 2006
275 @http.start do
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
276
eaa2444 r1623@macbook-pro: glenn | 2007-06-10 18:54:27 -0700
grempe authored Jun 11, 2007
277 # remove any keys that have nil or empty values
b9c68f6 r1295@mac-mini: glenn | 2007-06-20 14:43:47 -0700
grempe authored Jun 20, 2007
278 params.reject! { |key, value| value.nil? or value.empty?}
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
279
d84bb93 r1567@macbook-pro: glenn | 2007-06-03 23:50:29 -0700
grempe authored Jun 4, 2007
280 params.merge!( {"Action" => action,
dd4e2c4 @cstar Version 2 signature
cstar authored Jan 27, 2009
281 "SignatureVersion" => "2",
c1d3fd1 Switched from HMAC-SHA1 to HMAC-SHA256 signature
Mike Bailey authored May 16, 2010
282 "SignatureMethod" => 'HmacSHA256',
5b4ab60 r1619@macbook-pro: glenn | 2007-06-10 16:43:54 -0700
grempe authored Jun 10, 2007
283 "AWSAccessKeyId" => @access_key_id,
7a7f0d0 refactored library so that it can encompass multiple apis, and added …
Kris Rasmussen authored Jul 2, 2009
284 "Version" => api_version,
d84bb93 r1567@macbook-pro: glenn | 2007-06-03 23:50:29 -0700
grempe authored Jun 4, 2007
285 "Timestamp"=>Time.now.getutc.iso8601} )
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
286
2a50f5c @delano Fixed signature for EU region
delano authored Apr 17, 2009
287 sig = get_aws_auth_param(params, @secret_access_key, @server)
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
288
1f1a53d @grempe Change HTTP API requests to use POST instead of GET.
authored Feb 25, 2008
289 query = params.sort.collect do |param|
fc5e7ec r970@mac: glenn | 2006-12-16 14:33:36 -0800
grempe authored Dec 16, 2006
290 CGI::escape(param[0]) + "=" + CGI::escape(param[1])
291 end.join("&") + "&Signature=" + sig
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
292
748ec4d patches for eucalyptus compatibility
Sang-Min Park authored Nov 13, 2010
293 req = Net::HTTP::Post.new(@path)
1f1a53d @grempe Change HTTP API requests to use POST instead of GET.
authored Feb 26, 2008
294 req.content_type = 'application/x-www-form-urlencoded'
5b3a2c0 @grempe MAJOR cleanup of RubyForge cruft all made possible by GitHub gem host…
authored Apr 25, 2008
295 req['User-Agent'] = "github-amazon-ec2-ruby-gem"
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
296
1f1a53d @grempe Change HTTP API requests to use POST instead of GET.
authored Feb 26, 2008
297 response = @http.request(req, query)
fd20977 @grempe Whitespace and RDS_URL.
authored Oct 30, 2009
298
d84bb93 r1567@macbook-pro: glenn | 2007-06-03 23:50:29 -0700
grempe authored Jun 4, 2007
299 # Make a call to see if we need to throw an error based on the response given by EC2
b9c68f6 r1295@mac-mini: glenn | 2007-06-20 14:43:47 -0700
grempe authored Jun 20, 2007
300 # All error classes are defined in EC2/exceptions.rb
7a7f0d0 refactored library so that it can encompass multiple apis, and added …
Kris Rasmussen authored Jul 2, 2009
301 aws_error?(response)
d84bb93 r1567@macbook-pro: glenn | 2007-06-03 23:50:29 -0700
grempe authored Jun 4, 2007
302 return response
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
303
2679389 r962@mac: glenn | 2006-12-14 10:24:38 -0800
grempe authored Dec 14, 2006
304 end
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
305
2679389 r962@mac: glenn | 2006-12-14 10:24:38 -0800
grempe authored Dec 14, 2006
306 end
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
307
fc5e7ec r970@mac: glenn | 2006-12-16 14:33:36 -0800
grempe authored Dec 16, 2006
308 # Set the Authorization header using AWS signed header authentication
2a50f5c @delano Fixed signature for EU region
delano authored Apr 16, 2009
309 def get_aws_auth_param(params, secret_access_key, server)
748ec4d patches for eucalyptus compatibility
Sang-Min Park authored Nov 13, 2010
310 canonical_string = AWS.canonical_string(params, server,"POST", @path)
7a7f0d0 refactored library so that it can encompass multiple apis, and added …
Kris Rasmussen authored Jul 2, 2009
311 encoded_canonical = AWS.encode(secret_access_key, canonical_string)
2679389 r962@mac: glenn | 2006-12-14 10:24:38 -0800
grempe authored Dec 14, 2006
312 end
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
313
861d52f r1641@macbook-pro: glenn | 2007-06-16 12:00:49 -0700
grempe authored Jun 16, 2007
314 # allow us to have a one line call in each method which will do all of the work
315 # in making the actual request to AWS.
316 def response_generator( options = {} )
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
317
861d52f r1641@macbook-pro: glenn | 2007-06-16 12:00:49 -0700
grempe authored Jun 16, 2007
318 options = {
319 :action => "",
320 :params => {}
321 }.merge(options)
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
322
861d52f r1641@macbook-pro: glenn | 2007-06-16 12:00:49 -0700
grempe authored Jun 16, 2007
323 raise ArgumentError, ":action must be provided to response_generator" if options[:action].nil? || options[:action].empty?
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
324
861d52f r1641@macbook-pro: glenn | 2007-06-16 12:00:49 -0700
grempe authored Jun 16, 2007
325 http_response = make_request(options[:action], options[:params])
326 http_xml = http_response.body
6e1d8e2 Removed debug output
Thomas Dudziak authored Oct 15, 2010
327
861d52f r1641@macbook-pro: glenn | 2007-06-16 12:00:49 -0700
grempe authored Jun 16, 2007
328 return Response.parse(:xml => http_xml)
329 end
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
330
d84bb93 r1567@macbook-pro: glenn | 2007-06-03 23:50:29 -0700
grempe authored Jun 4, 2007
331 # Raises the appropriate error if the specified Net::HTTPResponse object
0584b47 @grempe Updated EC2 API version to 2009-10-31
authored Dec 4, 2009
332 # contains an AWS error; returns +false+ otherwise.
7a7f0d0 refactored library so that it can encompass multiple apis, and added …
Kris Rasmussen authored Jul 2, 2009
333 def aws_error?(response)
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
334
d84bb93 r1567@macbook-pro: glenn | 2007-06-03 23:50:29 -0700
grempe authored Jun 4, 2007
335 # return false if we got a HTTP 200 code,
336 # otherwise there is some type of error (40x,50x) and
337 # we should try to raise an appropriate exception
338 # from one of our exception classes defined in
339 # exceptions.rb
340 return false if response.is_a?(Net::HTTPSuccess)
341
d58a13b @grempe Fix #26. Raise an exception immediately if the response is a 5xx Serv…
authored Nov 21, 2010
342 raise AWS::Error, "Unexpected server error. response.body is: #{response.body}" if response.is_a?(Net::HTTPServerError)
343
d84bb93 r1567@macbook-pro: glenn | 2007-06-03 23:50:29 -0700
grempe authored Jun 4, 2007
344 # parse the XML document so we can walk through it
345 doc = REXML::Document.new(response.body)
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
346
d84bb93 r1567@macbook-pro: glenn | 2007-06-03 23:50:29 -0700
grempe authored Jun 4, 2007
347 # Check that the Error element is in the place we would expect.
348 # and if not raise a generic error exception
349 unless doc.root.elements['Errors'].elements['Error'].name == 'Error'
350 raise Error, "Unexpected error format. response.body is: #{response.body}"
351 end
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
352
d84bb93 r1567@macbook-pro: glenn | 2007-06-03 23:50:29 -0700
grempe authored Jun 4, 2007
353 # An valid error response looks like this:
354 # <?xml version="1.0"?><Response><Errors><Error><Code>InvalidParameterCombination</Code><Message>Unknown parameter: foo</Message></Error></Errors><RequestID>291cef62-3e86-414b-900e-17246eccfae8</RequestID></Response>
0584b47 @grempe Updated EC2 API version to 2009-10-31
authored Dec 4, 2009
355 # AWS throws some exception codes that look like Error.SubError. Since we can't name classes this way
d84bb93 r1567@macbook-pro: glenn | 2007-06-03 23:50:29 -0700
grempe authored Jun 4, 2007
356 # we need to strip out the '.' in the error 'Code' and we name the error exceptions with this
357 # non '.' name as well.
358 error_code = doc.root.elements['Errors'].elements['Error'].elements['Code'].text.gsub('.', '')
359 error_message = doc.root.elements['Errors'].elements['Error'].elements['Message'].text
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
360
d84bb93 r1567@macbook-pro: glenn | 2007-06-03 23:50:29 -0700
grempe authored Jun 4, 2007
361 # Raise one of our specific error classes if it exists.
362 # otherwise, throw a generic EC2 Error with a few details.
7a7f0d0 refactored library so that it can encompass multiple apis, and added …
Kris Rasmussen authored Jul 2, 2009
363 if AWS.const_defined?(error_code)
364 raise AWS.const_get(error_code), error_message
d84bb93 r1567@macbook-pro: glenn | 2007-06-03 23:50:29 -0700
grempe authored Jun 4, 2007
365 else
7a7f0d0 refactored library so that it can encompass multiple apis, and added …
Kris Rasmussen authored Jul 2, 2009
366 raise AWS::Error, error_message
d84bb93 r1567@macbook-pro: glenn | 2007-06-03 23:50:29 -0700
grempe authored Jun 4, 2007
367 end
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
368
d84bb93 r1567@macbook-pro: glenn | 2007-06-03 23:50:29 -0700
grempe authored Jun 4, 2007
369 end
deb7d06 Updated to support EC2 API version 2007-08-29 released on 2007-10-16
grempe authored Oct 17, 2007
370
2679389 r962@mac: glenn | 2006-12-14 10:24:38 -0800
grempe authored Dec 14, 2006
371 end
372 end
7a7f0d0 refactored library so that it can encompass multiple apis, and added …
Kris Rasmussen authored Jul 2, 2009
373
ffc499d @grempe Updated all docs to use YARD doc generator and meta tags.
authored Aug 21, 2009
374 Dir[File.join(File.dirname(__FILE__), 'AWS/**/*.rb')].sort.each { |lib| require lib }
375
Something went wrong with that request. Please try again.