Module: EC2
- Defined in:
- lib/EC2/images.rb,
lib/EC2.rb,
lib/EC2/console.rb,
lib/EC2/volumes.rb,
lib/EC2/keypairs.rb,
lib/EC2/products.rb,
lib/EC2/instances.rb,
lib/EC2/responses.rb,
lib/EC2/snapshots.rb,
lib/EC2/exceptions.rb,
lib/EC2/elastic_ips.rb,
lib/EC2/security_groups.rb,
lib/EC2/image_attributes.rb,
lib/EC2/availability_zones.rb
Overview
– Amazon Web Services EC2 Query API Ruby library
- Ruby Gem Name
-
amazon-ec2
- Author
-
Glenn Rempe ([email protected])
- Copyright
-
Copyright © 2007-2008 Glenn Rempe
- License
-
Distributes under the same terms as Ruby
- Home
++
Defined Under Namespace
Classes: ArgumentError, AuthFailure, Base, Error, InstanceLimitExceeded, InsufficientInstanceCapacity, InternalError, InvalidAMIAttributeItemValue, InvalidAMIIDMalformed, InvalidAMIIDNotFound, InvalidAMIIDUnavailable, InvalidClientTokenId, InvalidGroupDuplicate, InvalidGroupInUse, InvalidGroupNotFound, InvalidGroupReserved, InvalidInstanceIDMalformed, InvalidInstanceIDNotFound, InvalidKeyPairDuplicate, InvalidKeyPairNotFound, InvalidManifest, InvalidParameterCombination, InvalidParameterValue, InvalidPermissionDuplicate, InvalidPermissionMalformed, InvalidReservationIDMalformed, InvalidReservationIDNotFound, InvalidUserIDMalformed, Response, SignatureDoesNotMatch, Unavailable, UnknownParameter
Constant Summary collapse
- EC2_URL =
ENV['EC2_URL']
- VALID_HOSTS =
['https://ec2.amazonaws.com', 'https://us-east-1.ec2.amazonaws.com', 'https://eu-west-1.ec2.amazonaws.com']
- DEFAULT_HOST =
default US host
'ec2.amazonaws.com'
- API_VERSION =
This is the version of the API as defined by Amazon Web Services
'2008-12-01'
Class Method Summary collapse
-
.canonical_string(params, host = DEFAULT_HOST, method = "POST", base = "/") ⇒ Object
Builds the canonical string for signing.
-
.encode(secret_access_key, str, urlencode = true) ⇒ Object
Encodes the given string with the secret_access_key, by taking the hmac-sha1 sum, and then base64 encoding it.
Class Method Details
.canonical_string(params, host = DEFAULT_HOST, method = "POST", base = "/") ⇒ Object
Builds the canonical string for signing. This strips out all ‘&’, ‘?’, and ‘=’ from the query string to be signed.
Note: The parameters in the path passed in must already be sorted in
case-insensitive alphabetical order and must not be url encoded.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/EC2.rb', line 43 def EC2.canonical_string(params, host = DEFAULT_HOST, method="POST", base="/") # Sort, and encode parameters into a canonical string. sorted_params = params.sort {|x,y| x[0] <=> y[0]} encoded_params = sorted_params.collect do |p| encoded = (CGI::escape(p[0].to_s) + "=" + CGI::escape(p[1].to_s)) # Ensure spaces are encoded as '%20', not '+' encoded.gsub('+', '%20') end sigquery = encoded_params.join("&") # Generate the request description string req_desc = method + "\n" + host + "\n" + base + "\n" + sigquery end |
.encode(secret_access_key, str, urlencode = true) ⇒ Object
Encodes the given string with the secret_access_key, by taking the hmac-sha1 sum, and then base64 encoding it. Optionally, it will also url encode the result of that to protect the string if it’s going to be used as a query string parameter.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/EC2.rb', line 67 def EC2.encode(secret_access_key, str, urlencode=true) digest = OpenSSL::Digest::Digest.new('sha1') b64_hmac = Base64.encode64( OpenSSL::HMAC.digest(digest, secret_access_key, str)).gsub("\n","") if urlencode return CGI::escape(b64_hmac) else return b64_hmac end end |