sensu-settings 9.10.0 → 10.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4130a5c9f9c7f870dade98007e89537935948eaa
4
- data.tar.gz: aa739d99b17cccabfd6acbef823e750cf80ff2f0
3
+ metadata.gz: 72b9dcbda492b08e982b281b94f65be601ef4e5e
4
+ data.tar.gz: 6dc42379262f05d750e47313827550f6987c82ad
5
5
  SHA512:
6
- metadata.gz: f48976092495a8ff65573e8e6ce643a43dee64bdc34fc4975167715027a023dfe6fdff5ffff23382a9383905302ade85d274f475b8899ec3b98b34c86b34d21f
7
- data.tar.gz: ed2ab15c91f45f7b2a62c0ca418937fdf8f037169cfc0888ccc198548add6bd80b20b006c28d2abe7dc0c09491bf403ec6eb85b91f3c525cb1dda13db4da5e3b
6
+ metadata.gz: 7bbd5259d726402435eead658c1d828c1aa468c6749c75792e101ccad16cc3717b94ed0a29142a12259b752efbb6c7d565a9c073c8949e295de324d54a745b41
7
+ data.tar.gz: 8769f81d864f075f38c25a38819f07500e53b1cac93ebda165e384ca8362fe04a068aedc2454b32274bc9209ae9d8ac2b19906ed851de6a6f7ed89f6ebc518dd
@@ -3,6 +3,8 @@ require "sensu/settings/loader"
3
3
  module Sensu
4
4
  module Settings
5
5
  class << self
6
+ attr_accessor :loader
7
+
6
8
  # Load Sensu settings.
7
9
  #
8
10
  # Settings are loaded in following order, prior to validation:
@@ -16,26 +18,23 @@ module Sensu
16
18
  # @option options [Array] :config_dirs to load.
17
19
  # @return [Loader] a loaded instance of Loader.
18
20
  def load(options={})
19
- @loader = Loader.new
20
- @loader.load_env
21
+ loader = Loader.new
22
+ loader.load_env
21
23
  if options[:config_file]
22
- @loader.load_file(options[:config_file], false)
24
+ loader.load_file(options[:config_file], false)
23
25
  end
24
26
  if options[:config_dir]
25
- @loader.load_directory(options[:config_dir])
27
+ loader.load_directory(options[:config_dir])
26
28
  end
27
29
  if options[:config_dirs]
28
30
  options[:config_dirs].each do |directory|
29
- @loader.load_directory(directory)
31
+ loader.load_directory(directory)
30
32
  end
31
33
  end
32
- @loader.load_overrides!
33
- if @loader.validate.empty?
34
- @loader.set_env!
35
- end
36
- @loader
34
+ loader.load_overrides!
35
+ loader
37
36
  rescue Loader::Error
38
- @loader
37
+ loader
39
38
  end
40
39
 
41
40
  # Retrieve the current loaded settings loader or load one up if
@@ -45,7 +44,7 @@ module Sensu
45
44
  # @param [Hash] options to pass to load().
46
45
  # @return [Loader] instance of a loaded loader.
47
46
  def get(options={})
48
- @loader || load(options)
47
+ @loader || @loader = load(options)
49
48
  end
50
49
  end
51
50
  end
@@ -2,6 +2,7 @@ require "sensu/settings/validator"
2
2
  require "sensu/json"
3
3
  require "tmpdir"
4
4
  require "socket"
5
+ require "digest"
5
6
 
6
7
  module Sensu
7
8
  module Settings
@@ -91,6 +92,7 @@ module Sensu
91
92
  def to_hash
92
93
  unless @indifferent_access
93
94
  indifferent_access!
95
+ @hexdigest = nil
94
96
  end
95
97
  @settings
96
98
  end
@@ -104,6 +106,31 @@ module Sensu
104
106
  to_hash[key]
105
107
  end
106
108
 
109
+ # Create a SHA256 hex digest for the settings Hash object. The
110
+ # client definition scope is ignored when the current process is
111
+ # not a Sensu client, as it is essentially ignored and it will
112
+ # likely cause a sum mismatch between two Sensu service systems.
113
+ # This method will not recalculate the hex digest, unless the
114
+ # settings have been altered, determine by the values of
115
+ # `@hexdigest` and `@indifferent_access`.
116
+ #
117
+ # @return [String] SHA256 hex digest.
118
+ def hexdigest
119
+ if @hexdigest && @indifferent_access
120
+ @hexdigest
121
+ else
122
+ hash = case sensu_service_name
123
+ when "client", "rspec"
124
+ to_hash
125
+ else
126
+ to_hash.reject do |key, value|
127
+ key.to_s == "client"
128
+ end
129
+ end
130
+ @hexdigest = Digest::SHA256.hexdigest(hash.to_s)
131
+ end
132
+ end
133
+
107
134
  # Load settings from the environment.
108
135
  #
109
136
  # Loads: SENSU_TRANSPORT_NAME, RABBITMQ_URL, REDIS_URL,
@@ -180,6 +207,7 @@ module Sensu
180
207
  @settings[:client][:subscriptions] << "client:#{@settings[:client][:name]}"
181
208
  @settings[:client][:subscriptions].uniq!
182
209
  warning("applied sensu client overrides", :client => @settings[:client])
210
+ @indifferent_access = false
183
211
  else
184
212
  warning("unable to apply sensu client overrides", {
185
213
  :reason => "client subscriptions is not an array",
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "sensu-settings"
5
- spec.version = "9.10.0"
5
+ spec.version = "10.0.0"
6
6
  spec.authors = ["Sean Porter"]
7
7
  spec.email = ["portertech@gmail.com"]
8
8
  spec.summary = "The Sensu settings library, loader and validator"
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: 9.10.0
4
+ version: 10.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Porter