sensu-settings 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b95af032c4b3a94e59a491db3c04ba24eb8379b0
4
- data.tar.gz: 2e86d492aa3f2f2e8cfb55e078e351a4812a3df6
3
+ metadata.gz: 574e3cda48e7886857ddee4f8dd6b299304726cb
4
+ data.tar.gz: 6cb9b7a031ae185dda7ffc341d80ef6e5497ebd9
5
5
  SHA512:
6
- metadata.gz: 54a52ab2912061d6eca52dc9f4dbfc84c0532cf9b4593275e653272fdaeb62e2989db94783a120eeb1b08c2630cd8567f261b6dec506c55636a4cffb932a5c72
7
- data.tar.gz: b4410e0f99ce6cba6d820ef90e7503147a794001c20fcd476f8ef94cc04169b38bf9e19aa3af504d8dbc0a527d14bcdf70310e191c590cfd552e9303f26ff5b2
6
+ metadata.gz: 7e5136184244c730101a4bb0dd859f4471c3cbe36761e17b0d0b5abba694b0a4c8dde879dd5ca15cea2d262d74eee0544c23bb595da3cf304a1b9456ce2cd263
7
+ data.tar.gz: ab0ee858e81fa3f116b3693a2dc2d616f1463df69a0633ce3c6317fad969584a39e3704a3ac49b32607d5435b398f804f77907c22e8ac38657014c9d1b01dbd6
@@ -4,11 +4,26 @@ module Sensu
4
4
  module Settings
5
5
  # Load Sensu settings.
6
6
  #
7
- # @param options [Hash]
7
+ # @param [Hash] options
8
+ # @option options [String] :config_file to load.
9
+ # @option options [String] :config_dir to load.
10
+ # @option options [Array] :config_dirs to load.
8
11
  # @return [Loader] a loaded instance of Loader.
9
12
  def self.load(options={})
10
13
  loader = Loader.new
11
- loader.load(options)
14
+ loader.load_env
15
+ if options[:config_file]
16
+ loader.load_file(options[:config_file])
17
+ end
18
+ if options[:config_dir]
19
+ loader.load_directory(options[:config_dir])
20
+ end
21
+ if options[:config_dirs]
22
+ options[:config_dirs].each do |directory|
23
+ loader.load_directory(directory)
24
+ end
25
+ end
26
+ loader.set_env!
12
27
  loader
13
28
  end
14
29
  end
@@ -118,29 +118,10 @@ module Sensu
118
118
  # Set Sensu settings related environment variables. This method
119
119
  # currently sets SENSU_CONFIG_FILES, a colon delimited list of
120
120
  # loaded config files.
121
- def set_env
121
+ def set_env!
122
122
  ENV["SENSU_CONFIG_FILES"] = @loaded_files.join(":")
123
123
  end
124
124
 
125
- # Load settings from the environment and the paths provided, set
126
- # appropriate environment variables.
127
- #
128
- # @param [Hash] options
129
- # @option options [String] :config_file to load.
130
- # @option options [String] :config_dir to load.
131
- # @return [Hash] loaded settings.
132
- def load(options={})
133
- load_env
134
- if options[:config_file]
135
- load_file(options[:config_file])
136
- end
137
- if options[:config_dir]
138
- load_directory(options[:config_dir])
139
- end
140
- set_env
141
- to_hash
142
- end
143
-
144
125
  # Validate the loaded settings.
145
126
  #
146
127
  # @return [Array] validation failures.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "sensu-settings"
5
- spec.version = "0.0.1"
5
+ spec.version = "0.0.2"
6
6
  spec.authors = ["Sean Porter"]
7
7
  spec.email = ["portertech@gmail.com"]
8
8
  spec.summary = "The Sensu settings library, loader and validator"
@@ -0,0 +1,9 @@
1
+ {
2
+ "checks": {
3
+ "app_http_endpoint": {
4
+ "command": "check-http.rb -u https://localhost/ping -q pong",
5
+ "standalone": true,
6
+ "interval": 30
7
+ }
8
+ }
9
+ }
data/spec/loader_spec.rb CHANGED
@@ -12,7 +12,7 @@ describe "Sensu::Settings::Loader" do
12
12
  end
13
13
 
14
14
  it "can provide a loader API" do
15
- @loader.should respond_to(:load, :validate!)
15
+ @loader.should respond_to(:load_env, :load_file, :load_directory, :set_env!, :validate!)
16
16
  end
17
17
 
18
18
  it "can provide indifferent access to settings" do
@@ -117,20 +117,17 @@ describe "Sensu::Settings::Loader" do
117
117
  warning[:message].should eq("loading config files from directory")
118
118
  end
119
119
 
