Skip to content

Commit db159bb

Browse files
committed
Refactor: @ssl checking - return early
1 parent b9558eb commit db159bb

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/logstash/inputs/http.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,41 +238,42 @@ def validate_ssl_settings!
238238
@logger.warn("SSL Certificate will not be used") if @ssl_certificate
239239
@logger.warn("SSL Key will not be used") if @ssl_key
240240
@logger.warn("SSL Java Key Store will not be used") if @keystore
241+
return # code bellow assumes `ssl => true`
241242
elsif !(ssl_key_configured? || ssl_jks_configured?)
242243
raise LogStash::ConfigurationError, "Certificate or JKS must be configured"
243244
end
244245

245-
if @ssl && (original_params.key?("verify_mode") && original_params.key?("ssl_verify_mode"))
246+
if original_params.key?("verify_mode") && original_params.key?("ssl_verify_mode")
246247
raise LogStash::ConfigurationError, "Both `ssl_verify_mode` and (deprecated) `verify_mode` were set. Use only `ssl_verify_mode`."
247248
elsif original_params.key?("verify_mode")
248249
@ssl_verify_mode_final = @verify_mode
249250
else
250251
@ssl_verify_mode_final = @ssl_verify_mode
251252
end
252253

253-
if @ssl && (original_params.key?('cipher_suites') && original_params.key?('ssl_cipher_suites'))
254+
if original_params.key?('cipher_suites') && original_params.key?('ssl_cipher_suites')
254255
raise LogStash::ConfigurationError, "Both `ssl_cipher_suites` and (deprecated) `cipher_suites` were set. Use only `ssl_cipher_suites`."
255256
elsif original_params.key?('cipher_suites')
256257
@ssl_cipher_suites_final = @cipher_suites
257258
else
258259
@ssl_cipher_suites_final = @ssl_cipher_suites
259260
end
260261

261-
if @ssl && (original_params.key?('tls_min_version') && original_params.key?('ssl_supported_protocols'))
262+
if original_params.key?('tls_min_version') && original_params.key?('ssl_supported_protocols')
262263
raise LogStash::ConfigurationError, "Both `ssl_supported_protocols` and (deprecated) `tls_min_ciphers` were set. Use only `ssl_supported_protocols`."
263-
elsif @ssl && (original_params.key?('tls_max_version') && original_params.key?('ssl_supported_protocols'))
264+
elsif original_params.key?('tls_max_version') && original_params.key?('ssl_supported_protocols')
264265
raise LogStash::ConfigurationError, "Both `ssl_supported_protocols` and (deprecated) `tls_max_ciphers` were set. Use only `ssl_supported_protocols`."
265266
else
266-
if @ssl && (original_params.key?('tls_min_version') || original_params.key?('tls_max_version'))
267+
if original_params.key?('tls_min_version') || original_params.key?('tls_max_version')
267268
@ssl_supported_protocols_final = TLS.get_supported(tls_min_version..tls_max_version).map(&:name)
268269
else
269270
@ssl_supported_protocols_final = @ssl_supported_protocols
270271
end
271272
end
272273

273-
if @ssl && require_certificate_authorities? && !client_authentication?
274+
if require_certificate_authorities? && !client_authentication?
274275
raise LogStash::ConfigurationError, "Using `ssl_verify_mode` (or `verify_mode`) set to PEER or FORCE_PEER, requires the configuration of `ssl_certificate_authorities`"
275-
elsif @ssl && !require_certificate_authorities? && client_authentication?
276+
elsif !require_certificate_authorities? && client_authentication?
276277
raise LogStash::ConfigurationError, "The configuration of `ssl_certificate_authorities` requires setting `ssl_verify_mode` (or `verify_mode`) to PEER or FORCE_PEER"
277278
end
278279
end

0 commit comments

Comments
 (0)