Class: WinRM::PSRP::ReceiveResponseReader

Inherits:
WSMV::ReceiveResponseReader show all
Defined in:
lib/winrm/psrp/receive_response_reader.rb

Overview

Class for reading powershell responses in Receive_Response messages

Constant Summary

Constants included from WSMV::Header

WSMV::Header::RESOURCE_URI_CMD, WSMV::Header::RESOURCE_URI_POWERSHELL

Constants included from WSMV::SOAP

WSMV::SOAP::NS_ADDRESSING, WSMV::SOAP::NS_CIMBINDING, WSMV::SOAP::NS_ENUM, WSMV::SOAP::NS_SCHEMA_INST, WSMV::SOAP::NS_SOAP_ENV, WSMV::SOAP::NS_TRANSFER, WSMV::SOAP::NS_WIN_SHELL, WSMV::SOAP::NS_WSMAN_CONF, WSMV::SOAP::NS_WSMAN_DMTF, WSMV::SOAP::NS_WSMAN_FAULT, WSMV::SOAP::NS_WSMAN_MSFT

Instance Attribute Summary

Attributes inherited from WSMV::ReceiveResponseReader

#logger

Instance Method Summary collapse

Methods inherited from WSMV::ReceiveResponseReader

#read_response

Methods included from WSMV::Header

#action_command, #action_delete, #action_enumerate, #action_enumerate_pull, #action_get, #action_receive, #action_send, #action_signal, #merge_headers, #resource_uri_cmd, #resource_uri_shell, #resource_uri_wmi, #selector_shell_id, #shared_headers

Methods included from WSMV::SOAP

#namespaces

Constructor Details

#initialize(transport, logger) ⇒ ReceiveResponseReader

Creates a new ReceiveResponseReader

Parameters:

  • transport (HttpTransport)

    The WinRM SOAP transport

  • logger (Logger)

    The logger to log diagnostic messages to



26
27
28
29
# File 'lib/winrm/psrp/receive_response_reader.rb', line 26

def initialize(transport, logger)
  super
  @output_decoder = PowershellOutputDecoder.new
end

Instance Method Details

#read_message(wsmv_message, wait_for_done_state = false) {|Message| ... } ⇒ Object

Reads PSRP messages sent in one or more receive response messages

Parameters:

  • wsmv_message (WinRM::WSMV::Base)

    A wsmv message to send to endpoint

  • wait_for_done_state (defaults to: false)

    whether to poll for a CommandState of Done

Yields:

  • (Message)

    PSRP Message in response

Yield Returns:

  • (Array<Message>)

    All messages in response



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/winrm/psrp/receive_response_reader.rb', line 36

def read_message(wsmv_message, wait_for_done_state = false)
  messages = []
  defragmenter = MessageDefragmenter.new
  read_response(wsmv_message, wait_for_done_state) do |stream|
    message = defragmenter.defragment(stream[:text])
    next unless message

    if block_given?
      yield message
    else
      messages.push(message)
    end
  end
  messages unless block_given?
end

#read_output(wsmv_message) {|standard, standard| ... } ⇒ Object

Reads streams and returns decoded output

Parameters:

Yield Parameters:

  • standard (string)

    out response text

  • standard (string)

    error response text

Yield Returns:



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/winrm/psrp/receive_response_reader.rb', line 57

def read_output(wsmv_message)
  with_output do |output|
    read_message(wsmv_message, true) do |message|
      exit_code = find_exit_code(message)
      output.exitcode = exit_code if exit_code
      decoded_text = @output_decoder.decode(message)
      next unless decoded_text

      out = { stream_type(message) => decoded_text }
      output << out
      yield [out[:stdout], out[:stderr]] if block_given?
    end
  end
end