Class: Elasticsearch::Transport::Transport::HTTP::AWS

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/logstash/outputs/amazon_es/aws_transport.rb

Overview

Transport implementation, which V4 Signs requests using the [Faraday](rubygems.org/gems/faraday) library for abstracting the HTTP client.

See Also:

  • Transport::Base

Defined Under Namespace

Classes: CredentialConfig

Constant Summary collapse

DEFAULT_PORT =
80
DEFAULT_PROTOCOL =
"http"

Instance Method Summary collapse

Instance Method Details

#__build_connectionsConnections::Collection

Builds and returns a collection of connections.

Returns:

  • (Connections::Collection)


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/logstash/outputs/amazon_es/aws_transport.rb', line 63

def __build_connections
  region = options[:region]
  access_key_id = options[:aws_access_key_id] || nil
  secret_access_key = options[:aws_secret_access_key] || nil
  session_token = options[:session_token] || nil
  profile = options[:profile] || 'default'
  instance_cred_retries = options[:instance_profile_credentials_retries] || 0
  instance_cred_timeout = options[:instance_profile_credentials_timeout] || 1
  
  credential_config = CredentialConfig.new(access_key_id, secret_access_key, session_token, profile,
                                           instance_cred_retries, instance_cred_timeout, region)
  credentials = Aws::CredentialProviderChain.new(credential_config).resolve

  Connections::Collection.new \
    :connections => hosts.map { |host|
      host[:protocol]   = host[:scheme] || DEFAULT_PROTOCOL
      host[:port]     ||= DEFAULT_PORT
      url               = __full_url(host)
                        
      aes_connection = ::Faraday::Connection.new(url,  (options[:transport_options] || {})) do |faraday|
        faraday.request :aws_v4_signer,
                              credentials: credentials,
                              service_name: 'es',
                              region: region
        faraday.adapter :manticore
      end
      
      Connections::Connection.new \
        :host => host,
        :connection => aes_connection
    },
    :selector_class => options[:selector_class],
    :selector => options[:selector]
end

#host_unreachable_exceptionsArray

Returns an array of implementation specific connection errors.

Returns:

  • (Array)


102
103
104
# File 'lib/logstash/outputs/amazon_es/aws_transport.rb', line 102

def host_unreachable_exceptions
  [::Faraday::Error::ConnectionFailed, ::Faraday::Error::TimeoutError]
end

#perform_request(method, path, params = {}, body = nil) ⇒ Response

Performs the request by invoking Transport::Base#perform_request with a block.

Returns:

  • (Response)

See Also:

  • Transport::Base#perform_request


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/logstash/outputs/amazon_es/aws_transport.rb', line 47

def perform_request(method, path, params={}, body=nil)
  super do |connection, url|
    response = connection.connection.run_request \
     method.downcase.to_sym,
      url,
      ( body ? __convert_to_json(body) : nil ),
      {}

    Response.new response.status, response.body, response.headers
  end
end