Class: Inspec::Resources::SiteProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/resources/iis_site.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inspec) ⇒ SiteProvider

Returns a new instance of SiteProvider.



98
99
100
# File 'lib/inspec/resources/iis_site.rb', line 98

def initialize(inspec)
  @inspec = inspec
end

Instance Attribute Details

#inspecObject (readonly)

Returns the value of attribute inspec.



96
97
98
# File 'lib/inspec/resources/iis_site.rb', line 96

def inspec
  @inspec
end

Instance Method Details

#iis_site(name) ⇒ Object

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



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/inspec/resources/iis_site.rb', line 103

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