120
- it "can load settings from the environment, a file, and a directory" do
121
- ENV["RABBITMQ_URL"] = "amqp://guest:guest@localhost:5672/"
122
- settings = @loader.load(:config_file => @config_file, :config_dir => @config_dir)
123
- settings[:rabbitmq].should eq(ENV["RABBITMQ_URL"])
124
- settings[:api][:port].should eq(4567)
125
- settings[:checks][:merger][:command].should eq("echo -n merger")
126
- settings[:checks][:merger][:subscribers].should eq(["foo", "bar"])
127
- settings[:checks][:nested][:command].should eq("true")
120
+ it "can set environment variables for child processes" do
121
+ @loader.load_file(@config_file)
122
+ @loader.load_directory(@config_dir)
123
+ @loader.loaded_files.size.should eq(3)
124
+ @loader.set_env!
128
125
  ENV["SENSU_CONFIG_FILES"].split(":").should eq(@loader.loaded_files)
129
- ENV["RABBITMQ_URL"] = nil
130
126
  end
131
127
 
132
128
  it "can load settings and determine if certain definitions exist" do
133
- @loader.load(:config_file => @config_file, :config_dir => @config_dir)
129
+ @loader.load_file(@config_file)
130
+ @loader.load_directory(@config_dir)
134
131
  @loader.check_exists?("nonexistent").should be_false
135
132
  @loader.check_exists?("tokens").should be_true
136
133
  @loader.filter_exists?("nonexistent").should be_false
@@ -142,7 +139,8 @@ describe "Sensu::Settings::Loader" do
142
139
  end
143
140
 
144
141
  it "can load settings and provide setting category accessors" do
145
- @loader.load(:config_file => @config_file, :config_dir => @config_dir)
142
+ @loader.load_file(@config_file)
143
+ @loader.load_directory(@config_dir)
146
144
  @loader.checks.should be_kind_of(Array)
147
145
  @loader.checks.should_not be_empty
148
146
  check = @loader.checks.detect do |check|
@@ -4,10 +4,35 @@ require "sensu/settings"
4
4
  describe "Sensu::Settings" do
5
5
  include Helpers
6
6
 
7
+ before do
8
+ @assets_dir = File.join(File.dirname(__FILE__), "assets")
9
+ @config_file = File.join(@assets_dir, "config.json")
10
+ @config_dir = File.join(@assets_dir, "conf.d")
11
+ @app_dir = File.join(@assets_dir, "app")
12
+ end
13
+
7
14
  it "can provide a loader" do
8
15
  Sensu::Settings.should respond_to(:load)
9
16
  Sensu::Settings.load.should be_an_instance_of(Sensu::Settings::Loader)
10
17
  settings = Sensu::Settings.load
11
18
  settings.should respond_to(:validate!)
12
19
  end
20
+
21
+ it "can load settings from the environment, a file, and a directory" do
22
+ ENV["RABBITMQ_URL"] = "amqp://guest:guest@localhost:5672/"
23
+ settings = Sensu::Settings.load(:config_file => @config_file, :config_dir => @config_dir)
24
+ settings[:rabbitmq].should eq(ENV["RABBITMQ_URL"])
25
+ settings[:api][:port].should eq(4567)
26
+ settings[:checks][:merger][:command].should eq("echo -n merger")
27
+ settings[:checks][:merger][:subscribers].should eq(["foo", "bar"])
28
+ settings[:checks][:nested][:command].should eq("true")
29
+ ENV["SENSU_CONFIG_FILES"].split(":").should eq(settings.loaded_files)
30
+ ENV["RABBITMQ_URL"] = nil
31
+ end
32
+
33
+ it "can load settings from files in multiple directories" do
34
+ settings = Sensu::Settings.load(:config_dirs => [@config_dir, @app_dir])
35
+ settings[:checks][:merger][:command].should eq("echo -n merger")
36
+ settings[:checks][:app_http_endpoint][:command].should eq("check-http.rb -u https://localhost/ping -q pong")
37
+ end
13
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Porter
@@ -108,6 +108,7 @@ files:
108
108
  - lib/sensu/settings/validators/subdue.rb
109
109
  - lib/sensu/settings/validators/transport.rb
110
110
  - sensu-settings.gemspec
111
+ - spec/assets/app/config/sensu/app_http_endpoint.json
111
112
  - spec/assets/conf.d/merger.json
112
113
  - spec/assets/conf.d/nested/file.json
113
114
  - spec/assets/config.json
@@ -142,6 +143,7 @@ signing_key:
142
143
  specification_version: 4
143
144
  summary: The Sensu settings library, loader and validator
144
145
  test_files:
146
+ - spec/assets/app/config/sensu/app_http_endpoint.json
145
147
  - spec/assets/conf.d/merger.json
146
148
  - spec/assets/conf.d/nested/file.json
147
149
  - spec/assets/config.json