Module: AWS

Defined in:
lib/AWS/EC2/images.rb,
lib/AWS.rb,
lib/AWS/EC2.rb,
lib/AWS/ELB.rb,
lib/AWS/responses.rb,
lib/AWS/exceptions.rb,
lib/AWS/EC2/console.rb,
lib/AWS/EC2/volumes.rb,
lib/AWS/EC2/keypairs.rb,
lib/AWS/EC2/products.rb,
lib/AWS/EC2/instances.rb,
lib/AWS/EC2/snapshots.rb,
lib/AWS/EC2/elastic_ips.rb,
lib/AWS/ELB/load_balancers.rb,
lib/AWS/EC2/security_groups.rb,
lib/AWS/EC2/image_attributes.rb,
lib/AWS/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

github.com/grempe/amazon-ec2/tree/master

++

Defined Under Namespace

Modules: EC2, ELB Classes: ArgumentError, AuthFailure, Base, DuplicateLoadBalancerName, Error, InstanceLimitExceeded, InsufficientInstanceCapacity, InternalError, InvalidAMIAttributeItemValue, InvalidAMIIDMalformed, InvalidAMIIDNotFound, InvalidAMIIDUnavailable, InvalidClientTokenId, InvalidConfigurationRequest, InvalidGroupDuplicate, InvalidGroupInUse, InvalidGroupNotFound, InvalidGroupReserved, InvalidInstance, InvalidInstanceIDMalformed, InvalidInstanceIDNotFound, InvalidKeyPairDuplicate, InvalidKeyPairNotFound, InvalidManifest, InvalidParameterCombination, InvalidParameterValue, InvalidPermissionDuplicate, InvalidPermissionMalformed, InvalidReservationIDMalformed, InvalidReservationIDNotFound, InvalidUserIDMalformed, LoadBalancerNotFound, MalformedInput, Response, SignatureDoesNotMatch, TooManyLoadBalancers, Unavailable, UnknownParameter, ValidationError

Class Method Summary collapse

Class Method Details

.canonical_string(params, 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.


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/AWS.rb', line 14

def AWS.canonical_string(params, 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.



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/AWS.rb', line 38

def AWS.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