cookbook-omnifetch 0.8.1 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d885dea1d6f27e93aa303376a7caddd2725945daff18a30c07da8a98bebc5bd
4
- data.tar.gz: ca7bde1e963ce293d9f04d2fc3f09dc07fb76d33c4a014998d92bbb9faf08500
3
+ metadata.gz: b6b7baff1c908f3ee02466f86ff7225a6a567006ed325313514d429eb07bddaa
4
+ data.tar.gz: a30c239d1ff4f032738cf9755226aff95e6f7df330c5119b367fa520306a9372
5
5
  SHA512:
6
- metadata.gz: 32cb4fc4f4af6122720bb3bd3e4e8841f526c237a70b44041d38025eaefebcfaf1e7c79e078972d8908349fef2bdca8c94a49f3e231b66dd31efd5fca73c7899
7
- data.tar.gz: ea541a9ca6d65c6ca4d50865fcf6b7ee975f04e4bf644d062cf6f35a54a7eba9adc76b90bb694c14045513813138478f3c3ac47f06610c5e9a289dc5d4bbc238
6
+ metadata.gz: c7f11e46181d038e79d55e527ebc743b977ed012ad0630dbfe8f687bdc36c9638a0a7e70eb24feacc1fc2ef960cdd68f4cdbff55eea8d5bdd98c5f29f2b25962
7
+ data.tar.gz: 5ad4d570c3fe10fa6f30c055d8bb0d73dd24fc1a90c15fe804007bda3b9738780d0e87128ecfae2cb569e5bdba949ad3d2f3e48999e58c27b99dd970f4cae297
@@ -1,14 +1,14 @@
1
- require "cookbook-omnifetch/version"
2
- require "cookbook-omnifetch/integration"
3
-
4
- require "cookbook-omnifetch/base"
5
- require "cookbook-omnifetch/git"
6
- require "cookbook-omnifetch/github"
7
- require "cookbook-omnifetch/path"
8
- require "cookbook-omnifetch/artifactserver"
9
- require "cookbook-omnifetch/artifactory"
10
- require "cookbook-omnifetch/chef_server"
11
- require "cookbook-omnifetch/chef_server_artifact"
1
+ require_relative "cookbook-omnifetch/version"
2
+ require_relative "cookbook-omnifetch/integration"
3
+
4
+ require_relative "cookbook-omnifetch/base"
5
+ require_relative "cookbook-omnifetch/git"
6
+ require_relative "cookbook-omnifetch/github"
7
+ require_relative "cookbook-omnifetch/path"
8
+ require_relative "cookbook-omnifetch/artifactserver"
9
+ require_relative "cookbook-omnifetch/artifactory"
10
+ require_relative "cookbook-omnifetch/chef_server"
11
+ require_relative "cookbook-omnifetch/chef_server_artifact"
12
12
 
13
13
  module CookbookOmnifetch
14
14
 
@@ -1,7 +1,7 @@
1
- require "cookbook-omnifetch/base"
1
+ require_relative "base"
2
2
 
3
- require "mixlib/archive"
4
- require "tmpdir"
3
+ require "mixlib/archive" unless defined?(Mixlib::Archive)
4
+ require "tmpdir" unless defined?(Dir.mktmpdir)
5
5
 
6
6
  module CookbookOmnifetch
7
7
 
@@ -15,7 +15,12 @@ module CookbookOmnifetch
15
15
  super
16
16
  @uri ||= options[:artifactory]
17
17
  @cookbook_version = options[:version]
18
- @http_client = options[:http_client]
18
+ if options[:http_client]
19
+ @http_client = options[:http_client]
20
+ else
21
+ headers = { "X-Jfrog-Art-API" => Chef::Config.artifactory_api_key || ENV["ARTIFACTORY_API_KEY"] }
22
+ @http_client = Chef::HTTP::Simple.new(uri, headers: headers)
23
+ end
19
24
  end
20
25
 
21
26
  def repo_host
@@ -93,13 +98,13 @@ module CookbookOmnifetch
93
98
  "#to_lock must be implemented on #{self.class.name}!"
94
99
  end
95
100
 
96
- # The path where all pristine tarballs from an artifactserver are held.
101
+ # The path where all pristine tarballs from an artifactory are held.
97
102
  # Tarballs are moved/swapped into this location once they have been staged
98
103
  # in a co-located staging directory.
99
104
  #
100
105
  # @return [Pathname]
101
106
  def cache_root
102
- Pathname.new(CookbookOmnifetch.cache_path).join(".cache", "artifactserver")
107
+ Pathname.new(CookbookOmnifetch.cache_path).join(".cache", "artifactory")
103
108
  end
104
109
 
105
110
  # The path where tarballs are downloaded to and unzipped. On certain platforms
@@ -113,7 +118,7 @@ module CookbookOmnifetch
113
118
  #
114
119
  # @return [Pathname]
115
120
  def staging_root
116
- Pathname.new(CookbookOmnifetch.cache_path).join(".cache_tmp", "artifactserver")
121
+ Pathname.new(CookbookOmnifetch.cache_path).join(".cache_tmp", "artifactory")
117
122
  end
