Class: WinRM::WSMV::WqlQuery

Inherits:
Base
  • Object
show all
Defined in:
lib/winrm/wsmv/wql_query.rb

Overview

WSMV message to query Windows via WQL

Constant Summary

Constants included from Header

Header::RESOURCE_URI_CMD, Header::RESOURCE_URI_POWERSHELL

Constants included from SOAP

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

Instance Method Summary collapse

Methods inherited from Base

#build

Methods included from 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 SOAP

#namespaces

Constructor Details

#initialize(transport, session_opts, wql, namespace = nil) ⇒ WqlQuery

Returns a new instance of WqlQuery.



22
23
24
25
26
27
# File 'lib/winrm/wsmv/wql_query.rb', line 22

def initialize(transport, session_opts, wql, namespace = nil)
  @session_opts = session_opts
  @wql = wql
  @namespace = namespace
  @transport = transport
end

Instance Method Details

#process_response(response, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/winrm/wsmv/wql_query.rb', line 29

def process_response(response, &block)
  parser = Nori.new(
    parser: :rexml,
    advanced_typecasting: false,
    convert_tags_to: ->(tag) { tag.snakecase.to_sym },
    strip_namespaces: true
  )
  @items = Hash.new { |h, k| h[k] = [] }

  hresp = parser.parse(response.to_s)[:envelope][:body][:enumerate_response]
  process_items hresp[:items], &block

  # Perform WS-Enum PULL's until we have all the elements
  enumeration_context = hresp[:enumeration_context]
  until enumeration_context.nil?
    query = WqlPull.new(@session_opts, @namespace, enumeration_context)
    hresp = query.process_response(@transport.send_request(query.build))[:pull_response]
    process_items hresp[:items], &block
    enumeration_context = hresp[:enumeration_context]
  end

  @items
end