Class: Inspec::Resources::WindowsFileSystemResource

Inherits:
FsManagement
  • Object
show all
Defined in:
lib/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



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/resources/filesystem.rb', line 82

def info(partition)
  cmd = inspec.command <<-EOF.gsub(/^\s*/, '')
    $disk = Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='#{partition}'"
    $disk.Size = $disk.Size / 1GB
    $disk | select -property DeviceID,Size,FileSystem | 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: fs['Size'].to_i,
    type: fs['FileSystem'],
  }
end