sensu-settings 1.3.0 → 1.4.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: b52b0d7d44f148e43deac0e2450f8e023bc5a6f3
4
- data.tar.gz: f9b954ae820cc6256c3ea5981ec2b4fd8b8e9655
3
+ metadata.gz: d07bac3d033762f1692fc77a8ee78cfa93b8af23
4
+ data.tar.gz: d51b987e700c9aaa9da75d4486e875acdecbd35f
5
5
  SHA512:
6
- metadata.gz: 08b52a7c91d24a07b79e116d628bbfe591f5396c43abe6632f4bce65f7c3793eeae5f447b226690076122caf72587e25cb56d9c1b645a7d84d4745dbeda374da
7
- data.tar.gz: c5f8afca71385402593b9615b976086218f439504c95fa0b9b2debf64e22e58f54c4cb384d470d7de9cdaa5ed03b3bbc2292b59d803b1992c7d177858037fec6
6
+ metadata.gz: abf335edc0f6cb4174bf52c1c2a9c3241cca29db316e6ce27d19bcd948d981ff5d5fc20da4cc7314ec39f8d3ea5a7d49d7b12d97d2b0b1d633819af29b76804b
7
+ data.tar.gz: 440a5744b1bcc636f4ed3b59582918c94c24714c165a62d74b668416c2bfcb68d869d08d12f38cb62a39c2f90fefdda1502ad7e5bb682471a67229d8df13d608
@@ -42,6 +42,7 @@ module Sensu
42
42
  def must_be_a_string(value)
43
43
  value.is_a?(String)
44
44
  end
45
+ alias_method :is_a_string?, :must_be_a_string
45
46
 
46
47
  # Check that a value is a string, if set (not nil).
47
48
  #
@@ -2,6 +2,19 @@ module Sensu
2
2
  module Settings
3
3
  module Validators
4
4
  module Check
5
+ # Validate check source.
6
+ # Validates: source
7
+ #
8
+ # @param check [Hash] sensu check definition.
9
+ def validate_check_source(check)
10
+ if is_a_string?(check[:source])
11
+ must_match_regex(/^[\w\.-]+$/, check[:source]) ||
12
+ invalid(check, "check source cannot contain spaces or special characters")
13
+ else
14
+ invalid(check, "check source must be a string")
15
+ end
16
+ end
17
+
5
18
  # Validate check scheduling.
6
19
  # Validates: interval, standalone, subscribers
7
20
  #
@@ -69,14 +82,11 @@ module Sensu
69
82
  invalid(check, "either check command or extension must be set")
70
83
  must_be_a_numeric_if_set(check[:timeout]) ||
71
84
  invalid(check, "check timeout must be numeric")
72
- must_be_a_string_if_set(check[:source]) ||
73
- invalid(check, "check source must be a string")
85
+ validate_check_source(check) if check[:source]
74
86
  validate_check_scheduling(check)
75
87
  validate_check_handling(check)
76
88
  validate_check_flap_detection(check)
77
- if check[:subdue]
78
- validate_subdue(check)
79
- end
89
+ validate_subdue(check) if check[:subdue]
80
90
  end
81
91
  end
82
92
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "sensu-settings"
5
- spec.version = "1.3.0"
5
+ spec.version = "1.4.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"
@@ -145,6 +145,9 @@ describe "Sensu::Settings::Validator" do
145
145
  expect(@validator.reset).to eq(1)
146
146
  check[:source] = "switch-%42%"
147
147
  @validator.validate_check(check)
148
+ expect(@validator.reset).to eq(1)
149
+ check[:source] = "switch-42"
150
+ @validator.validate_check(check)
148
151
  expect(@validator.reset).to eq(0)
149
152
  check[:extension] = 'foo'
150
153
  @validator.validate_check(check)
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: 1.3.0
4
+ version: 1.4.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: 2015-03-16 00:00:00.000000000 Z
11
+ date: 2015-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json