class Inspec::Resources::IisApp

Public Class Methods

new(path, site_name) click to toggle source
# File lib/inspec/resources/iis_app.rb, line 20
def initialize(path, site_name)
  @path = path
  @site_name = site_name
  @cache = nil
  @inspec = inspec
end

Public Instance Methods

application_pool() click to toggle source
# File lib/inspec/resources/iis_app.rb, line 27
def application_pool
  iis_app[:application_pool]
end
exists?() click to toggle source
# File lib/inspec/resources/iis_app.rb, line 47
def exists?
  !iis_app[:path].empty?
end
has_application_pool?(application_pool) click to toggle source
# File lib/inspec/resources/iis_app.rb, line 55
def has_application_pool?(application_pool)
  iis_app[:application_pool] == application_pool
end
has_path?(path) click to toggle source
# File lib/inspec/resources/iis_app.rb, line 59
def has_path?(path)
  iis_app[:path] == path
end
has_physical_path?(physical_path) click to toggle source
# File lib/inspec/resources/iis_app.rb, line 63
def has_physical_path?(physical_path)
  iis_app[:physical_path] == physical_path
end
has_protocol?(protocol) click to toggle source
# File lib/inspec/resources/iis_app.rb, line 67
def has_protocol?(protocol)
  iis_app[:protocols].include?(protocol)
end
has_site_name?(site_name) click to toggle source
# File lib/inspec/resources/iis_app.rb, line 51
def has_site_name?(site_name)
  iis_app[:site_name] == site_name
end
path() click to toggle source
# File lib/inspec/resources/iis_app.rb, line 39
def path
  iis_app[:path]
end
physical_path() click to toggle source
# File lib/inspec/resources/iis_app.rb, line 43
def physical_path
  iis_app[:physical_path]
end
protocols() click to toggle source
# File lib/inspec/resources/iis_app.rb, line 31
def protocols
  iis_app[:protocols]
end
site_name() click to toggle source
# File lib/inspec/resources/iis_app.rb, line 35
def site_name
  iis_app[:site_name]
end
to_s() click to toggle source
# File lib/inspec/resources/iis_app.rb, line 71
def to_s
  "iis_app '#{@site_name}#{@path}'"
end

Private Instance Methods

iis_app() click to toggle source
# File lib/inspec/resources/iis_app.rb, line 77
def iis_app
  return @cache unless @cache.nil?

  command = "Import-Module WebAdministration; Get-WebApplication -Name '#{@path}' -Site '#{@site_name}' | Select-Object * | ConvertTo-Json"
  cmd = @inspec.command(command)

  begin
    app = JSON.parse(cmd.stdout)
  rescue JSON::ParserError => _e
    return {}
  end

  # map our values to a hash table
  info = {
    site_name: @site_name,
    path: @path,
    application_pool: app["applicationPool"],
    physical_path: app["PhysicalPath"],
    protocols: app["enabledProtocols"],
  }

  @cache = info unless info.nil?
end