Skip to content

Commit 2a13975

Browse files
committed
Implemented NullableString in Java an updates latest String setting references
1 parent 5131596 commit 2a13975

File tree

8 files changed

+96
-28
lines changed

8 files changed

+96
-28
lines changed

logstash-core/lib/logstash/settings.rb

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -527,26 +527,28 @@ def validate(value)
527527

528528
java_import org.logstash.settings.StringSetting
529529

530-
class String < Setting
531-
def initialize(name, default = nil, strict = true, possible_strings = [])
532-
@possible_strings = possible_strings
533-
super(name, ::String, default, strict)
534-
end
535-
536-
def validate(value)
537-
super(value)
538-
unless @possible_strings.empty? || @possible_strings.include?(value)
539-
raise ArgumentError.new("Invalid value \"#{name}: #{value}\". Options are: #{@possible_strings.inspect}")
540-
end
541-
end
542-
end
543-
544-
class NullableString < String
545-
def validate(value)
546-
return if value.nil?
547-
super(value)
548-
end
549-
end
530+
# class String < Setting
531+
# def initialize(name, default = nil, strict = true, possible_strings = [])
532+
# @possible_strings = possible_strings
533+
# super(name, ::String, default, strict)
534+
# end
535+
#
536+
# def validate(value)
537+
# super(value)
538+
# unless @possible_strings.empty? || @possible_strings.include?(value)
539+
# raise ArgumentError.new("Invalid value \"#{name}: #{value}\". Options are: #{@possible_strings.inspect}")
540+
# end
541+
# end
542+
# end
543+
544+
java_import org.logstash.settings.NullableString
545+
546+
# class NullableString < String
547+
# def validate(value)
548+
# return if value.nil?
549+
# super(value)
550+
# end
551+
# end
550552

551553
class Password < Coercible
552554
def initialize(name, default = nil, strict = true)

logstash-core/spec/logstash/settings/string_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
require "spec_helper"
1919
require "logstash/settings"
2020

21-
describe LogStash::Setting::String do
21+
describe LogStash::Setting::StringSetting do
2222
let(:possible_values) { ["a", "b", "c"] }
2323
subject { described_class.new("mytext", possible_values.first, true, possible_values) }
2424
describe "#set" do
2525
context "when a value is given outside of possible_values" do
2626
it "should raise an ArgumentError" do
27-
expect { subject.set("d") }.to raise_error(ArgumentError)
27+
expect { subject.set("d") }.to raise_error(java.lang.IllegalArgumentException)
2828
end
2929
end
3030
context "when a value is given within possible_values" do
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.logstash.settings;
20+
21+
import java.util.List;
22+
23+
public class NullableString extends StringSetting {
24+
25+
public NullableString(String name, String defaultValue, boolean strict, List<String> possibleStrings) {
26+
super(name, defaultValue, strict, possibleStrings);
27+
}
28+
29+
public NullableString(String name, String defaultValue) {
30+
super(name, defaultValue);
31+
}
32+
33+
public NullableString(String name, String defaultValue, boolean strict) {
34+
super(name, defaultValue, strict);
35+
}
36+
37+
public NullableString(String name) {
38+
super(name, null);
39+
}
40+
41+
@Override
42+
public void validate(String input) throws IllegalArgumentException {
43+
if (input == null) {
44+
return;
45+
}
46+
super.validate(input);
47+
}
48+
}

logstash-core/src/main/java/org/logstash/settings/StringSetting.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
119
package org.logstash.settings;
220

321
import java.util.Collections;

x-pack/lib/config_management/extension.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def additionals_settings(settings)
4040
settings.register(LogStash::Setting::NullableString.new("xpack.management.elasticsearch.ssl.certificate"))
4141
settings.register(LogStash::Setting::NullableString.new("xpack.management.elasticsearch.ssl.key"))
4242
settings.register(LogStash::Setting::ArrayCoercible.new("xpack.management.elasticsearch.ssl.cipher_suites", String, []))
43-
settings.register(LogStash::Setting::String.new("xpack.management.elasticsearch.ssl.verification_mode", "full", true, %w[none certificate full]))
43+
settings.register(LogStash::Setting::StringSetting.new("xpack.management.elasticsearch.ssl.verification_mode", "full", true, %w[none certificate full]))
4444
settings.register(LogStash::Setting::Boolean.new("xpack.management.elasticsearch.sniffing", false))
4545
rescue => e
4646
logger.error("Cannot register new settings", :message => e.message, :backtrace => e.backtrace)

