module RightAws::RightAwsBaseInterface
Constants
- DEFAULT_SIGNATURE_VERSION
Attributes
aws_access_key_id[R]
Current #aws_access_key_id
aws_secret_access_key[R]
Current #aws_secret_access_key
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 191 def self.caching @@caching end
caching=(caching)
click to toggle source
# File lib/awsbase/right_awsbase.rb, line 194 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 ifdo_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 279 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) # feb 04, 2009 (load balancer uses 'RequestId' hence use 'i' modifier to hit it also) response = response.sub(%r{<requestId>.+?</requestId>}i, '') 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 270 def caching? @params.key?(:cache) ? @params[:cache] : @@caching end
get_connection(aws_service, request)
click to toggle source
# File lib/awsbase/right_awsbase.rb, line 363 def get_connection(aws_service, request) #:nodoc server_url = "#{request[:protocol]}://#{request[:server]}:#{request[:port]}}" # case @params[:connections].to_s when 'dedicated' @connections_storage ||= {} else # 'dedicated' @connections_storage = (Thread.current[aws_service] ||= {}) end # @connections_storage[server_url] ||= {} @connections_storage[server_url][:last_used_at] = Time.now @connections_storage[server_url][:connection] ||= Rightscale::HttpConnection.new(:exception => RightAws::AwsError, :logger => @logger) # keep X most recent connections (but were used not far than Y minutes ago) connections = 0 @connections_storage.to_a.sort{|i1, i2| i2[1][:last_used_at] <=> i1[1][:last_used_at]}.to_a.each do |i| if i[0] != server_url && (@params[:max_connections] <= connections || i[1][:last_used_at] < Time.now - @params[:connection_lifetime]) # delete the connection from the list @connections_storage.delete(i[0]) # then finish it i[1][:connection].finish((@params[:max_connections] <= connections) ? "out-of-limit" : "out-of-date") rescue nil else connections += 1 end end @connections_storage[server_url][:connection] 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 260 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 309 def update_cache(function, hash) (@cache[function.to_sym] ||= {}).merge!(hash) if caching? end