mirror of
https://github.com/inspec/inspec
synced 2024-11-15 01:17:08 +00:00
implement run script resource for windows
This commit is contained in:
parent
89223ceb2b
commit
67f6ae5be2
2 changed files with 40 additions and 0 deletions
39
lib/resources/script.rb
Normal file
39
lib/resources/script.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
# encoding: utf-8
|
||||
# copyright: 2015, Vulcano Security GmbH
|
||||
# author: Christoph Hartmann
|
||||
# author: Dominik Richter
|
||||
# license: All rights reserved
|
||||
|
||||
class Script < Cmd
|
||||
name 'script'
|
||||
def initialize(script)
|
||||
case vulcano.os[:family]
|
||||
when 'windows'
|
||||
# encodes a script as base64 to run as powershell encodedCommand
|
||||
# this comes with performance issues: @see https://gist.github.com/fnichol/7b20596b950e65fb96f9
|
||||
require 'winrm'
|
||||
script = WinRM::PowershellScript.new(script)
|
||||
cmd = "powershell -encodedCommand #{script.encoded}"
|
||||
else
|
||||
return skip_resource 'The `script` resource is not supported on your OS yet.'
|
||||
end
|
||||
|
||||
@command = cmd
|
||||
end
|
||||
|
||||
def result
|
||||
@result ||= vulcano.command(@command)
|
||||
end
|
||||
|
||||
def stdout
|
||||
result.stdout
|
||||
end
|
||||
|
||||
def stderr
|
||||
result.stderr
|
||||
end
|
||||
|
||||
def exit_status
|
||||
result.exit_status.to_i
|
||||
end
|
||||
end
|
|
@ -56,6 +56,7 @@ require 'resources/postgres_conf'
|
|||
require 'resources/postgres_session'
|
||||
require 'resources/processes'
|
||||
require 'resources/registry_key'
|
||||
require 'resources/script'
|
||||
require 'resources/security_policy'
|
||||
require 'resources/service'
|
||||
require 'resources/ssh_conf'
|
||||
|
|
Loading…
Reference in a new issue