mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
feature: start github uri reader
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
parent
9065eaa35c
commit
7a59d9ce76
4 changed files with 38 additions and 13 deletions
|
@ -1,7 +1,7 @@
|
|||
# encoding: utf-8
|
||||
|
||||
module Vulcano::Targets
|
||||
class FileTarget
|
||||
class FileHelper
|
||||
def handles?(target)
|
||||
File::file?(target) and target.end_with?('.rb')
|
||||
end
|
||||
|
@ -14,5 +14,5 @@ module Vulcano::Targets
|
|||
end
|
||||
end
|
||||
|
||||
Vulcano::Targets.add_module('file', FileTarget.new)
|
||||
Vulcano::Targets.add_module('file', FileHelper.new)
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'vulcano/targets/dir'
|
|||
require 'vulcano/targets/file'
|
||||
|
||||
module Vulcano::Targets
|
||||
class FolderTarget
|
||||
class FolderHelper
|
||||
def handles?(target)
|
||||
File::directory?(target)
|
||||
end
|
||||
|
@ -27,5 +27,5 @@ module Vulcano::Targets
|
|||
end
|
||||
end
|
||||
|
||||
Vulcano::Targets.add_module('folder', FolderTarget.new)
|
||||
Vulcano::Targets.add_module('folder', FolderHelper.new)
|
||||
end
|
||||
|
|
|
@ -1,15 +1,38 @@
|
|||
# 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
|
||||
|
||||
class UrlTarget
|
||||
def handles?(target)
|
||||
uri = URI.parse(target)
|
||||
%{ http https }.include? uri.scheme
|
||||
end
|
||||
|
||||
def resolve(target)
|
||||
raise "TODO"
|
||||
end
|
||||
Vulcano::Targets.add_module('url', UrlHelper.new)
|
||||
|
||||
end
|
||||
|
||||
Vulcano::Targets.add_module('url', UrlTarget.new)
|
||||
|
|
|
@ -29,4 +29,6 @@ Gem::Specification.new do |spec|
|
|||
spec.add_dependency 'rainbow', '~> 2'
|
||||
spec.add_dependency 'serverspec', '~> 2.18'
|
||||
spec.add_dependency 'method_source', '~> 0.8'
|
||||
spec.add_dependency 'rubyzip', '~> 1.1'
|
||||
spec.add_dependency 'rspec', '~> 3.3'
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue