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.



94
95
96
# File 'lib/inspec/resources/iis_site.rb', line 94

def initialize(inspec)
  @inspec = inspec
end

Instance Attribute Details

#inspecObject (readonly)

Returns the value of attribute inspec.



92
93
94
# File 'lib/inspec/resources/iis_site.rb', line 92

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



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# 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