Class: Inspec::Targets::UrlHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/targets/url.rb

Instance Method Summary collapse

Instance Method Details

#handles?(target) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/inspec/targets/url.rb', line 12

def handles?(target)
  uri = URI.parse(target)
  return false if uri.nil? or uri.scheme.nil?
  %{ http https }.include? uri.scheme
end

#resolve(target) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/inspec/targets/url.rb', line 18

def resolve(target)
  return nil unless target.start_with? 'https://github.com' and
                    target.end_with? '.git'

  url = target.sub(/.git$/, '') + '/archive/master.zip'
  resolve_zip(url)
end

#resolve_zip(url) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/inspec/targets/url.rb', line 26

def resolve_zip(url)
  zipfile = Tempfile.new('inspec-dl-')
  zipfile.binmode
  zipfile.write(open(url).read)
  zipfile.rewind
  content = ZipHelper.new.resolve(zipfile.path)
  zipfile.close
  zipfile.unlink
  content
end