class WinRM::WSMV::CreateShell
WSMV
message to create a remote shell
Constants
- UTF8_CODE_PAGE
utf8 as default codepage msdn.microsoft.com/en-us/library/dd317756(VS.85).aspx
Attributes
codepage[RW]
env_vars[RW]
i_stream[RW]
idle_timeout[RW]
noprofile[RW]
o_stream[RW]
working_directory[RW]
Public Class Methods
new(session_opts, shell_opts = {})
click to toggle source
# File lib/winrm/wsmv/create_shell.rb, line 29 def initialize(session_opts, shell_opts = {}) @session_opts = session_opts @shell_uri = opt_or_default(shell_opts, :shell_uri, RESOURCE_URI_CMD) @i_stream = opt_or_default(shell_opts, :i_stream, 'stdin') @o_stream = opt_or_default(shell_opts, :o_stream, 'stdout stderr') @codepage = opt_or_default(shell_opts, :codepage, UTF8_CODE_PAGE) @noprofile = opt_or_default(shell_opts, :noprofile, 'FALSE') @working_directory = opt_or_default(shell_opts, :working_directory) @idle_timeout = opt_or_default(shell_opts, :idle_timeout) @env_vars = opt_or_default(shell_opts, :env_vars) end
Protected Instance Methods
create_body(body)
click to toggle source
# File lib/winrm/wsmv/create_shell.rb, line 47 def create_body(body) body.tag!("#{NS_WIN_SHELL}:Shell") { |s| s << Gyoku.xml(shell_body) } end
create_header(header)
click to toggle source
# File lib/winrm/wsmv/create_shell.rb, line 43 def create_header(header) header << Gyoku.xml(shell_headers) end
Private Instance Methods
action_create()
click to toggle source
# File lib/winrm/wsmv/create_shell.rb, line 91 def action_create { "#{NS_ADDRESSING}:Action" => 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Create', :attributes! => { "#{NS_ADDRESSING}:Action" => { 'mustUnderstand' => true } } } end
environment_vars_body()
click to toggle source
# File lib/winrm/wsmv/create_shell.rb, line 73 def environment_vars_body { "#{NS_WIN_SHELL}:Variable" => @env_vars.values, :attributes! => { "#{NS_WIN_SHELL}:Variable" => { 'Name' => @env_vars.keys } } } end
format_idle_timeout(timeout)
click to toggle source
backwards compat - idle_timeout
as an Iso8601Duration
string
# File lib/winrm/wsmv/create_shell.rb, line 69 def format_idle_timeout(timeout) timeout.is_a?(String) ? timeout : Iso8601Duration.sec_to_dur(timeout) end
header_opts()
click to toggle source
# File lib/winrm/wsmv/create_shell.rb, line 102 def header_opts { "#{NS_WSMAN_DMTF}:OptionSet" => { "#{NS_WSMAN_DMTF}:Option" => [@noprofile, @codepage], :attributes! => { "#{NS_WSMAN_DMTF}:Option" => { 'Name' => %w[WINRS_NOPROFILE WINRS_CODEPAGE] } } } } end
opt_or_default(shell_opts, key, default_value = nil)
click to toggle source
# File lib/winrm/wsmv/create_shell.rb, line 53 def opt_or_default(shell_opts, key, default_value = nil) shell_opts.key?(key) ? shell_opts[key] : default_value end
shell_body()
click to toggle source
# File lib/winrm/wsmv/create_shell.rb, line 57 def shell_body body = { "#{NS_WIN_SHELL}:InputStreams" => @i_stream, "#{NS_WIN_SHELL}:OutputStreams" => @o_stream } body["#{NS_WIN_SHELL}:WorkingDirectory"] = @working_directory if @working_directory body["#{NS_WIN_SHELL}:IdleTimeOut"] = format_idle_timeout(@idle_timeout) if @idle_timeout body["#{NS_WIN_SHELL}:Environment"] = environment_vars_body if @env_vars body end
shell_headers()
click to toggle source
# File lib/winrm/wsmv/create_shell.rb, line 84 def shell_headers merge_headers(shared_headers(@session_opts), resource_uri_shell(@shell_uri), action_create, header_opts) end