spec/es_helper.rb in logstash-input-elasticsearch-4.3.3 vs spec/es_helper.rb in logstash-input-elasticsearch-4.4.0

- old
+ new

@@ -1,12 +1,31 @@ module ESHelper def self.get_host_port - return "http://elasticsearch:9200" if ENV["INTEGRATION"] == "true" + return "elasticsearch:9200" if ENV["INTEGRATION"] == "true" || ENV["SECURE_INTEGRATION"] == "true" raise "This setting is only used for integration tests" end - def self.get_client - Elasticsearch::Client.new(:hosts => [get_host_port]) + def self.get_client(options = {}) + ssl_options = {} + hosts = [get_host_port] + + if options[:ca_file] + ssl_options = { :ssl => true, :ca_file => options[:ca_file] } + hosts.map! do |h| + host, port = h.split(":") + { :host => host, :scheme => 'https', :port => port } + end + end + + transport_options = {} + + if options[:user] && options[:password] + token = Base64.strict_encode64("#{options[:user]}:#{options[:password]}") + transport_options[:headers] = { :Authorization => "Basic #{token}" } + end + + @client = Elasticsearch::Client.new(:hosts => hosts, :transport_options => transport_options, :ssl => ssl_options, + :transport_class => ::Elasticsearch::Transport::Transport::HTTP::Manticore) end def self.doc_type if ESHelper.es_version_satisfies?(">=8") nil \ No newline at end of file