Class: CookbookOmnifetch::ArtifactserverLocation
- Inherits:
-
BaseLocation
- Object
- BaseLocation
- CookbookOmnifetch::ArtifactserverLocation
- Defined in:
- lib/cookbook-omnifetch/artifactserver.rb
Instance Attribute Summary collapse
-
#cookbook_version ⇒ Object
readonly
Returns the value of attribute cookbook_version.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Attributes inherited from BaseLocation
Instance Method Summary collapse
- #==(other) ⇒ Object
- #cache_key ⇒ Object
-
#cache_path ⇒ Pathname
The path where the pristine tarball is cached.
- #cache_root ⇒ Object
-
#cached_cookbook ⇒ CachedCookbook
The cached cookbook for this location.
- #cookbook_name ⇒ Object
-
#http_client(uri) ⇒ Object
TODO: DI this.
-
#initialize(dependency, options = {}) ⇒ ArtifactserverLocation
constructor
A new instance of ArtifactserverLocation.
-
#install ⇒ void
Install the given cookbook.
-
#install_path ⇒ Pathname?
The path where this cookbook would live in the store, if it were installed.
-
#installed? ⇒ Boolean
Determine if this revision is installed.
- #repo_host ⇒ Object
- #sanitized_version ⇒ Object
-
#to_lock ⇒ string
The lockfile representation of this location.
Methods inherited from BaseLocation
Constructor Details
#initialize(dependency, options = {}) ⇒ ArtifactserverLocation
Returns a new instance of ArtifactserverLocation.
15 16 17 18 19 |
# File 'lib/cookbook-omnifetch/artifactserver.rb', line 15 def initialize(dependency, = {}) super @uri ||= [:artifactserver] @cookbook_version = [:version] end |
Instance Attribute Details
#cookbook_version ⇒ Object (readonly)
Returns the value of attribute cookbook_version.
13 14 15 |
# File 'lib/cookbook-omnifetch/artifactserver.rb', line 13 def cookbook_version @cookbook_version end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
12 13 14 |
# File 'lib/cookbook-omnifetch/artifactserver.rb', line 12 def uri @uri end |
Instance Method Details
#==(other) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/cookbook-omnifetch/artifactserver.rb', line 100 def ==(other) raise "TODO" other.is_a?(GitLocation) && other.uri == uri && other.branch == branch && other.tag == tag && other.shortref == shortref && other.rel == rel end |
#cache_key ⇒ Object
79 80 81 |
# File 'lib/cookbook-omnifetch/artifactserver.rb', line 79 def cache_key "#{dependency.name}-#{cookbook_version}-#{repo_host}" end |
#cache_path ⇒ Pathname
The path where the pristine tarball is cached
117 118 119 |
# File 'lib/cookbook-omnifetch/artifactserver.rb', line 117 def cache_path cache_root.join("#{cache_key}.tgz") end |
#cache_root ⇒ Object
110 111 112 |
# File 'lib/cookbook-omnifetch/artifactserver.rb', line 110 def cache_root Pathname.new(CookbookOmnifetch.cache_path).join('.cache', 'artifactserver') end |
#cached_cookbook ⇒ CachedCookbook
The cached cookbook for this location.
86 87 88 89 |
# File 'lib/cookbook-omnifetch/artifactserver.rb', line 86 def cached_cookbook raise AbstractFunction, "#cached_cookbook must be implemented on #{self.class.name}!" end |
#cookbook_name ⇒ Object
25 26 27 |
# File 'lib/cookbook-omnifetch/artifactserver.rb', line 25 def cookbook_name dependency.name end |
#http_client(uri) ⇒ Object
TODO: DI this.
63 64 65 |
# File 'lib/cookbook-omnifetch/artifactserver.rb', line 63 def http_client(uri) Chef::HTTP::Simple.new(uri) end |
#install ⇒ void
This method returns an undefined value.
Install the given cookbook. Subclasses that implement this method should perform all the installation and validation steps required.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cookbook-omnifetch/artifactserver.rb', line 40 def install FileUtils.mkdir_p(cache_root) unless cache_root.exist? http = http_client(uri) http.streaming_request(nil) do |tempfile| tempfile.close FileUtils.mv(tempfile.path, cache_path) end Dir.mktmpdir do |staging_dir| Zlib::GzipReader.open(cache_path) do |gz_file| tar = Archive::Tar::Minitar::Input.new(gz_file) tar.each do |e| tar.extract_entry(staging_dir, e) end end staged_cookbook_path = File.join(staging_dir, cookbook_name) validate_cached!(staged_cookbook_path) FileUtils.mv(staged_cookbook_path, install_path) end end |
#install_path ⇒ Pathname?
The path where this cookbook would live in the store, if it were installed.
75 76 77 |
# File 'lib/cookbook-omnifetch/artifactserver.rb', line 75 def install_path @install_path ||= CookbookOmnifetch.storage_path.join(cache_key) end |
#installed? ⇒ Boolean
Determine if this revision is installed.
32 33 34 |
# File 'lib/cookbook-omnifetch/artifactserver.rb', line 32 def installed? install_path.exist? end |
#repo_host ⇒ Object
21 22 23 |
# File 'lib/cookbook-omnifetch/artifactserver.rb', line 21 def repo_host @host ||= URI.parse(uri).host end |
#sanitized_version ⇒ Object
67 68 69 |
# File 'lib/cookbook-omnifetch/artifactserver.rb', line 67 def sanitized_version cookbook_version end |
#to_lock ⇒ string
The lockfile representation of this location.
94 95 96 97 |
# File 'lib/cookbook-omnifetch/artifactserver.rb', line 94 def to_lock raise AbstractFunction, "#to_lock must be implemented on #{self.class.name}!" end |