118
123
 
119
124
  # The path where the pristine tarball is cached
@@ -1,7 +1,7 @@
1
- require "cookbook-omnifetch/base"
1
+ require_relative "base"
2
2
 
3
- require "mixlib/archive"
4
- require "tmpdir"
3
+ require "mixlib/archive" unless defined?(Mixlib::Archive)
4
+ require "tmpdir" unless defined?(Dir.mktmpdir)
5
5
 
6
6
  module CookbookOmnifetch
7
7
 
@@ -1,4 +1,4 @@
1
- require "cookbook-omnifetch/exceptions"
1
+ require_relative "exceptions"
2
2
 
3
3
  module CookbookOmnifetch
4
4
  class BaseLocation
@@ -1,5 +1,5 @@
1
- require "cookbook-omnifetch/base"
2
- require "cookbook-omnifetch/metadata_based_installer"
1
+ require_relative "base"
2
+ require_relative "metadata_based_installer"
3
3
 
4
4
  module CookbookOmnifetch
5
5
  class ChefServerLocation < BaseLocation
@@ -34,7 +34,8 @@ module CookbookOmnifetch
34
34
  #
35
35
  # @return [Boolean]
36
36
  def installed?
37
- install_path.exist?
37
+ # Always force a refresh of cache
38
+ false
38
39
  end
39
40
 
40
41
  def http_client
@@ -1,5 +1,5 @@
1
- require "cookbook-omnifetch/base"
2
- require "cookbook-omnifetch/metadata_based_installer"
1
+ require_relative "base"
2
+ require_relative "metadata_based_installer"
3
3
 
4
4
  module CookbookOmnifetch
5
5
  # This location allows fetching from the `cookbook_artifacts/` API where Chef
@@ -45,7 +45,8 @@ module CookbookOmnifetch
45
45
  #
46
46
  # @return [Boolean]
47
47
  def installed?
48
- install_path.exist?
48
+ # Always force a refresh of cache
49
+ false
49
50
  end
50
51
 
51
52
  def http_client
@@ -1,7 +1,7 @@
1
- require "tmpdir"
2
- require "cookbook-omnifetch"
3
- require "cookbook-omnifetch/base"
4
- require "cookbook-omnifetch/exceptions"
1
+ require "tmpdir" unless defined?(Dir.mktmpdir)
2
+ require_relative "../cookbook-omnifetch"
3
+ require_relative "base"
4
+ require_relative "exceptions"
5
5
 
6
6
  module CookbookOmnifetch
7
7
  class GitLocation < BaseLocation
@@ -1,4 +1,4 @@
1
- require "cookbook-omnifetch/exceptions"
1
+ require_relative "exceptions"
2
2
 
3
3
  module CookbookOmnifetch
4
4
 
@@ -1,21 +1,23 @@
1
- require "cookbook-omnifetch/threaded_job_queue"
1
+ require_relative "threaded_job_queue"
2
+ require "digest/md5"
2
3
 
3
4
  module CookbookOmnifetch
4
5
 
5
6
  class MetadataBasedInstaller
6
7
  class CookbookMetadata
7
8
 
8
- FILE_TYPES = [
9
- :resources,
10
- :providers,
11
- :recipes,
12
- :definitions,
13
- :libraries,
14
- :attributes,
15
- :files,
16
- :templates,
17
- :root_files,
18
- ].freeze
9
+ FILE_TYPES = %i{
10
+ resources
11
+ providers
12
+ recipes
13
+ definitions
14
+ libraries
15
+ attributes
16
+ files
17
+ templates
18
+ root_files
19
+ all_files
20
+ }.freeze
19
21
 
20
22
  def initialize(metadata)
21
23
  @metadata = metadata
@@ -26,7 +28,7 @@ module CookbookOmnifetch
26
28
  next unless @metadata.key?(type.to_s)
27
29
 
28
30
  @metadata[type.to_s].each do |file|
29
- yield file["url"], file["path"]
31
+ yield file["url"], file["path"], file["checksum"]
30
32
  end
31
33
  end
32
34
  end
@@ -45,50 +47,58 @@ module CookbookOmnifetch
45
47
  end
46
48
 
47
49
  def install
48
- FileUtils.rm_rf(staging_path) # ensure we have a clean dir, just in case
49
- FileUtils.mkdir_p(staging_root) unless staging_root.exist?
50
- md = http_client.get(url_path)
51
-
52
- queue = ThreadedJobQueue.new
50
+ metadata = http_client.get(url_path)
51
+ clean_cache(metadata)
52
+ sync_cache(metadata)
53
+ end
53
54
 
54
- CookbookMetadata.new(md).files do |url, path|
55
- stage = staging_path.join(path)
56
- FileUtils.mkdir_p(File.dirname(stage))
55
+ # Removes files from cache that are not supposed to be there, based on
56
+ # files in metadata.
57
+ def clean_cache(metadata)
58
+ actual_file_list = Dir.glob(File.join(install_path, "**/*"))
59
+ expected_file_list = []
60
+ CookbookMetadata.new(metadata).files { |_, path, _| expected_file_list << File.join(install_path, path) }
61
+
62
+ extra_files = actual_file_list - expected_file_list
63
+ extra_files.each do |path|
64
+ if File.file?(path)
65
+ FileUtils.rm(path)
66
+ end
67
+ end
68
+ end
57
69
 
