reduce cognitive complexity, breakup function

Signed-off-by: Kerry Vance <vancelot@osuosl.org>
This commit is contained in:
Kerry Vance 2019-09-05 12:20:45 -07:00
parent 729d9965ed
commit 41978b4bc7

View file

@ -30,41 +30,9 @@ module Inspec::Resources
def hostname(opt = nil)
os = inspec.os
if os.linux?
if !opt.nil?
opt = case opt
when "f", "long", "fqdn", "full"
" -f"
when "d", "domain"
" -d"
when "i", "ip_address"
" -I"
when "s", "short"
" -s"
else
"ERROR"
end
end
if opt == "ERROR"
skip_resource "The `sys_info.hostname` resource is not supported with that option on your OS."
else
inspec.command("hostname#{opt}").stdout.chomp
end
linux_hostname(opt)
elsif os.darwin?
if !opt.nil?
opt = case opt
when "f", "long", "fqdn", "full"
" -f"
when "s", "short"
" -s"
else
"ERROR"
end
end
if opt == "ERROR"
skip_resource "The `sys_info.hostname` resource is not supported with that option on your OS."
else
inspec.command("hostname#{opt}").stdout.chomp
end
mac_hostname(opt)
elsif os.windows?
if !opt.nil?
skip_resource "The `sys_info.hostname` resource is not supported with that option on your OS."
@ -76,6 +44,46 @@ module Inspec::Resources
end
end
def linux_hostname(opt = nil)
if !opt.nil?
opt = case opt
when "f", "long", "fqdn", "full"
" -f"
when "d", "domain"
" -d"
when "i", "ip_address"
" -I"
when "s", "short"
" -s"
else
"ERROR"
end
end
if opt == "ERROR"
skip_resource "The `sys_info.hostname` resource is not supported with that option on your OS."
else
inspec.command("hostname#{opt}").stdout.chomp
end
end
def mac_hostname(opt = nil)
if !opt.nil?
opt = case opt
when "f", "long", "fqdn", "full"
" -f"
when "s", "short"
" -s"
else
"ERROR"
end
end
if opt == "ERROR"
skip_resource "The `sys_info.hostname` resource is not supported with that option on your OS."
else
inspec.command("hostname#{opt}").stdout.chomp
end
end
# returns the Manufacturer of the local system
def manufacturer
os = inspec.os