logstash-mixin-validator_support 1.0.2-java → 1.1.1-java

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
  SHA256:
3
- metadata.gz: 13ac395ad145d01d61c2bdabe650b196c4be7acb6c368da1243b0a3631cc014b
4
- data.tar.gz: 12e1918821bb58ce03193385764288bbd947441466d7be1140f5f0722ccadb4d
3
+ metadata.gz: 159f311b4e84d43448ee190e79e43a7cb357e8428375e2a0a4df1c8d9410b4c3
4
+ data.tar.gz: 3ccacc4edcd70fe348ef64e5881149568dbe472bfec9cf932fc731f6440cc776
5
5
  SHA512:
6
- metadata.gz: c82c7c247334d02711f10e1ff3074b10cb01dc06932b6582cfee6199171ab28619e978eaf47799e32f2e3f13fb9e3ead252490f2cf01ce8937d7e3a7ca6380dd
7
- data.tar.gz: add01c80a60310c57de1e4b0cf459ff78da4ad1f6cb97fdebbdff43757552ef2bdb897d0f0e61408b1323f79d1fd7182afdf870de65ab94288a4b076703c1792
6
+ metadata.gz: f0599cb15cf09c700a401d14bc023aec8afee421a1d169654fa396e479544a0fec6a6a7bd754d0e503afb020f4f3b30eec144298be1910c900f1c258bedb34fc
7
+ data.tar.gz: d251678e6c755bc20887fc94fe9cdc51b11e8a5a6415169599b4554e9d47dfce3fc949ad3a5151c37e84c8b9625287a5887705dc9368c53a859101356d921812
data/CHANGELOG.md CHANGED
@@ -1,7 +1,11 @@
1
- # 1.0.2
1
+ ## 1.1.1
2
+ - allow single word host names [#7](https://github.com/logstash-plugins/logstash-mixin-validator_support/pull/7)
2
3
 
3
- - Fix: '' value behavior in `field_reference` validator [#2](https://github.com/logstash-plugins/logstash-mixin-validator_support/pull/2)
4
+ ## 1.1.0
5
+ - Introduces `:required_host_optional_port` validator [#4](https://github.com/logstash-plugins/logstash-mixin-validator_support/pull/4)
4
6
 
5
- # 1.0.1
7
+ ## 1.0.2
8
+ - Fix: '' value behavior in `field_reference` validator [#2](https://github.com/logstash-plugins/logstash-mixin-validator_support/pull/2)
6
9
 
7
- - Introduces plugin parameter validation adapters, including initial backport for `:field_reference` validator.
10
+ ## 1.0.1
11
+ - Introduces plugin parameter validation adapters, including initial backport for `:field_reference` validator.
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+
3
+ require 'logstash/plugin_mixins/validator_support'
4
+
5
+ require 'resolv'
6
+
7
+ module LogStash
8
+ module PluginMixins
9
+ module ValidatorSupport
10
+
11
+
12
+ # rely on Resolv's IPv4#create and IPv6#create to validate IP addresses, but first regex to avoid most exceptions
13
+ is_valid_ipv4 = ->(candidate) { Resolv::IPv4::Regex.match?(candidate) && Resolv::IPv4.create(candidate) rescue false}
14
+ is_valid_ipv6 = ->(candidate) { Resolv::IPv6::Regex.match?(candidate) && Resolv::IPv6.create(candidate) rescue false}
15
+
16
+ # RFC1123 validated at https://regexr.com/7n2ce
17
+ rfc1123_hostname_pattern = %r{\A(?=.{1,255}\z)(?:(?=[^.]{1,63}(?:[.]|\z))[a-z0-9]+(?:[a-z0-9\-]+[a-z0-9])?(?:[.]|\z))+\z}i
18
+ is_valid_hostname = ->(candidate) { rfc1123_hostname_pattern.match?(candidate) }
19
+
20
+ # the normalized tuple from valid values
21
+ host_port_pair = Struct.new(:host, :port)
22
+
23
+ expectation_desc = "required-host optional-port pair"
24
+
25
+ port_range = Range.new(0,65535)
26
+
27
+ ##
28
+ # When included into a Logstash plugin, adds a valiador named `required_host_optional_port`, which expects
29
+ # exactly one string matching a required host, optionally followed by a colon and a port number, and coerces
30
+ # valid values into a value with `host` and `port` attributes.
31
+ # When specifying an IPv6 address, it MUST be enclosed in square-brackets, and the address itself (without
32
+ # brackets) will be made available in the coerced value's `host` attribute
33
+ RequiredHostOptionalPortValidationAdapter = NamedValidationAdapter.new(:required_host_optional_port) do |value|
34
+ break ValidationResult.failure("Expected exactly one #{expectation_desc}, got `#{value.inspect}`") unless value.kind_of?(Array) && value.size <= 1
35
+
36
+ candidate = value.first
37
+
38
+ break ValidationResult.failure("Expected a valid #{expectation_desc}, got `#{candidate.inspect}`") unless candidate.kind_of?(String) && !candidate.empty?
39
+
40
+ # optional port
41
+ candidate_host, candidate_port = candidate.split(%r{\:(?=\d{1,5}\z)},2)
42
+ port = candidate_port&.to_i
43
+
44
+ break ValidationResult.failure("Expected a port in #{port_range.inspect}, got `#{port}`") if port && !port_range.include?(port)
45
+
46
+ # bracket-wrapped ipv6
47
+ if candidate_host.start_with?('[') && candidate_host.end_with?(']')
48
+ candidate_host = candidate_host[1...-1]
49
+ break ValidationResult.success(host_port_pair.new(candidate_host, port)) if is_valid_ipv6[candidate_host]
50
+ else
51
+ # ipv4 or hostname
52
+ break ValidationResult.success(host_port_pair.new(candidate_host, port)) if is_valid_ipv4[candidate_host]
53
+ break ValidationResult.success(host_port_pair.new(candidate_host, port)) if is_valid_hostname[candidate_host]
54
+ end
55
+
56
+ break ValidationResult.failure("Expected a valid #{expectation_desc}, got `#{candidate.inspect}`")
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,76 @@
1
+ # encoding: utf-8
2
+
3
+ require 'logstash/plugin_mixins/validator_support/required_host_optional_port_validation_adapter'
4
+
5
+ describe LogStash::PluginMixins::ValidatorSupport::RequiredHostOptionalPortValidationAdapter do
6
+
7
+ it 'is an instance of NamedValidationAdapter' do
8
+ expect(described_class).to be_a_kind_of LogStash::PluginMixins::ValidatorSupport::NamedValidationAdapter
9
+ end
10
+
11
+ context '#validate' do
12
+ {
13
+ "127.0.0.1:1234" => {:host => "127.0.0.1", :port => 1234},
14
+ "82.31.1.3:9800" => {:host => "82.31.1.3", :port => 9800},
15
+ "localhost:1234" => {:host => "localhost", :port => 1234},
16
+ "foo.com:1234" => {:host => "foo.com", :port => 1234},
17
+ "foo-bar-domain.com:9800" => {:host => "foo-bar-domain.com", :port => 9800},
18
+ "[::1]:1234" => {:host => "::1", :port => 1234},
19
+ "[2001:db8:3333:4444:5555:6666:7777:8888]:9800" => {:host => "2001:db8:3333:4444:5555:6666:7777:8888", :port => 9800},
20
+ "[2001:db8:3333::7777:8888]:9800" => {:host => "2001:db8:3333::7777:8888", :port => 9800},
21
+ "[::ffff:93.184.216.34]:1023" => {:host => "::ffff:93.184.216.34", :port => 1023},
22
+
23
+ "127.0.0.1" => {:host => "127.0.0.1", :port => nil},
24
+ "82.31.1.3" => {:host => "82.31.1.3", :port => nil},
25
+ "foo.com" => {:host => "foo.com", :port => nil},
26
+ "foo-bar-domain.com" => {:host => "foo-bar-domain.com", :port => nil},
27
+ "[::1]" => {:host => "::1", :port => nil},
28
+ "[2001:db8:3333:4444:5555:6666:7777:8888]" => {:host => "2001:db8:3333:4444:5555:6666:7777:8888", :port => nil},
29
+ "[2001:db8:3333::7777:8888]" => {:host => "2001:db8:3333::7777:8888", :port => nil},
30
+ "[::ffff:93.184.216.34]" => {:host => "::ffff:93.184.216.34", :port => nil},
31
+ }.each do |candidate, expected_result|
32
+ context "valid input `#{candidate.inspect}`" do
33
+ it "coerces the result to a host/port struct `#{expected_result}`" do
34
+ is_valid_result, coerced_or_error = described_class.validate([candidate])
35
+ failure = is_valid_result ? nil : coerced_or_error
36
+ coerced = is_valid_result ? coerced_or_error : nil
37
+
38
+ aggregate_failures do
39
+ expect(is_valid_result).to be true
40
+ expect(failure).to be_nil # makes spec failure output useful
41
+ end
42
+ expect(coerced).to have_attributes(expected_result.to_h)
43
+ end
44
+ end
45
+ end
46
+
47
+ [
48
+ "not an address",
49
+ "http://example.com:1234",
50
+ "tcp://example.com",
51
+ "http://example.com:1234/v1/this",
52
+ "",
53
+ ":1234", # port without host
54
+ "::1", # bare ipv6
55
+ "2001:db8:3333:4444:5555:6666:7777:8888",
56
+ "2001:db8:3333::7777:8888",
57
+ "[1:2:3:4:5:6::7:8:9:a:b:c]", # invalid compressed hex ipv6 form
58
+ "[::ffff:258.512.768.999]", # invalid compressed hex4dec ipv6 form
59
+ "example.com:98000",
60
+ ].each do |candidate|
61
+ context "invalid input `#{candidate.inspect}`" do
62
+ it "reports the input as invalid" do
63
+ is_valid_result, coerced_or_error = described_class.validate([candidate])
64
+ failure = is_valid_result ? nil : coerced_or_error
65
+ coerced = is_valid_result ? coerced_or_error : nil
66
+
67
+ aggregate_failures do
68
+ expect(is_valid_result).to be false
69
+ expect(coerced).to be_nil # makes spec failure output useful
70
+ end
71
+ expect(failure).to_not be_nil
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-mixin-validator_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.1
5
5
  platform: java
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-06 00:00:00.000000000 Z
11
+ date: 2023-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,9 @@ files:
66
66
  - README.md
67
67
  - lib/logstash/plugin_mixins/validator_support.rb
68
68
  - lib/logstash/plugin_mixins/validator_support/field_reference_validation_adapter.rb
69
+ - lib/logstash/plugin_mixins/validator_support/required_host_optional_port_validation_adapter.rb
69
70
  - spec/logstash/plugin_mixins/validator_support/field_reference_validation_adapter_spec.rb
71
+ - spec/logstash/plugin_mixins/validator_support/required_host_optional_port_validation_adapter_spec.rb
70
72
  - spec/logstash/plugin_mixins/validator_support_spec.rb
71
73
  homepage: https://github.com/logstash-plugins/logstash-mixin-validator_support
72
74
  licenses:
@@ -87,11 +89,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
89
  - !ruby/object:Gem::Version
88
90
  version: '0'
89
91
  requirements: []
90
- rubygems_version: 3.1.6
92
+ rubygems_version: 3.2.33
91
93
  signing_key:
92
94
  specification_version: 4
93
95
  summary: Support for the plugin parameter validations introduced in recent releases
94
96
  of Logstash, for plugins wishing to use them on older Logstashes
95
97
  test_files:
96
98
  - spec/logstash/plugin_mixins/validator_support/field_reference_validation_adapter_spec.rb
99
+ - spec/logstash/plugin_mixins/validator_support/required_host_optional_port_validation_adapter_spec.rb
97
100
  - spec/logstash/plugin_mixins/validator_support_spec.rb