mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
(cherry picked from commit 022072c437
)
This commit is contained in:
parent
4f6419fd1c
commit
fb68365e45
3 changed files with 46 additions and 1 deletions
|
@ -118,7 +118,14 @@ module LogStash module Filters module Geoip class DownloadManager
|
|||
end
|
||||
|
||||
def rest_client
|
||||
@client ||= Manticore::Client.new(request_timeout: 15, connect_timeout: 5)
|
||||
@client ||= begin
|
||||
client_options = {
|
||||
request_timeout: 15,
|
||||
connect_timeout: 5
|
||||
}
|
||||
client_options[:proxy]=ENV['http_proxy'] if ENV.include?('http_proxy')
|
||||
Manticore::Client.new(client_options)
|
||||
end
|
||||
end
|
||||
|
||||
def uuid
|
||||
|
|
|
@ -39,6 +39,18 @@ describe LogStash::Filters::Geoip do
|
|||
expect(download_manager).to receive(:service_endpoint).and_return(bad_uri).twice
|
||||
expect { download_manager.send(:check_update) }.to raise_error(LogStash::Filters::Geoip::DownloadManager::BadResponseCodeError, /404/)
|
||||
end
|
||||
|
||||
context "when ENV['http_proxy'] is set" do
|
||||
let(:proxy_url) { 'http://user:pass@example.com:1234' }
|
||||
|
||||
around(:each) { |example| with_environment('http_proxy' => proxy_url, &example) }
|
||||
|
||||
it "initializes the client with the proxy" do
|
||||
expect(::Manticore::Client).to receive(:new).with(a_hash_including(:proxy => proxy_url)).and_call_original
|
||||
|
||||
download_manager.send(:rest_client)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "check update" do
|
||||
|
|
|
@ -47,6 +47,32 @@ def apply_settings(settings_values, settings = nil)
|
|||
settings
|
||||
end
|
||||
|
||||
##
|
||||
# yields to the provided block with the ENV modified by
|
||||
# the provided overrides. Values given as `nil` will be deleted
|
||||
# if present in the base ENV.
|
||||
#
|
||||
# @param replacement [Hash{String=>[String,nil]}]
|
||||
def with_environment(overrides)
|
||||
replacement = ENV.to_hash
|
||||
.merge(overrides)
|
||||
.reject { |_,v| v.nil? }
|
||||
|
||||
with_environment!(replacement) { yield }
|
||||
end
|
||||
|
||||
##
|
||||
# yields to the provided block with the ENV replaced
|
||||
# @param replacement [Hash{String=>String}]
|
||||
def with_environment!(replacement)
|
||||
original = ENV.to_hash.dup.freeze
|
||||
ENV.replace(replacement)
|
||||
|
||||
yield
|
||||
ensure
|
||||
ENV.replace(original)
|
||||
end
|
||||
|
||||
def start_agent(agent)
|
||||
agent_task = Stud::Task.new do
|
||||
begin
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue