Class: Inspec::Plugins::Fetcher

Inherits:
PluginRegistry::Plugin show all
Defined in:
lib/inspec/plugins/fetcher.rb

Overview

An Inspec::Plugins::Fetcher is responsible for fetching a remote source to a local directory or file provided by the user.

In general, there are two kinds of fetchers. (1) Fetchers that implement this entire API (see the Git or Url fetchers for examples), and (2) fetchers that only implement self.resolve and then call the resolve_next method with a modified target hash. Fetchers in (2) do not need to implement the functions in this class because the caller will never actually get an instance of those fetchers.

Instance Attribute Summary

Attributes inherited from PluginRegistry::Plugin

#parent, #target

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PluginRegistry::Plugin

name, priority, resolve, resolve_next

Class Method Details

.plugin_registryObject



23
24
25
# File 'lib/inspec/plugins/fetcher.rb', line 23

def self.plugin_registry
  Inspec::Fetcher
end

Instance Method Details

#archive_pathObject

The path to the archive on disk. This can be passed to a FileProvider to get access to the files in the fetched profile.



32
33
34
# File 'lib/inspec/plugins/fetcher.rb', line 32

def archive_path
  fail "Fetcher #{self} does not implement `archive_path()`. This is required."
end

#cache_keyObject

A string based on the components of the resolved source, suitable for constructing per-source file names.



77
78
79
80
81
82
83
# File 'lib/inspec/plugins/fetcher.rb', line 77

def cache_key
  key = ''
  resolved_source.each do |k, v|
    key << "#{k}:#{v}"
  end
  Digest::SHA256.hexdigest key
end

#fetch(_path) ⇒ Object

Fetches the remote source to a local source, using the provided path as a partial filename. That is, if you pass /foo/bar/baz, the fetcher can create:

/foo/bar/baz/: A profile directory, or /foo/bar/baz.tar.gz: A profile tarball, or /foo/bar/baz.zip



45
46
47
# File 'lib/inspec/plugins/fetcher.rb', line 45

def fetch(_path)
  fail "Fetcher #{self} does not implement `fetch()`. This is required."
end

#relative_targetObject

relative_target is provided to keep compatibility with 3rd party plugins.

Deprecated: This function may be removed in future versions of Inspec, don’t depend on it in new plugins.



68
69
70
71
# File 'lib/inspec/plugins/fetcher.rb', line 68

def relative_target
  file_provider = Inspec::FileProvider.for_path(archive_path)
  file_provider.relative_provider
end

#resolved_sourceObject

The full specification of the remote source, with any ambigious references provided by the user resolved to an exact reference where possible. For example, in the Git provide, a tag will be resolved to an exact revision.



55
56
57
# File 'lib/inspec/plugins/fetcher.rb', line 55

def resolved_source
  fail "Fetcher #{self} does not implement `resolved_source()`. This is required for terminal fetchers."
end