x-pack/lib/geoip_database_management/extension.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Extension < LogStash::UniversalPlugin
1111
def additionals_settings(settings)
1212
require "logstash/runner"
1313
logger.trace("Registering additional geoip settings")
14-
settings.register(LogStash::Setting::String.new("xpack.geoip.downloader.endpoint", "https://geoip.elastic.co/v1/database")
14+
settings.register(LogStash::Setting::StringSetting.new("xpack.geoip.downloader.endpoint", "https://geoip.elastic.co/v1/database")
1515
.with_deprecated_alias("xpack.geoip.download.endpoint"))
1616
settings.register(LogStash::Setting::TimeValue.new("xpack.geoip.downloader.poll.interval", "24h"))
1717
settings.register(LogStash::Setting::Boolean.new("xpack.geoip.downloader.enabled", true))

x-pack/lib/monitoring/monitoring.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def additionals_settings(settings)
250250
# (Experimental) Direct shipping settings
251251
register_monitoring_settings(settings)
252252

253-
settings.register(LogStash::Setting::String.new("node.uuid", ""))
253+
settings.register(LogStash::Setting::StringSetting.new("node.uuid", ""))
254254
rescue => e
255255
logger.error e.message
256256
logger.error e.backtrace.to_s
@@ -275,7 +275,7 @@ def register_monitoring_settings(settings, prefix = "")
275275
settings.register(LogStash::Setting::NullableString.new("#{prefix}monitoring.elasticsearch.ssl.truststore.password"))
276276
settings.register(LogStash::Setting::NullableString.new("#{prefix}monitoring.elasticsearch.ssl.keystore.path"))
277277
settings.register(LogStash::Setting::NullableString.new("#{prefix}monitoring.elasticsearch.ssl.keystore.password"))
278-
settings.register(LogStash::Setting::String.new("#{prefix}monitoring.elasticsearch.ssl.verification_mode", "full", true, ["none", "certificate", "full"]))
278+
settings.register(LogStash::Setting::StringSetting.new("#{prefix}monitoring.elasticsearch.ssl.verification_mode", "full", true, ["none", "certificate", "full"]))
279279
settings.register(LogStash::Setting::NullableString.new("#{prefix}monitoring.elasticsearch.ssl.certificate"))
280280
settings.register(LogStash::Setting::NullableString.new("#{prefix}monitoring.elasticsearch.ssl.key"))
281281
settings.register(LogStash::Setting::ArrayCoercible.new("#{prefix}monitoring.elasticsearch.ssl.cipher_suites", String, []))

x-pack/spec/config_management/extension_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"xpack.management.logstash.poll_interval" => [LogStash::Setting::TimeValue, LogStash::Util::TimeValue.from_value("5s")],
3333
"xpack.management.pipeline.id" => [LogStash::Setting::ArrayCoercible, ["main"]],
3434
"xpack.management.elasticsearch.hosts" => [LogStash::Setting::ArrayCoercible, ["https://localhost:9200"]],
35-
"xpack.management.elasticsearch.username" => [LogStash::Setting::String, "logstash_system"],
36-
"xpack.management.elasticsearch.password" => [LogStash::Setting::String, nil],
35+
"xpack.management.elasticsearch.username" => [LogStash::Setting::StringSetting, "logstash_system"],
36+
"xpack.management.elasticsearch.password" => [LogStash::Setting::StringSetting, nil],
3737
"xpack.management.elasticsearch.ssl.certificate_authority" => [LogStash::Setting::NullableString, nil],
3838
"xpack.management.elasticsearch.ssl.ca_trusted_fingerprint" => [LogStash::Setting::NullableString, nil],
3939
"xpack.management.elasticsearch.ssl.truststore.path" => [LogStash::Setting::NullableString, nil],

0 commit comments

Comments
 (0)