sensu-settings 3.2.0 → 3.3.0

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: a2a3bc1839a6bb401f3c669c081d03416855d502
4
- data.tar.gz: a7741e0e1e8f4a0a836cc45f00c88617dded54f3
3
+ metadata.gz: 59c86f090d9e6b164204356e7d7924f72163e6b6
4
+ data.tar.gz: d28b6cced806d5e0283697f5819dff25c227f85d
5
5
  SHA512:
6
- metadata.gz: 1dd681e6a477fd9321b4daaaf2340d8bf7d31eda31e90ac2686a805c5cab55f6ae5150b16a9be553799ebca5df7a6e840a7c7a5853190fce6d1ff6946eed22d8
7
- data.tar.gz: 0847523f88e6ae486a6efcfe3e4690db7d49ece84ba8272b48851eb9bb68c0bb2ce074c8b6a522be9958fe058aebac39cc3acf5137a9f703347448ea6af347f4
6
+ metadata.gz: 0249f3b2e216d465ac811e883760ad3c055a6baeedf7c5ddd86632b2692b1550262e246d2d1ae06b976c375aaeb2379d898e7d37ce6b5100bf30708a552ce2da
7
+ data.tar.gz: b14a67f57e2184907f07e98f21081f66f3decbe90e3bbbf10a6c1e9f55cd4fff56871ced058409758733dbc23b5882a8deaeb82990ce0a2d52d2b310247c164e
@@ -105,6 +105,33 @@ module Sensu
105
105
  invalid(client, "client signature must be a string")
106
106
  end
107
107
 
108
+ # Validate client registration handlers.
109
+ # Validates: registration (handler, handlers)
110
+ #
111
+ # @param client [Hash] sensu client definition.
112
+ def validate_client_registration_handlers(client)
113
+ must_be_a_string_if_set(client[:registration][:handler]) ||
114
+ invalid(client, "client registration handler must be a string")
115
+ must_be_an_array_if_set(client[:registration][:handlers]) ||
116
+ invalid(client, "client registration handlers must be an array")
117
+ if is_an_array?(client[:registration][:handlers])
118
+ items_must_be_strings(client[:registration][:handlers]) ||
119
+ invalid(client, "client registration handlers must each be a string")
120
+ end
121
+ end
122
+
123
+ # Validate client registration.
124
+ # Validates: registration
125
+ #
126
+ # @param client [Hash] sensu client definition.
127
+ def validate_client_registration(client)
128
+ must_be_a_hash_if_set(client[:registration]) ||
129
+ invalid(client, "client registration must be a hash")
130
+ if is_a_hash?(client[:registration])
131
+ validate_client_registration_handlers(client)
132
+ end
133
+ end
134
+
108
135
  # Validate a Sensu client definition.
109
136
  # Validates: name, address, safe_mode
110
137
  #
@@ -125,6 +152,7 @@ module Sensu
125
152
  validate_client_keepalive(client)
126
153
  validate_client_redact(client)
127
154
  validate_client_signature(client)
155
+ validate_client_registration(client)
128
156
  end
129
157
  end
130
158
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "sensu-settings"
5
- spec.version = "3.2.0"
5
+ spec.version = "3.3.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"
@@ -604,6 +604,37 @@ describe "Sensu::Settings::Validator" do
604
604
  expect(@validator.reset).to eq(0)
605
605
  end
606
606
 
607
+ it "can validate client registration" do
608
+ client = {
609
+ :name => "foo",
610
+ :address => "127.0.0.1",
611
+ :subscriptions => ["bar"]
612
+ }
613
+ @validator.validate_client(client)
614
+ expect(@validator.reset).to eq(0)
615
+ client[:registration] = true
616
+ @validator.validate_client(client)
617
+ expect(@validator.reset).to eq(1)
618
+ client[:registration] = {}
619
+ @validator.validate_client(client)
620
+ expect(@validator.reset).to eq(0)
621
+ client[:registration][:handler] = 1
622
+ @validator.validate_client(client)
623
+ expect(@validator.reset).to eq(1)
624
+ client[:registration][:handler] = "foo"
625
+ @validator.validate_client(client)
626
+ expect(@validator.reset).to eq(0)
627
+ client[:registration][:handlers] = 1
628
+ @validator.validate_client(client)
629
+ expect(@validator.reset).to eq(1)
630
+ client[:registration][:handlers] = [1]
631
+ @validator.validate_client(client)
632
+ expect(@validator.reset).to eq(1)
633
+ client[:registration][:handlers] = ["foo"]
634
+ @validator.validate_client(client)
635
+ expect(@validator.reset).to eq(0)
636
+ end
637
+
607
638
  it "can run, validating client" do
608
639
  settings = {
609
640
  :client => {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Porter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-28 00:00:00.000000000 Z
11
+ date: 2016-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -157,4 +157,3 @@ test_files:
157
157
  - spec/rules_spec.rb
158
158
  - spec/settings_spec.rb
159
159
  - spec/validator_spec.rb
160
- has_rdoc: