From 75b17561ee353ac555d0348c3af64d94f084426d Mon Sep 17 00:00:00 2001 From: Kerry Vance Date: Thu, 11 Jul 2019 14:12:27 -0700 Subject: [PATCH] expand sys_info resource functionality Signed-off-by: Kerry Vance --- lib/inspec/resources/sys_info.rb | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/inspec/resources/sys_info.rb b/lib/inspec/resources/sys_info.rb index 6f24a0c40..01301774d 100644 --- a/lib/inspec/resources/sys_info.rb +++ b/lib/inspec/resources/sys_info.rb @@ -13,13 +13,38 @@ module Inspec::Resources describe sys_info do its('hostname') { should eq 'example.com' } end + + describe sys_info do + its('hostname') { should eq 'example.com' } + end + EXAMPLE + %w{ alias domain fqdn ip-address short }.each do |opt| + define_method(opt.to_sym) do + hostname(opt) + end + end + # returns the hostname of the local system - def hostname + def hostname(opt = nil) os = inspec.os if os.linux? || os.darwin? - inspec.command("hostname").stdout.chomp + opt = case opt + when "f", "long", "fqdn", "full" + " -f" + when "a", "alias" + " -a" + when "d", "domain" + " -d" + when "i", "ip-address" + " -i" + when "s", "short" + " -s" + else + nil + end + inspec.command("hostname#{opt}").stdout.chomp elsif os.windows? inspec.powershell("$env:computername").stdout.chomp else