class Inspec::Resources::SiteProvider

Attributes

inspec[R]

Public Class Methods

new(inspec) click to toggle source
# File lib/inspec/resources/iis_site.rb, line 94
def initialize(inspec)
  @inspec = inspec
end

Public Instance Methods

iis_site(name) click to toggle source

want to populate everything using one powershell command here and spit it out as json

# File lib/inspec/resources/iis_site.rb, line 99
def iis_site(name)
  command = "Get-Website '#{name}' | Select-Object -Property Name,State,PhysicalPath,bindings,ApplicationPool | ConvertTo-Json"
  cmd = @inspec.command(command)

  begin
    site = JSON.parse(cmd.stdout)
  rescue JSON::ParserError => _e
    return nil
  end

  bindings_array = site["bindings"]["Collection"].map do |k|
    "#{k["protocol"]} #{k["bindingInformation"]}#{k["protocol"] == "https" ? " sslFlags=#{k["sslFlags"]}" : ""}"
  end

  # map our values to a hash table
  info = {
    name: site["name"],
    state: site["state"],
    path: site["physicalPath"],
    bindings: bindings_array,
    app_pool: site["applicationPool"],
  }

  info
end