2016-02-21 01:02:39 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# author: Dominik Richter
|
|
|
|
# author: Christoph Hartmann
|
|
|
|
|
|
|
|
module Fetchers
|
|
|
|
class Local < Inspec.fetcher(1)
|
|
|
|
name 'local'
|
|
|
|
priority 0
|
|
|
|
|
|
|
|
def self.resolve(target)
|
2016-09-08 09:11:44 +00:00
|
|
|
local_path = if target.is_a?(String)
|
|
|
|
resolve_from_string(target)
|
|
|
|
elsif target.is_a?(Hash)
|
|
|
|
resolve_from_hash(target)
|
|
|
|
end
|
|
|
|
|
|
|
|
if local_path
|
|
|
|
new(local_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.resolve_from_hash(target)
|
|
|
|
if target.key?(:path)
|
|
|
|
local_path = target[:path]
|
|
|
|
if target.key?(:cwd)
|
|
|
|
local_path = File.expand_path(local_path, target[:cwd])
|
|
|
|
end
|
|
|
|
local_path
|
|
|
|
end
|
|
|
|
end
|
2016-08-19 14:21:04 +00:00
|
|
|
|
2016-09-08 09:11:44 +00:00
|
|
|
def self.resolve_from_string(target)
|
2016-08-19 14:21:04 +00:00
|
|
|
# Support "urls" in the form of file://
|
|
|
|
if target.start_with?('file://')
|
|
|
|
target = target.gsub(%r{^file://}, '')
|
2016-06-30 03:18:30 +00:00
|
|
|
else
|
|
|
|
# support for windows paths
|
2016-08-24 14:06:12 +00:00
|
|
|
target = target.tr('\\', '/')
|
2016-08-19 14:21:04 +00:00
|
|
|
end
|
|
|
|
|
2016-09-08 09:11:44 +00:00
|
|
|
if File.exist?(target)
|
|
|
|
target
|
2016-08-17 13:25:07 +00:00
|
|
|
end
|
2016-02-21 01:02:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(target)
|
2016-08-19 14:21:04 +00:00
|
|
|
@target = target
|
2016-02-21 01:02:39 +00:00
|
|
|
end
|
|
|
|
|
2016-09-08 09:11:44 +00:00
|
|
|
def fetch(_path)
|
|
|
|
archive_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def archive_path
|
|
|
|
@target
|
|
|
|
end
|
|
|
|
|
|
|
|
def resolved_source
|
|
|
|
{ path: @target }
|
2016-02-21 01:02:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|