Method: Inspec::IafProvider#initialize

Defined in:
lib/inspec/file_provider.rb

#initialize(path) ⇒ IafProvider

Returns a new instance of IafProvider.



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/inspec/file_provider.rb', line 230

def initialize(path)
  f = File.open(path, "rb")
  version = f.readline.strip!
  if version == "INSPEC-PROFILE-1"
    while f.readline != "\n" do end
    content = f.read
    f.close
  elsif version == "INSPEC-PROFILE-2"
    f.readline.strip!
    content = f.read
    f.close
    content = content.slice(490, content.length).lstrip
  else
    raise Inspec::InvalidProfileSignature, "Unrecognized IAF version."
  end

  tmpfile = nil
  Dir.mktmpdir do |workdir|
    tmpfile = Pathname.new(workdir).join("temp_profile.tar.gz")
    File.open(tmpfile, "wb") { |fl| fl.write(content) }
    super(tmpfile)
  end
end