Module: RightAws::RightAwsBaseInterface

Included in:
Ec2, S3Interface, SqsInterface
Defined in:
lib/awsbase/right_awsbase.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#aws_access_key_idObject (readonly)

Current aws_access_key_id



79
80
81
# File 'lib/awsbase/right_awsbase.rb', line 79

def aws_access_key_id
  @aws_access_key_id
end

#last_errorsObject

Last AWS errors list (used by AWSErrorHandler)



85
86
87
# File 'lib/awsbase/right_awsbase.rb', line 85

def last_errors
  @last_errors
end

#last_requestObject (readonly)

Last HTTP request object



81
82
83
# File 'lib/awsbase/right_awsbase.rb', line 81

def last_request
  @last_request
end

#last_request_idObject

Last AWS request id (used by AWSErrorHandler)



87
88
89
# File 'lib/awsbase/right_awsbase.rb', line 87

def last_request_id
  @last_request_id
end

#last_responseObject (readonly)

Last HTTP response object



83
84
85
# File 'lib/awsbase/right_awsbase.rb', line 83

def last_response
  @last_response
end

#loggerObject

Logger object



89
90
91
# File 'lib/awsbase/right_awsbase.rb', line 89

def logger
  @logger
end

#paramsObject

Initial params hash



91
92
93
# File 'lib/awsbase/right_awsbase.rb', line 91

def params
  @params
end

Instance Method Details

#init(service_info, aws_access_key_id, aws_secret_access_key, params = {}) ⇒ Object

:nodoc:

Raises:



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/awsbase/right_awsbase.rb', line 93

def init(service_info, aws_access_key_id, aws_secret_access_key, params={}) #:nodoc:
  @params = params
  raise AwsError.new("AWS access keys are required to operate on #{service_info[:name]}") \
    if aws_access_key_id.blank? || aws_secret_access_key.blank?
  @aws_access_key_id     = aws_access_key_id
  @aws_secret_access_key = aws_secret_access_key
  @params[:server]       ||= service_info[:default_host]
  @params[:port]         ||= service_info[:default_port]
  @params[:protocol]     ||= service_info[:default_protocol]
  @params[:multi_thread] ||= defined?(AWS_DAEMON)
  @logger = @params[:logger]
  @logger = RAILS_DEFAULT_LOGGER if !@logger && defined?(RAILS_DEFAULT_LOGGER)
  @logger = Logger.new(STDOUT)   if !@logger
  @logger.info "New #{self.class.name} using #{@params[:multi_thread] ? 'multi' : 'single'}-threaded mode"
  @error_handler = nil
end

#multi_threadObject

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



115
116
117
# File 'lib/awsbase/right_awsbase.rb', line 115

def multi_thread
  @params[:multi_thread]
end

#on_exception(options = {:raise=>true, :log=>true}) ⇒ Object

:nodoc:



110
111
112
# File 'lib/awsbase/right_awsbase.rb', line 110

def on_exception(options={:raise=>true, :log=>true}) # :nodoc:
  AwsError::on_aws_exception(self, options)
end

#request_info_impl(connection, benchblock, request, parser, &block) ⇒ Object

:nodoc:



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/awsbase/right_awsbase.rb', line 119

def request_info_impl(connection, benchblock, request, parser, &block) #:nodoc:
  @last_request  = request[:request]
  @last_response = nil
  response=nil
  blockexception = nil

  if(block != nil)
    # TRB 9/17/07 Careful - because we are passing in blocks, we get a situation where
    # an exception may get thrown in the block body (which is high-level
    # code either here or in the application) but gets caught in the
    # low-level code of HttpConnection.  The solution is not to let any
    # exception escape the block that we pass to HttpConnection::request.
    # Exceptions can originate from code directly in the block, or from user
    # code called in the other block which is passed to response.read_body.
    benchblock.service.add! do
      responsehdr = connection.request(request) do |response|
      #########
        begin
          @last_response = response
          if response.is_a?(Net::HTTPSuccess)
            @error_handler = nil
            response.read_body(&block)
          else
            @error_handler = AWSErrorHandler.new(self, parser, self.class.amazon_problems) unless @error_handler
            check_result   = @error_handler.check(request)
            if check_result
              @error_handler = nil
              return check_result 
            end
            raise AwsError.new(@last_errors, @last_response.code, @last_request_id)
          end
        rescue Exception => e
          blockexception = e
        end
      end
      #########

      #OK, now we are out of the block passed to the lower level
      if(blockexception)
        raise blockexception
      end
      benchblock.xml.add! do
        parser.parse(responsehdr)
      end
      return parser.result
    end
  else
    benchblock.service.add!{ response = connection.request(request) }
      # check response for errors...
    @last_response = response
    if response.is_a?(Net::HTTPSuccess)
      @error_handler = nil
      benchblock.xml.add! { parser.parse(response) }
      return parser.result
    else
      @error_handler = AWSErrorHandler.new(self, parser, self.class.amazon_problems) unless @error_handler
      check_result   = @error_handler.check(request)
      if check_result
        @error_handler = nil
        return check_result 
      end
      raise AwsError.new(@last_errors, @last_response.code, @last_request_id)
    end
  end
rescue
  @error_handler = nil
  raise
end