Class: RightScale::CloudApi::RequestInitializer

Inherits:
Routine show all
Defined in:
lib/base/routines/request_initializer.rb

Overview

The routine adds a random token to all the GET requests if the corresponding option is enabled.

Instance Attribute Summary

Attributes inherited from Routine

#data

Instance Method Summary collapse

Methods inherited from Routine

#cloud_api_logger, #execute, #invoke_callback_method, #options, #reset, #with_timer

Instance Method Details

#processObject

Initializes things we may need to initialize.

Sometimes we may need to add a random token for every request so that remote cloud. This may be needed when the cloud caches responses for similar requests. Lets say you listed instances then created one and then listed them again. S-me clouds (rackspace) may start to report the new seconds after it was created because of the caching they do.

But if we mix something random onto every request then 2 consecutive list instances calls will look like they are different and the cloud wont return the cached data.



41
42
43
44
45
46
47
48
# File 'lib/base/routines/request_initializer.rb', line 41

def process
  # Add a random thing to every get request
  if data[:request][:verb] == :get && !data[:options][:random_token]._blank?
    random_token_name = 'rsrcarandomtoken'
    random_token_name = data[:options][:random_token].to_s if [String, Symbol].include?(data[:options][:random_token].class)
    data[:request][:params][random_token_name] = Utils::generate_token
  end
end