inspec/lib/resources/powershell.rb

58 lines
1.4 KiB
Ruby
Raw Normal View History

# encoding: utf-8
# copyright: 2015, Vulcano Security GmbH
module Inspec::Resources
2016-03-18 11:29:36 +00:00
class PowershellScript < Cmd
name 'powershell'
supports platform: 'windows'
2016-03-18 11:29:36 +00:00
desc 'Use the powershell InSpec audit resource to test a Windows PowerShell script on the Microsoft Windows platform.'
example "
script = <<-EOH
2017-04-20 15:43:33 +00:00
# your powershell script
EOH
2015-11-27 13:02:38 +00:00
2016-03-18 11:29:36 +00:00
describe powershell(script) do
its('matcher') { should eq 'output' }
end
"
2015-10-07 11:13:37 +00:00
def initialize(script)
unless inspec.os.windows?
super('')
return skip_resource 'The `script` resource is not supported on your OS yet.'
end
# since WinRM 2.0 and the default use of powershell for local execution in
# train, we do not need to wrap the script here anymore
super(script)
end
# we cannot determine if a command exists, because that does not work for scripts
def exist?
nil
end
# Removes leading and trailing whitespace from stdout
def strip
result.stdout&.strip
end
def to_s
2016-03-18 11:29:36 +00:00
'Powershell'
end
end
# this is deprecated syntax and will be removed in future versions
class LegacyPowershellScript < PowershellScript
name 'script'
def initialize(script)
deprecated
super(script)
end
def deprecated
warn '[DEPRECATION] `script(script)` is deprecated. Please use `powershell(script)` instead.'
end
end
end