class PatchFinder::Engine::MSU::Technet

Attributes

firstpage[R]

Public Class Methods

new() click to toggle source

Initializes the Technet client.

@return [void]

# File lib/patch_finder/engine/msu/technet.rb, line 16
def initialize
  @firstpage ||= lambda {
    uri = '/en-us/security/bulletin/dn602597.aspx'
    res = send_http_get_request("#{TECHNET}#{uri}")
    return res.body
  }.call
end

Public Instance Methods

find_msb_numbers(keyword) click to toggle source

Returns the MSB (advisories) numbers for a search keyword.

@param keyword [String] @return [Array]

# File lib/patch_finder/engine/msu/technet.rb, line 28
def find_msb_numbers(keyword)
  product_list_matches = get_product_dropdown_list.select { |p| Regexp.new(keyword) === p[:option_text] }
  if product_list_matches.empty?
    print_verbose('No match from the product list, attempting a generic search')
    search_by_keyword(keyword)
  else
    product_names = []
    ids = []
    product_list_matches.each do |e|
      ids << e[:option_value]
      product_names << e[:option_text]
    end
    print_verbose("Matches from the product list (#{product_names.length}): #{ product_names * ', ' }")
    search_by_product_ids(ids)
  end
end
get_product_dropdown_list() click to toggle source

Returns the Technet product list.

@return [Array]

# File lib/patch_finder/engine/msu/technet.rb, line 95
def get_product_dropdown_list
  @product_dropdown_list ||= lambda {
    list = []

    page = ::Nokogiri::HTML(firstpage)
    page.search('//div[@class="sb-search"]//select[@id="productDropdown"]//option').each do |product|
      option_value = product.attributes['value'].value
      option_text  = product.text
      next if option_value == '-1' # This is the ALL option
      list << { option_value: option_value, option_text: option_text }
    end

    list
  }.call
end
search_by_keyword(keyword) click to toggle source

Searches for the MSBs (advisories) based on a keyword.

@param keyword [String] @return [Hash]

# File lib/patch_finder/engine/msu/technet.rb, line 87
def search_by_keyword(keyword)
  j = search(keyword)
  j['b'].collect { |e| e['Id'] }.map { |e| e.downcase }
end
search_by_product_ids(ids) click to toggle source

Searches for the MSBs (advisories) based on product IDs (as search keywords)

@param ids [Array] @return [Array]

# File lib/patch_finder/engine/msu/technet.rb, line 71
def search_by_product_ids(ids)
  msb_numbers = []

  ids.each do |id|
    j = search(id)
    msb = j['b'].collect { |e| e['Id'] }.map { |e| e.downcase }
    msb_numbers.concat(msb)
  end

  msb_numbers
end