From d2aa09150e177fd0f852851166c39df0d3a4b683 Mon Sep 17 00:00:00 2001 From: Rob Wilson Date: Mon, 13 Jul 2015 12:07:18 +0100 Subject: [PATCH 1/3] permit symlinks in config directory --- lib/sensu/settings/loader.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sensu/settings/loader.rb b/lib/sensu/settings/loader.rb index 4007891..9caa1f9 100644 --- a/lib/sensu/settings/loader.rb +++ b/lib/sensu/settings/loader.rb @@ -124,7 +124,7 @@ def load_file(file) def load_directory(directory) warning("loading config files from directory", :directory => directory) path = directory.gsub(/\\(?=\S)/, "/") - Dir.glob(File.join(path, "**/*.json")).each do |file| + Dir.glob(File.join(path, "**{,/*/**}/*.json")).each do |file| load_file(file) end end From d6f7aacf669059407c345f917ebd09b3afd1b70e Mon Sep 17 00:00:00 2001 From: Rob Wilson Date: Tue, 14 Jul 2015 22:56:39 +0100 Subject: [PATCH 2/3] update tests --- lib/sensu/settings/loader.rb | 2 +- spec/assets/alternative/conf.d/symlinked.json | 11 +++++++++++ spec/assets/conf.d/alternative | 1 + spec/loader_spec.rb | 4 ++-- 4 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 spec/assets/alternative/conf.d/symlinked.json create mode 120000 spec/assets/conf.d/alternative diff --git a/lib/sensu/settings/loader.rb b/lib/sensu/settings/loader.rb index 9caa1f9..de20821 100644 --- a/lib/sensu/settings/loader.rb +++ b/lib/sensu/settings/loader.rb @@ -124,7 +124,7 @@ def load_file(file) def load_directory(directory) warning("loading config files from directory", :directory => directory) path = directory.gsub(/\\(?=\S)/, "/") - Dir.glob(File.join(path, "**{,/*/**}/*.json")).each do |file| + Dir.glob(File.join(path, "**{,/*/**}/*.json")).uniq.each do |file| load_file(file) end end diff --git a/spec/assets/alternative/conf.d/symlinked.json b/spec/assets/alternative/conf.d/symlinked.json new file mode 100644 index 0000000..0fb3f9e --- /dev/null +++ b/spec/assets/alternative/conf.d/symlinked.json @@ -0,0 +1,11 @@ +{ + "checks": { + "symlinked": { + "command": "echo -n symlinked", + "subscribers": [ + "baz" + ], + "interval": 60 + } + } +} diff --git a/spec/assets/conf.d/alternative b/spec/assets/conf.d/alternative new file mode 120000 index 0000000..506c23d --- /dev/null +++ b/spec/assets/conf.d/alternative @@ -0,0 +1 @@ +../alternative/conf.d/ \ No newline at end of file diff --git a/spec/loader_spec.rb b/spec/loader_spec.rb index 84bf641..5009779 100644 --- a/spec/loader_spec.rb +++ b/spec/loader_spec.rb @@ -139,7 +139,7 @@ it "can load settings from files in a directory" do @loader.load_directory(@config_dir) warnings = @loader.warnings - expect(warnings.size).to eq(4) + expect(warnings.size).to eq(6) messages = warnings.map do |warning| warning[:message] end @@ -159,7 +159,7 @@ it "can set environment variables for child processes" do @loader.load_file(@config_file) @loader.load_directory(@config_dir) - expect(@loader.loaded_files.size).to eq(3) + expect(@loader.loaded_files.size).to eq(4) @loader.set_env! expect(ENV["SENSU_LOADED_TEMPFILE"]).to match(/sensu_rspec_loaded_files/) loaded_files = IO.read(ENV["SENSU_LOADED_TEMPFILE"]) From 902c978829af1677fec3b41256b1d1709ec52834 Mon Sep 17 00:00:00 2001 From: Rob Wilson Date: Mon, 20 Jul 2015 18:33:37 +0100 Subject: [PATCH 3/3] create symlink in a directory loop to confirm config loading symlink support doesn't add possibility of causing an infinite loop --- spec/assets/alternative/conf.d/loop | 1 + 1 file changed, 1 insertion(+) create mode 120000 spec/assets/alternative/conf.d/loop diff --git a/spec/assets/alternative/conf.d/loop b/spec/assets/alternative/conf.d/loop new file mode 120000 index 0000000..e5ef02d --- /dev/null +++ b/spec/assets/alternative/conf.d/loop @@ -0,0 +1 @@ +../conf.d \ No newline at end of file