Class: Inspec::Resources::WindowsFileSystemResource

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

Instance Attribute Summary

Attributes inherited from FsManagement

#inspec

Instance Method Summary collapse

Methods inherited from FsManagement

#initialize

Constructor Details

This class inherits a constructor from Inspec::Resources::FsManagement

Instance Method Details

#info(partition) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/inspec/resources/filesystem.rb', line 114

def info(partition)
  cmd = inspec.command <<-EOF.gsub(/^\s*/, "")
    $disk = Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='#{partition}'"
    $disk.Size = $disk.Size / 1KB
    $disk.FreeSpace = $disk.FreeSpace / 1KB
    $disk | select -property DeviceID,Size,FileSystem,FreeSpace | ConvertTo-Json
  EOF

  raise Inspec::Exceptions::ResourceSkipped, "Unable to get available space for partition #{partition}" if cmd.stdout == "" || cmd.exit_status.to_i != 0

  begin
    fs = JSON.parse(cmd.stdout)
  rescue JSON::ParserError => e
    raise Inspec::Exceptions::ResourceFailed,
          "Failed to parse JSON from Powershell. " \
          "Error: #{e}"
  end
  {
    name: fs["DeviceID"],
    size_kb: fs["Size"].to_i,
    free_kb: fs["FreeSpace"].to_i,
    type: fs["FileSystem"],
  }
end