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