-
Notifications
You must be signed in to change notification settings - Fork 683
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This extends the dependency feature to include support for url-based dependencies. It takes some deviations from the current support for URLs that we'll likely want to make more consistent. To better support vendoring consistently across all future source types, we unpack the tarball into the cache. If we think we are *only* going to support tarballs, we could avoid the unpacking and use the existing streaming support only. Another advnatage of unpacking the tarball into the cache/vendor directory is that eventually most classes would *only* need to care about how to read data from a path on disk and the fetchers would only need to care about how to download and unpack something to a location on disk. Signed-off-by: Steven Danna <steve@chef.io>
- Loading branch information
1 parent
8e10cb4
commit afbce4c
Showing
6 changed files
with
161 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,57 @@ | ||
# encoding: utf-8 | ||
require 'digest' | ||
|
||
module Inspec | ||
class VendorIndex | ||
attr_reader :list, :path | ||
attr_reader :path | ||
def initialize(path) | ||
@path = path | ||
FileUtils.mkdir_p(path) unless File.directory?(path) | ||
@list = Dir[File.join(path, '*')].map { |x| load_path(x) } | ||
end | ||
|
||
def find(_dependency) | ||
# TODO | ||
fail NotImplementedError, '#find(dependency) on VendorIndex seeks implementation.' | ||
# | ||
# For a given name and source_url, return true if the | ||
# profile exists in the VendorIndex. | ||
# | ||
# @param [String] name | ||
# @param [String] source_url | ||
# @return [Boolean] | ||
# | ||
def exists?(name, source_url) | ||
File.exist?("#{path_for(name, source_url)}/inspec.yml") | ||
end | ||
|
||
# | ||
# Return the path to given profile in the vendor index. | ||
# | ||
# The `source_url` parameter should be a URI-like string that | ||
# fully specifies the source of the exact version we want to pull | ||
# down. | ||
# | ||
# @param [String] name | ||
# @param [String] source_url | ||
# @return [String] | ||
# | ||
def path_for(name, source_url) | ||
File.join(@path, key_for(name, source_url)) | ||
end | ||
|
||
private | ||
|
||
def load_path(_path) | ||
# TODO | ||
fail NotImplementedError, '#load_path(path) on VendorIndex wants to be implemented.' | ||
# | ||
# Return the key for a given profile in the vendor index. | ||
# | ||
# The `source_url` parameter should be a URI-like string that | ||
# fully specifies the source of the exact version we want to pull | ||
# down. | ||
# | ||
# @param [String] name | ||
# @param [String] source_url | ||
# @return [String] | ||
# | ||
def key_for(name, source_url) | ||
source_hash = Digest::SHA256.hexdigest source_url | ||
"#{name}-#{source_hash}" | ||
end | ||
end | ||
end |