mirror of
https://github.com/inspec/inspec
synced 2025-01-14 22:24:56 +00:00
55 lines
1.2 KiB
Ruby
55 lines
1.2 KiB
Ruby
|
# encoding: utf-8
|
||
|
|
||
|
module Vulcano
|
||
|
module Backend
|
||
|
|
||
|
def configure_winrm(conf)
|
||
|
si = Specinfra.configuration
|
||
|
si.backend = :winrm
|
||
|
si.os = { family: 'windows'}
|
||
|
|
||
|
# common options
|
||
|
host = conf['host'].to_s
|
||
|
port = conf['port']
|
||
|
user = conf['user'].to_s
|
||
|
pass = conf['pass'].tp_s
|
||
|
|
||
|
# SSL configuration
|
||
|
if conf['winrm_ssl']
|
||
|
scheme = 'https'
|
||
|
port = port || 5986
|
||
|
else
|
||
|
scheme = 'http'
|
||
|
port = port || 5985
|
||
|
end
|
||
|
|
||
|
# validation
|
||
|
if host.empty?
|
||
|
raise "You must configure a target host."
|
||
|
end
|
||
|
unless port > 0
|
||
|
raise "Port must be > 0 (not #{port})"
|
||
|
end
|
||
|
if user.empty?
|
||
|
raise "You must configure a WinRM user for login."
|
||
|
end
|
||
|
if pass.empty?
|
||
|
raise "You must configure a WinRM password."
|
||
|
end
|
||
|
|
||
|
# create the connection
|
||
|
endpoint = "#{scheme}://#{host}:#{port}/wsman"
|
||
|
winrm = ::WinRM::WinRMWebService.new(
|
||
|
endpoint,
|
||
|
:ssl,
|
||
|
user: user,
|
||
|
pass: pass,
|
||
|
basic_auth_only: true,
|
||
|
no_ssl_peer_verification: conf['winrm_self_signed'],
|
||
|
)
|
||
|
si.winrm = winrm
|
||
|
end
|
||
|
|
||
|
end
|
||
|
end
|