inspec/lib/vulcano/targets/url.rb
Dominik Richter 7a59d9ce76 feature: start github uri reader
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
2015-08-12 22:34:37 -07:00

38 lines
805 B
Ruby

# encoding: utf-8
require 'uri'
require 'tempfile'
require 'open-uri'
require 'vulcano/targets/zip'
module Vulcano::Targets
class UrlHelper
def handles?(target)
uri = URI.parse(target)
%{ http https }.include? uri.scheme
end
def resolve(target)
if target.start_with? "https://github.com" and target.end_with? ".git"
url = target.sub(/.git$/,'') + '/archive/master.zip'
return resolve_zip(url)
else
end
end
def resolve_zip(url)
zipfile = Tempfile.new('vulcano-dl-')
zipfile.binmode
zipfile.write(open(url).read)
zipfile.rewind
content = ZipHelper.resolve(zipfile.path)
zipfile.close
zipfile.unlink
return content
end
end
Vulcano::Targets.add_module('url', UrlHelper.new)
end