Fallback to a local configuration if the parsing for remote configuration fails

Fixes #2653
This commit is contained in:
Pier-Hugues Pellerin 2015-02-19 15:09:00 -05:00 committed by Jordan Sissel
parent 6230084c20
commit 786d2d2c1a
2 changed files with 53 additions and 9 deletions

View file

@ -294,17 +294,24 @@ class LogStash::Agent < Clamp::Command
end # def configure_plugin_path
def load_config(path)
begin
uri = URI.parse(path)
uri = URI.parse(path)
case uri.scheme
when nil then
case uri.scheme
when nil then
local_config(path)
when /http/ then
fetch_config(uri)
when "file" then
local_config(uri.path)
else
fail(I18n.t("logstash.agent.configuration.scheme-not-supported", :path => path))
end
rescue URI::InvalidURIError
# fallback for windows.
# if the parsing of the file failed we assume we can reach it locally.
# some relative path on windows arent parsed correctly (.\logstash.conf)
local_config(path)
when /http/ then
fetch_config(uri)
when "file" then
local_config(uri.path)
else
fail(I18n.t("logstash.agent.configuration.scheme-not-supported", :path => path))
end
end

View file

@ -0,0 +1,37 @@
require 'spec_helper'
describe LogStash::Agent do
subject { LogStash::Agent.new('') }
let(:dummy_config) { 'input {}' }
context "when loading the configuration" do
context "when local" do
before { expect(subject).to receive(:local_config).with(path) }
context "unix" do
let(:path) { './test.conf' }
it 'works with relative path' do
subject.load_config(path)
end
end
context "windows" do
let(:path) { '.\test.conf' }
it 'work with relative windows path' do
subject.load_config(path)
end
end
end
context "when remote" do
context 'supported scheme' do
let(:path) { "http://test.local/superconfig.conf" }
before { expect(Net::HTTP).to receive(:get) { dummy_config } }
it 'works with http' do
expect(subject.load_config(path)).to eq("#{dummy_config}\n")
end
end
end
end
end