mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
Refactor Hash.fetch usage to provide default values
Rather than explicitly running through if/else blocks, it's easier to read if the default value is provided against the Hash method calls directly.
This commit is contained in:
parent
c83c1444a3
commit
5d70c6026e
1 changed files with 9 additions and 48 deletions
|
@ -94,54 +94,15 @@ class LogStash::Outputs::Email < LogStash::Outputs::Base
|
|||
def register
|
||||
require "mail"
|
||||
if @via == "smtp"
|
||||
debug = @options.include?("debug")
|
||||
if !debug
|
||||
debug = false
|
||||
else
|
||||
debug = @options.fetch("debug")
|
||||
end
|
||||
smtpIporHost = @options.include?("smtpIporHost")
|
||||
if !smtpIporHost
|
||||
smtpIporHost = "localhost"
|
||||
else
|
||||
smtpIporHost = @options.fetch("smtpIporHost")
|
||||
end
|
||||
domain = @options.include?("domain")
|
||||
if !domain
|
||||
domain = "localhost"
|
||||
else
|
||||
domain = @options.fetch("domain")
|
||||
end
|
||||
port = @options.include?("port")
|
||||
if !port
|
||||
port = 25
|
||||
else
|
||||
port = @options.fetch("port")
|
||||
end
|
||||
tls = @options.include?("starttls")
|
||||
if !tls
|
||||
tls = false
|
||||
else
|
||||
tls = @options.fetch("starttls")
|
||||
end
|
||||
pass = @options.include?("password")
|
||||
if !pass
|
||||
pass = nil
|
||||
else
|
||||
pass = @options.fetch("password")
|
||||
end
|
||||
userName = @options.include?("userName")
|
||||
if !userName
|
||||
userName = nil
|
||||
else
|
||||
userName = @options.fetch("userName")
|
||||
end
|
||||
authenticationType = @options.include?("authenticationType")
|
||||
if !authenticationType
|
||||
authenticationType = nil
|
||||
else
|
||||
authenticationType = @options.fetch("authenticationType")
|
||||
end
|
||||
debug = @options.fetch("debug", false)
|
||||
smtpIporHost = @options.fetch("smtpIporHost", "localhost")
|
||||
domain = @options.fetch("domain", "localhost")
|
||||
port = @options.fetch("port", 25)
|
||||
tls = @options.fetch("starttls", false)
|
||||
pass = @options.fetch("password", nil)
|
||||
userName = @options.fetch("userName", nil)
|
||||
authenticationType = @options.fetch("authenticationType", nil)
|
||||
|
||||
Mail.defaults do
|
||||
delivery_method :smtp , { :address => smtpIporHost,
|
||||
:port => port,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue