RightAws::RightAwsBaseInterface

Attributes

aws_access_key_id[R]
cache[R]

Cache

connection[R]

RightHttpConnection instance

last_errors[RW]

Last AWS errors list (used by AWSErrorHandler)

last_request[R]

Last HTTP request object

last_request_id[RW]

Last AWS request id (used by AWSErrorHandler)

last_response[R]

Last HTTP response object

logger[RW]

Logger object

params[RW]

Initial params hash

signature_version[R]

Signature version (all services except s3)

Public Class Methods

caching() click to toggle source
# File lib/awsbase/right_awsbase.rb, line 177
def self.caching
  @@caching
end
caching=(caching) click to toggle source
# File lib/awsbase/right_awsbase.rb, line 180
def self.caching=(caching)
  @@caching = caching
end

Public Instance Methods

cache_hits?(function, response, do_raise=:raise) click to toggle source

Check if the aws function response hits the cache or not. If the cache hits:

  • raises an AwsNoChange exception if do_raise == :raise.

  • returnes parsed response from the cache if it exists or true otherwise.

If the cache miss or the caching is off then returns false.

# File lib/awsbase/right_awsbase.rb, line 254
def cache_hits?(function, response, do_raise=:raise)
  result = false
  if caching?
    function = function.to_sym
    # get rid of requestId (this bad boy was added for API 2008-08-08+ and it is uniq for every response)
    response = response.sub(%{<requestId>.+?</requestId>}, '')
    response_md5 = MD5.md5(response).to_s
    # check for changes
    unless @cache[function] && @cache[function][:response_md5] == response_md5
      # well, the response is new, reset cache data
      update_cache(function, {:response_md5 => response_md5, 
                              :timestamp    => Time.now, 
                              :hits         => 0, 
                              :parsed       => nil})
    else
      # aha, cache hits, update the data and throw an exception if needed
      @cache[function][:hits] += 1
      if do_raise == :raise
        raise(AwsNoChange, "Cache hit: #{function} response has not changed since "+
                           "#{@cache[function][:timestamp].strftime('%Y-%m-%d %H:%M:%S')}, "+
                           "hits: #{@cache[function][:hits]}.")
      else
        result = @cache[function][:parsed] || true
      end
    end
  end
  result
end
caching?() click to toggle source

Returns true if the describe_xxx responses are being cached

# File lib/awsbase/right_awsbase.rb, line 245
def caching?
  @params.key?(:cache) ? @params[:cache] : @@caching
end
multi_thread() click to toggle source

Return true if this instance works in multi_thread mode and false otherwise.

# File lib/awsbase/right_awsbase.rb, line 293
def multi_thread
  @params[:multi_thread]
end
signed_service_params(aws_secret_access_key, service_hash, http_verb=nil, host=nil, service=nil ) click to toggle source
# File lib/awsbase/right_awsbase.rb, line 235
def signed_service_params(aws_secret_access_key, service_hash, http_verb=nil, host=nil, service=nil )
  case signature_version.to_s
  when '0' then AwsUtils::sign_request_v0(aws_secret_access_key, service_hash)
  when '1' then AwsUtils::sign_request_v1(aws_secret_access_key, service_hash)
  when '2' then AwsUtils::sign_request_v2(aws_secret_access_key, service_hash, http_verb, host, service)
  else raise AwsError.new("Unknown signature version (#{signature_version.to_s}) requested")
  end
end
update_cache(function, hash) click to toggle source
# File lib/awsbase/right_awsbase.rb, line 283
def update_cache(function, hash)
  (@cache[function.to_sym] ||= {}).merge!(hash) if caching?
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.