mirror of
https://github.com/inspec/inspec
synced 2025-02-17 06:28:40 +00:00
reduce cognitive complexity, breakup function
Signed-off-by: Kerry Vance <vancelot@osuosl.org>
This commit is contained in:
parent
729d9965ed
commit
41978b4bc7
1 changed files with 42 additions and 34 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue