mirror of
https://github.com/inspec/inspec
synced 2025-02-17 06:28:40 +00:00
fails loudly with unsupported options
Signed-off-by: Kerry Vance <vancelot@osuosl.org>
This commit is contained in:
parent
540515f796
commit
729d9965ed
2 changed files with 43 additions and 3 deletions
|
@ -41,6 +41,24 @@ The following examples show how to use this Chef InSpec audit resource.
|
|||
|
||||
<br>
|
||||
|
||||
### Compare content to hostname
|
||||
|
||||
describe file('/path/to/some/file') do
|
||||
its('content') { should match sys_info.hostname }
|
||||
end
|
||||
|
||||
<br>
|
||||
|
||||
Options can be passed as arguments to hostname as well.
|
||||
|
||||
describe file('/path/to/some/file') do
|
||||
its('content') { should match sys_info.hostname('full') }
|
||||
end
|
||||
|
||||
<br>
|
||||
|
||||
Currently supported arguments to `hostname` on Linux platforms are 'full'|'f'|'fqdn'|'long', 'domain'|'d', 'ip_address'|'i', and 'short'|'s'. Mac currently supports 'full'|'f'|'fqdn'|'long' and 'short'|'s'
|
||||
|
||||
## Matchers
|
||||
|
||||
For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
||||
|
|
|
@ -29,7 +29,8 @@ module Inspec::Resources
|
|||
# returns the hostname of the local system
|
||||
def hostname(opt = nil)
|
||||
os = inspec.os
|
||||
if os.linux? || os.darwin?
|
||||
if os.linux?
|
||||
if !opt.nil?
|
||||
opt = case opt
|
||||
when "f", "long", "fqdn", "full"
|
||||
" -f"
|
||||
|
@ -40,9 +41,30 @@ module Inspec::Resources
|
|||
when "s", "short"
|
||||
" -s"
|
||||
else
|
||||
nil
|
||||
"ERROR"
|
||||
end
|
||||
inspec.command("hostname#{opt}").stdout.chomp
|
||||
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
|
||||
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
|
||||
elsif os.windows?
|
||||
if !opt.nil?
|
||||
skip_resource "The `sys_info.hostname` resource is not supported with that option on your OS."
|
||||
|
|
Loading…
Add table
Reference in a new issue