mirror of
https://github.com/inspec/inspec
synced 2024-12-26 21:13:25 +00:00
53 lines
1.2 KiB
Ruby
53 lines
1.2 KiB
Ruby
|
# encoding: utf-8
|
||
|
|
||
|
require 'winrm'
|
||
|
|
||
|
class Vulcano::Backends::SpecinfraHelper
|
||
|
module Winrm
|
||
|
def self.winrm_url(conf)
|
||
|
host = conf['host'].to_s
|
||
|
port = conf['port']
|
||
|
fail 'You must configure a target host.' if host.empty?
|
||
|
|
||
|
# SSL configuration
|
||
|
if conf['winrm_ssl']
|
||
|
scheme = 'https'
|
||
|
port ||= 5986
|
||
|
else
|
||
|
scheme = 'http'
|
||
|
port ||= 5985
|
||
|
end
|
||
|
|
||
|
"#{scheme}://#{host}:#{port}/wsman"
|
||
|
end
|
||
|
|
||
|
def self.configure(conf)
|
||
|
si = Specinfra.configuration
|
||
|
si.backend = :winrm
|
||
|
si.os = { family: 'windows' }
|
||
|
|
||
|
# validation
|
||
|
user = conf['user'].to_s
|
||
|
pass = conf['password'].to_s
|
||
|
|
||
|
if user.empty?
|
||
|
warn "We use default 'Administrator' as WinRM user for login."
|
||
|
user = 'Administrator'
|
||
|
end
|
||
|
fail 'You must configure a WinRM password.' if pass.empty?
|
||
|
|
||
|
# create the connection
|
||
|
endpoint = winrm_url(conf)
|
||
|
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
|