Class: CookbookOmnifetch::ArtifactoryLocation
- Inherits:
-
BaseLocation
- Object
- BaseLocation
- CookbookOmnifetch::ArtifactoryLocation
- Defined in:
- lib/cookbook-omnifetch/artifactory.rb
Instance Attribute Summary collapse
-
#cookbook_version ⇒ Object
readonly
Returns the value of attribute cookbook_version.
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Attributes inherited from BaseLocation
Instance Method Summary collapse
- #cache_key ⇒ Object
-
#cache_path ⇒ Pathname
The path where the pristine tarball is cached.
-
#cache_root ⇒ Pathname
The path where all pristine tarballs from an artifactory are held.
-
#cached_cookbook ⇒ CachedCookbook
The cached cookbook for this location.
- #cookbook_name ⇒ Object
-
#initialize(dependency, options = {}) ⇒ ArtifactoryLocation
constructor
A new instance of ArtifactoryLocation.
-
#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.
- #lock_data ⇒ Object
- #repo_host ⇒ Object
- #sanitized_version ⇒ Object
-
#staging_root ⇒ Pathname
The path where tarballs are downloaded to and unzipped.
-
#to_lock ⇒ string
The lockfile representation of this location.
Methods inherited from BaseLocation
Constructor Details
#initialize(dependency, options = {}) ⇒ ArtifactoryLocation
Returns a new instance of ArtifactoryLocation.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/cookbook-omnifetch/artifactory.rb', line 14 def initialize(dependency, = {}) super @uri ||= [:artifactory] @cookbook_version = [:version] if [:http_client] @http_client = [:http_client] else headers = { "X-Jfrog-Art-API" => Chef::Config.artifactory_api_key || ENV["ARTIFACTORY_API_KEY"] } @http_client = Chef::HTTP::Simple.new(uri, headers: headers) end end |
Instance Attribute Details
#cookbook_version ⇒ Object (readonly)
Returns the value of attribute cookbook_version.
11 12 13 |
# File 'lib/cookbook-omnifetch/artifactory.rb', line 11 def cookbook_version @cookbook_version end |
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client.
12 13 14 |
# File 'lib/cookbook-omnifetch/artifactory.rb', line 12 def http_client @http_client end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
10 11 12 |
# File 'lib/cookbook-omnifetch/artifactory.rb', line 10 def uri @uri end |
Instance Method Details
#cache_key ⇒ Object
74 75 76 |
# File 'lib/cookbook-omnifetch/artifactory.rb', line 74 def cache_key "#{dependency.name}-#{cookbook_version}-#{repo_host}" end |
#cache_path ⇒ Pathname
The path where the pristine tarball is cached
127 128 129 |
# File 'lib/cookbook-omnifetch/artifactory.rb', line 127 def cache_path cache_root.join("#{cache_key}.tgz") end |
#cache_root ⇒ Pathname
The path where all pristine tarballs from an artifactory are held. Tarballs are moved/swapped into this location once they have been staged in a co-located staging directory.
106 107 108 |
# File 'lib/cookbook-omnifetch/artifactory.rb', line 106 def cache_root Pathname.new(CookbookOmnifetch.cache_path).join(".cache", "artifactory") end |
#cached_cookbook ⇒ CachedCookbook
The cached cookbook for this location.
81 82 83 84 |
# File 'lib/cookbook-omnifetch/artifactory.rb', line 81 def cached_cookbook raise AbstractFunction, "#cached_cookbook must be implemented on #{self.class.name}!" end |
#cookbook_name ⇒ Object
30 31 32 |
# File 'lib/cookbook-omnifetch/artifactory.rb', line 30 def cookbook_name dependency.name 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.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cookbook-omnifetch/artifactory.rb', line 45 def install FileUtils.mkdir_p(cache_root) unless cache_root.exist? http_client.streaming_request(nil) do |tempfile| tempfile.close FileUtils.mv(tempfile.path, cache_path) end FileUtils.mkdir_p(staging_root) unless staging_root.exist? Dir.mktmpdir(nil, staging_root) do |staging_dir| Mixlib::Archive.new(cache_path).extract(staging_dir, perms: false) 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.
70 71 72 |
# File 'lib/cookbook-omnifetch/artifactory.rb', line 70 def install_path @install_path ||= CookbookOmnifetch.storage_path.join(cache_key) end |
#installed? ⇒ Boolean
Determine if this revision is installed.
37 38 39 |
# File 'lib/cookbook-omnifetch/artifactory.rb', line 37 def installed? install_path.exist? end |
#lock_data ⇒ Object
86 87 88 89 90 91 |
# File 'lib/cookbook-omnifetch/artifactory.rb', line 86 def lock_data out = {} out["artifactory"] = uri out["version"] = cookbook_version out end |
#repo_host ⇒ Object
26 27 28 |
# File 'lib/cookbook-omnifetch/artifactory.rb', line 26 def repo_host @host ||= URI.parse(uri).host end |
#sanitized_version ⇒ Object
62 63 64 |
# File 'lib/cookbook-omnifetch/artifactory.rb', line 62 def sanitized_version cookbook_version end |
#staging_root ⇒ Pathname
The path where tarballs are downloaded to and unzipped. On certain platforms you have a better chance of getting an atomic move if your temporary working directory is on the same device/volume as the destination. To support this, we use a staging directory located under the cache path under the rather mild assumption that everything under the cache path is going to be on one device.
Do not create anything under this directory that isn’t randomly named and remember to release your files once you are done.
120 121 122 |
# File 'lib/cookbook-omnifetch/artifactory.rb', line 120 def staging_root Pathname.new(CookbookOmnifetch.cache_path).join(".cache_tmp", "artifactory") end |
#to_lock ⇒ string
The lockfile representation of this location.
96 97 98 99 |
# File 'lib/cookbook-omnifetch/artifactory.rb', line 96 def to_lock raise AbstractFunction, "#to_lock must be implemented on #{self.class.name}!" end |