Class: Inspec::CachedFetcher
- Inherits:
-
Object
- Object
- Inspec::CachedFetcher
- Extended by:
- Forwardable
- Defined in:
- lib/inspec/cached_fetcher.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#fetcher ⇒ Object
readonly
Returns the value of attribute fetcher.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #assert_cache_sanity! ⇒ Object
- #cache_key ⇒ Object
- #fetch ⇒ Object
-
#initialize(target, cache) ⇒ CachedFetcher
constructor
A new instance of CachedFetcher.
- #resolved_source ⇒ Object
- #update_from_opts(_opts) ⇒ Object
Constructor Details
#initialize(target, cache) ⇒ CachedFetcher
Returns a new instance of CachedFetcher.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/inspec/cached_fetcher.rb', line 9 def initialize(target, cache) @target = target @fetcher = Inspec::Fetcher::Registry.resolve(target) if @fetcher.nil? raise("Could not fetch inspec profile in #{target.inspect}.") end @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
8 9 10 |
# File 'lib/inspec/cached_fetcher.rb', line 8 def cache @cache end |
#fetcher ⇒ Object (readonly)
Returns the value of attribute fetcher.
8 9 10 |
# File 'lib/inspec/cached_fetcher.rb', line 8 def fetcher @fetcher end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
8 9 10 |
# File 'lib/inspec/cached_fetcher.rb', line 8 def target @target end |
Instance Method Details
#assert_cache_sanity! ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/inspec/cached_fetcher.rb', line 53 def assert_cache_sanity! return unless target.respond_to?(:key?) && target.key?(:sha256) = <<~EOF The remote source #{fetcher} no longer has the requested content: Request Content Hash: #{target[:sha256]} Actual Content Hash: #{fetcher.resolved_source[:sha256]} For URL, supermarket, compliance, and other sources that do not provide versioned artifacts, this likely means that the remote source has changed since your lockfile was generated. EOF raise if fetcher.resolved_source[:sha256] != target[:sha256] end |
#cache_key ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/inspec/cached_fetcher.rb', line 29 def cache_key k = if target.is_a?(Hash) target[:sha256] || target[:ref] end if k.nil? fetcher.cache_key else k end end |
#fetch ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/inspec/cached_fetcher.rb', line 41 def fetch if cache.exists?(cache_key) Inspec::Log.debug "Using cached dependency for #{target}" [cache.prefered_entry_for(cache_key), false] else Inspec::Log.debug "Dependency does not exist in the cache #{target}" fetcher.fetch(cache.base_path_for(fetcher.cache_key)) assert_cache_sanity! [fetcher.archive_path, fetcher.writable?] end end |
#resolved_source ⇒ Object
20 21 22 23 |
# File 'lib/inspec/cached_fetcher.rb', line 20 def resolved_source fetch @fetcher.resolved_source end |
#update_from_opts(_opts) ⇒ Object
25 26 27 |
# File 'lib/inspec/cached_fetcher.rb', line 25 def update_from_opts(_opts) false end |