58
- queue << lambda do |_lock|
59
- http_client.streaming_request(url) do |tempfile|
60
- tempfile.close
61
- FileUtils.mv(tempfile.path, stage)
70
+ # Downloads any out-of-date files into installer cache, overwriting
71
+ # those that don't match the checksum provided the metadata @ url_path
72
+ def sync_cache(metadata)
73
+ queue = ThreadedJobQueue.new
74
+ CookbookMetadata.new(metadata).files do |url, path, checksum|
75
+ dest_path = File.join(install_path, path)
76
+ FileUtils.mkdir_p(File.dirname(dest_path))
77
+ if file_outdated?(dest_path, checksum)
78
+ queue << lambda do |_lock|
79
+ http_client.streaming_request(url) do |tempfile|
80
+ tempfile.close
81
+ FileUtils.mv(tempfile.path, dest_path)
82
+ end
62
83
  end
63
84
  end
64
85
  end
65
-
66
86
  queue.process(CookbookOmnifetch.chef_server_download_concurrency)
67
-
68
- FileUtils.mv(staging_path, install_path)
69
87
  end
70
88
 
71
- # The path where files are downloaded to. On certain platforms you have a
72
- # better chance of getting an atomic move if your temporary working
73
- # directory is on the same device/volume as the destination. To support
74
- # this, we use a staging directory located under the cache path under the
75
- # rather mild assumption that everything under the cache path is going to
76
- # be on one device.
89
+ # Check if a given file (at absolute path) is missing or does has a mismatched md5sum
77
90
  #
78
- # @return [Pathname]
79
- def staging_root
80
- Pathname.new(CookbookOmnifetch.cache_path).join(".cache_tmp", "metadata-installer")
81
- end
82
-
83
- def staging_path
84
- staging_root.join(staging_cache_key)
85
- end
86
-
87
- # Convert the URL to a safe name for a file and append our random slug.
88
- # This helps us avoid colliding in the case that there are multiple
89
- # processes installing the same cookbook at the same time.
90
- def staging_cache_key
91
- "#{url_path.gsub(/[^[:alnum:]]/, "_")}_#{slug}"
91
+ # @return [TrueClass, FalseClass]
92
+ def file_outdated?(path, expected_md5sum)
93
+ return true unless File.exist?(path)
94
+
95
+ md5 = Digest::MD5.new
96
+ File.open(path, "r") do |file|
97
+ while (chunk = file.read(1024))
98
+ md5.update chunk
99
+ end
100
+ end
101
+ md5.to_s != expected_md5sum
92
102
  end
93
103
  end
94
104
  end
@@ -1,4 +1,4 @@
1
- require "cookbook-omnifetch/base"
1
+ require_relative "base"
2
2
 
3
3
  module CookbookOmnifetch
4
4
  class PathLocation < BaseLocation
@@ -40,7 +40,7 @@ module CookbookOmnifetch
40
40
  end
41
41
  end
42
42
  workers.each { |worker| self << Thread.method(:exit) }
43
- workers.each { |worker| worker.join }
43
+ workers.each(&:join)
44
44
  end
45
45
  end
46
46
  end
@@ -1,3 +1,3 @@
1
1
  module CookbookOmnifetch
2
- VERSION = "0.8.1".freeze
2
+ VERSION = "0.11.1".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cookbook-omnifetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Winsor
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2019-03-18 00:00:00.000000000 Z
16
+ date: 2020-08-31 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: mixlib-archive
@@ -35,34 +35,6 @@ dependencies:
35
35
  - - "<"
36
36
  - !ruby/object:Gem::Version
37
37
  version: '2.0'
38
- - !ruby/object:Gem::Dependency
39
- name: rake
40
- requirement: !ruby/object:Gem::Requirement
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- version: '0'
45
- type: :development
46
- prerelease: false
47
- version_requirements: !ruby/object:Gem::Requirement
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- version: '0'
52
- - !ruby/object:Gem::Dependency
53
- name: rspec
54
- requirement: !ruby/object:Gem::Requirement
55
- requirements:
56
- - - "~>"
57
- - !ruby/object:Gem::Version
58
- version: '3.0'
59
- type: :development
60
- prerelease: false
61
- version_requirements: !ruby/object:Gem::Requirement
62
- requirements:
63
- - - "~>"
64
- - !ruby/object:Gem::Version
65
- version: '3.0'
66
38
  description:
67
39
  email:
68
40
  - jamie@vialstudios.com
@@ -102,7 +74,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
74
  requirements:
103
75
  - - ">="
104
76
  - !ruby/object:Gem::Version
105
- version: '0'
77
+ version: '2.5'
106
78
  required_rubygems_version: !ruby/object:Gem::Requirement
107
79
  requirements:
108
80
  - - ">="