Module: LinuxMountParser

Included in:
Inspec::Resources::FileResource, Inspec::Resources::LinuxMounts
Defined in:
lib/utils/parser.rb

Instance Method Summary collapse

Instance Method Details

#parse_mount_options(mount_line, compatibility = false) ⇒ Object

this parses the output of mount command (only tested on linux) this method expects only one line of the mount output



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/utils/parser.rb', line 69

def parse_mount_options(mount_line, compatibility = false)
  mount = mount_line.scan(/\S+/)

  # parse device and type
  mount_options    = { device: mount[0], type: mount[4] }

  if compatibility == false
    # parse options as array
    mount_options[:options] = mount[5].gsub(/\(|\)/, '').split(',')
  else
    # parse options as serverspec uses it, tbis is deprecated
    mount_options[:options] = {}
    mount[5].gsub(/\(|\)/, '').split(',').each do |option|
      name, val = option.split('=')
      if val.nil?
        val = true
      elsif val =~ /^\d+$/
        # parse numbers
        val = val.to_i
      end
      mount_options[:options][name.to_sym] = val
    end
  end

  mount_options
end