berkshelf 7.0.10 → 7.2.0

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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -3
  3. data/Rakefile +2 -2
  4. data/berkshelf.gemspec +3 -4
  5. data/bin/berks +1 -1
  6. data/lib/berkshelf/api_client/remote_cookbook.rb +1 -1
  7. data/lib/berkshelf/berksfile.rb +31 -31
  8. data/lib/berkshelf/chef_config_compat.rb +1 -1
  9. data/lib/berkshelf/cli.rb +5 -5
  10. data/lib/berkshelf/community_rest.rb +2 -2
  11. data/lib/berkshelf/config.rb +2 -2
  12. data/lib/berkshelf/cookbook_store.rb +2 -4
  13. data/lib/berkshelf/core_ext/file_utils.rb +1 -1
  14. data/lib/berkshelf/downloader.rb +5 -5
  15. data/lib/berkshelf/errors.rb +3 -0
  16. data/lib/berkshelf/file_syncer.rb +7 -12
  17. data/lib/berkshelf/location.rb +3 -3
  18. data/lib/berkshelf/locations/git.rb +6 -12
  19. data/lib/berkshelf/lockfile.rb +9 -9
  20. data/lib/berkshelf/mixin/git.rb +2 -2
  21. data/lib/berkshelf/packager.rb +5 -7
  22. data/lib/berkshelf/shell.rb +1 -1
  23. data/lib/berkshelf/shell_out.rb +4 -3
  24. data/lib/berkshelf/source.rb +2 -2
  25. data/lib/berkshelf/source_uri.rb +1 -1
  26. data/lib/berkshelf/ssl_policies.rb +4 -6
  27. data/lib/berkshelf/uploader.rb +4 -4
  28. data/lib/berkshelf/validator.rb +2 -8
  29. data/lib/berkshelf/version.rb +1 -1
  30. data/lib/berkshelf/visualizer.rb +2 -2
  31. data/lib/berkshelf.rb +7 -8
  32. data/spec/spec_helper.rb +1 -1
  33. data/spec/support/git.rb +18 -18
  34. data/spec/support/path_helpers.rb +4 -4
  35. data/spec/unit/berkshelf/locations/git_spec.rb +2 -5
  36. data/spec/unit/berkshelf/ridley_compat_spec.rb +1 -1
  37. data/spec/unit/berkshelf/source_spec.rb +22 -12
  38. data/spec/unit/berkshelf/ssl_policies_spec.rb +0 -1
  39. data/spec/unit/berkshelf/validator_spec.rb +0 -13
  40. metadata +10 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1209065e8abc3141efc5b789c212f990184a652cd89a0414ba4fefb2bc9c419
4
- data.tar.gz: 627233958a52340668fcc510f5142eaf37a8dec3130dd8f99d389004f26a7d8d
3
+ metadata.gz: 62d08805f26730ed4eb3721de768e7361113fe5d877c485a60358161904db3f9
4
+ data.tar.gz: 9a3f0b74b8cbda7bc06a92febdf8881002d8b42a3427c9e7e21565a705f28a1c
5
5
  SHA512:
6
- metadata.gz: 6a41ffac6b3b389d138f2bd430520b1e64257455f6b3332058d6f07bd7a52d0a60d24063206ffb54fb87c3645a92ef9087d0b653fc332bbc57f6335501bdbac6
7
- data.tar.gz: 667994356ccb8b8be2b2be7ff191b5da06e4d95d75f98f7ef6124a404b8b5ee1397236f335cfd7317e8fb21b3df8f242d1e6f30e62c617f2360cfb3e5a61d590
6
+ metadata.gz: d2b5c48cbdb73b61b318cf679098d036d53da85c4f3308c01b51711bdcfe9d073f7a482a87285d684a874054ae1ebe00e0162ef032582243a9b333cecbe744be
7
+ data.tar.gz: dd118413d20ac879b40e92c4ea78055686fc0823d0ee1bcbe58ab9d799cb7c1fc48b0326018988737b9c9952989531a3ef6711cdad26476198b5f120c4cba34b
data/Gemfile CHANGED
@@ -11,10 +11,9 @@ group :build do
11
11
  end
12
12
 
13
13
  group :development do
14
- # these all deliberately float because berkshelf has a Gemfile.lock that
15
- # equality pins them. temporarily pin as necessary for API breaks.
16
14
  gem "chef-bin" # for the proxy tests
17
- gem "aruba", ">= 0.10.0"
15
+ gem "aruba", "~> 0.10" # Stay below 1 until aruba/in_process monkeypatching stops
16
+ gem "cucumber", "< 4.0" # until we identify what is generating the ~@no_run tag in CI
18
17
  gem "cucumber-expressions", "= 5.0.13"
19
18
  gem "chef-zero", ">= 4.0"
20
19
  gem "dep_selector", ">= 1.0"
data/Rakefile CHANGED
@@ -14,8 +14,8 @@ begin
14
14
  require "cucumber"
15
15
  require "cucumber/rake/task"
16
16
  Cucumber::Rake::Task.new(:features) do |t|
17
- if RUBY_PLATFORM =~ WINDOWS_PLATFORM
18
- t.cucumber_opts = "--tags ~@not-windows"
17
+ if RUBY_PLATFORM =~ WINDOWS_PLATFORM || RUBY_PLATFORM =~ /darwin/
18
+ t.cucumber_opts = "--tags 'not @not-windows'"
19
19
  end
20
20
  end
21
21
  rescue LoadError
data/berkshelf.gemspec CHANGED
@@ -1,5 +1,4 @@
1
- # -*- encoding: utf-8; mode: ruby -*-
2
- require File.expand_path("../lib/berkshelf/version", __FILE__)
1
+ require File.expand_path("lib/berkshelf/version", __dir__)
3
2
 
4
3
  Gem::Specification.new do |s|
5
4
  s.authors = [
@@ -36,9 +35,9 @@ Gem::Specification.new do |s|
36
35
  s.add_dependency "solve", "~> 4.0"
37
36
  s.add_dependency "thor", ">= 0.20"
38
37
  s.add_dependency "octokit", "~> 4.0"
39
- s.add_dependency "mixlib-archive", ">= 0.4", "< 2.0"
38
+ s.add_dependency "mixlib-archive", ">= 1.1.4", "< 2.0" # needed for ruby 3.0 / Dir.chdir removal
40
39
  s.add_dependency "concurrent-ruby", "~> 1.0"
41
- s.add_dependency "chef", ">= 13.6.52"
40
+ s.add_dependency "chef", ">= 15.7.32" # needed for --skip-syntax-check
42
41
  s.add_dependency "chef-config"
43
42
  # this is required for Mixlib::Config#from_json
44
43
  s.add_dependency "mixlib-config", ">= 2.2.5"
data/bin/berks CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- $:.push File.expand_path("../../lib", __FILE__)
2
+ $:.push File.expand_path("../lib", __dir__)
3
3
  require "berkshelf/cli"
4
4
 
5
5
  Berkshelf::Cli::Runner.new(ARGV.dup).execute!
@@ -1,4 +1,4 @@
1
- require "json"
1
+ require "json" unless defined?(JSON)
2
2
  require "chef/mash"
3
3
 
4
4
  module Berkshelf
@@ -500,7 +500,7 @@ module Berkshelf
500
500
  latest = cookbooks.select do |cookbook|
501
501
  (include_non_satisfying || dependency.version_constraint.satisfies?(cookbook.version)) &&
502
502
  Semverse::Version.coerce(cookbook.version) > dependency.locked_version
503
- end.sort_by(&:version).last
503
+ end.max_by(&:version)
504
504
 
505
505
  unless latest.nil?
506
506
  hash[name] ||= {
@@ -740,41 +740,41 @@ module Berkshelf
740
740
 
741
741
  private
742
742
 
743
- # Ensure the lockfile is present on disk.
744
- #
745
- # @raise [LockfileNotFound]
746
- # if the lockfile does not exist on disk
747
- #
748
- # @return [true]
743
+ # Ensure the lockfile is present on disk.
744
+ #
745
+ # @raise [LockfileNotFound]
746
+ # if the lockfile does not exist on disk
747
+ #
748
+ # @return [true]
749
749
  def validate_lockfile_present!
750
750
  raise LockfileNotFound unless lockfile.present?
751
751
 
752
752
  true
753
753
  end
754
754
 
755
- # Ensure that all dependencies defined in the Berksfile exist in this
756
- # lockfile.
757
- #
758
- # @raise [LockfileOutOfSync]
759
- # if there are dependencies specified in the Berksfile which do not
760
- # exist (or are not satisifed by) the lockfile
761
- #
762
- # @return [true]
755
+ # Ensure that all dependencies defined in the Berksfile exist in this
756
+ # lockfile.
757
+ #
758
+ # @raise [LockfileOutOfSync]
759
+ # if there are dependencies specified in the Berksfile which do not
760
+ # exist (or are not satisifed by) the lockfile
761
+ #
762
+ # @return [true]
763
763
  def validate_lockfile_trusted!
764
764
  raise LockfileOutOfSync unless lockfile.trusted?
765
765
 
766
766
  true
767
767
  end
768
768
 
769
- # Ensure that all dependencies in the lockfile are installed on this
770
- # system. You should validate that the lockfile can be trusted before
771
- # using this method.
772
- #
773
- # @raise [DependencyNotInstalled]
774
- # if the dependency in the lockfile is not in the Berkshelf shelf on
775
- # this system
776
- #
777
- # @return [true]
769
+ # Ensure that all dependencies in the lockfile are installed on this
770
+ # system. You should validate that the lockfile can be trusted before
771
+ # using this method.
772
+ #
773
+ # @raise [DependencyNotInstalled]
774
+ # if the dependency in the lockfile is not in the Berkshelf shelf on
775
+ # this system
776
+ #
777
+ # @return [true]
778
778
  def validate_dependencies_installed!
779
779
  lockfile.graph.locks.each do |_, dependency|
780
780
  unless dependency.installed?
@@ -785,13 +785,13 @@ module Berkshelf
785
785
  true
786
786
  end
787
787
 
788
- # Determine if any cookbooks were specified that aren't in our shelf.
789
- #
790
- # @param [Array<String>] names
791
- # a list of cookbook names
792
- #
793
- # @raise [DependencyNotFound]
794
- # if a cookbook name is given that does not exist
788
+ # Determine if any cookbooks were specified that aren't in our shelf.
789
+ #
790
+ # @param [Array<String>] names
791
+ # a list of cookbook names
792
+ #
793
+ # @raise [DependencyNotFound]
794
+ # if a cookbook name is given that does not exist
795
795
  def validate_cookbook_names!(names)
796
796
  missing = names - lockfile.graph.locks.keys
797
797
 
@@ -1,6 +1,6 @@
1
1
  require "chef-config/config"
2
2
  require "chef-config/workstation_config_loader"
3
- require "socket" # FIXME: why?
3
+ require "socket" unless defined?(Socket) # FIXME: why?
4
4
 
5
5
  module Berkshelf
6
6
  class ChefConfigCompat
data/lib/berkshelf/cli.rb CHANGED
@@ -419,11 +419,11 @@ module Berkshelf
419
419
 
420
420
  private
421
421
 
422
- # Print a list of the given cookbooks. This is used by various
423
- # methods like {list} and {contingent}.
424
- #
425
- # @param [Array<CachedCookbook>] cookbooks
426
- #
422
+ # Print a list of the given cookbooks. This is used by various
423
+ # methods like {list} and {contingent}.
424
+ #
425
+ # @param [Array<CachedCookbook>] cookbooks
426
+ #
427
427
  def print_list(cookbooks)
428
428
  Array(cookbooks).sort.each do |cookbook|
429
429
  Berkshelf.formatter.msg " * #{cookbook.cookbook_name} (#{cookbook.version})"
@@ -1,5 +1,5 @@
1
- require "retryable"
2
- require "mixlib/archive"
1
+ require "retryable" unless defined?(Retryable)
2
+ require "mixlib/archive" unless defined?(Mixlib::Archive)
3
3
 
4
4
  module Berkshelf
5
5
  class CommunityREST
@@ -1,5 +1,5 @@
1
- require "mixlib/config"
2
- require "openssl"
1
+ require "mixlib/config" unless defined?(Mixlib::Config)
2
+ require "openssl" unless defined?(OpenSSL)
3
3
 
4
4
  # we need this method, but have to inject it into mixlib-config directly
5
5
  # to have it available from config contexts
@@ -1,4 +1,4 @@
1
- require "fileutils"
1
+ require "fileutils" unless defined?(FileUtils)
2
2
  require "chef/exceptions"
3
3
 
4
4
  module Berkshelf
@@ -49,9 +49,7 @@ module Berkshelf
49
49
 
50
50
  # Destroy the contents of the initialized storage path.
51
51
  def clean!
52
- Dir.chdir(storage_path) do
53
- FileUtils.rm_rf(Dir.glob("*"))
54
- end
52
+ FileUtils.rm_rf(Dir.glob("#{storage_path}/*"))
55
53
  end
56
54
 
57
55
  # Import a cookbook found on the local filesystem into this instance of the cookbook store.
@@ -1,4 +1,4 @@
1
- require "fileutils"
1
+ require "fileutils" unless defined?(FileUtils)
2
2
 
3
3
  module FileUtils
4
4
  class << self
@@ -1,7 +1,7 @@
1
- require "net/http"
2
- require "mixlib/archive"
1
+ require "net/http" unless defined?(Net::HTTP)
2
+ require "mixlib/archive" unless defined?(Mixlib::Archive)
3
3
  require_relative "ssl_policies"
4
- require "faraday"
4
+ require "faraday" unless defined?(Faraday)
5
5
 
6
6
  module Berkshelf
7
7
  class Downloader
@@ -84,7 +84,7 @@ module Berkshelf
84
84
  client_key: source.options[:client_key] || Berkshelf::Config.instance.chef.client_key,
85
85
  ssl: source.options[:ssl],
86
86
  }
87
- RidleyCompat.new_client(credentials) do |conn|
87
+ RidleyCompat.new_client(**credentials) do |conn|
88
88
  cookbook = Chef::CookbookVersion.load(name, version)
89
89
  manifest = cookbook.cookbook_manifest
90
90
  manifest.by_parent_directory.each do |segment, files|
@@ -145,7 +145,7 @@ module Berkshelf
145
145
 
146
146
  File.join(unpack_dir, cookbook_directory)
147
147
  when :uri
148
- require "open-uri"
148
+ require "open-uri" unless defined?(OpenURI)
149
149
 
150
150
  tmp_dir = Dir.mktmpdir
151
151
  archive_path = Pathname.new(tmp_dir) + "#{name}-#{version}.tar.gz"
@@ -91,6 +91,7 @@ module Berkshelf
91
91
 
92
92
  class CookbookSyntaxError < BerkshelfError; set_status_code(107); end
93
93
  class ConstraintNotSatisfied < BerkshelfError; set_status_code(111); end
94
+
94
95
  class BerksfileReadError < BerkshelfError
95
96
  set_status_code(113)
96
97
 
@@ -254,6 +255,7 @@ module Berkshelf
254
255
  end
255
256
 
256
257
  class UploadFailure < BerkshelfError; end
258
+
257
259
  class FrozenCookbook < UploadFailure
258
260
  set_status_code(126)
259
261
 
@@ -436,6 +438,7 @@ module Berkshelf
436
438
  end
437
439
 
438
440
  class DuplicateDemand < BerkshelfError; set_status_code(138); end
441
+
439
442
  class LockfileNotFound < BerkshelfError
440
443
  set_status_code(140)
441
444
 
@@ -1,4 +1,4 @@
1
- require "fileutils"
1
+ require "fileutils" unless defined?(FileUtils)
2
2
 
3
3
  module Berkshelf
4
4
  module FileSyncer
@@ -24,8 +24,8 @@ module Berkshelf
24
24
  # versions of windows points at 'C:\users'. Some users have their
25
25
  # temp directory still referring to 'C:\Documents and Settings'.
26
26
  #
27
- def glob(pattern)
28
- Dir.glob(pattern, File::FNM_DOTMATCH).sort.reject do |file|
27
+ def glob(pattern, **kwargs)
28
+ Dir.glob(pattern, File::FNM_DOTMATCH, **kwargs).sort.reject do |file|
29
29
  basename = File.basename(file)
30
30
  IGNORED_FILES.include?(basename)
31
31
  end
@@ -65,11 +65,10 @@ module Berkshelf
65
65
  [exclude, "#{exclude}/*"]
66
66
  end.flatten
67
67
 
68
- source_files = Dir.chdir(source) do
69
- glob("**/*").reject do |source_file|
68
+ source_files =
69
+ glob("**/*", base: source).reject do |source_file|
70
70
  excludes.any? { |exclude| File.fnmatch?(exclude, source_file, File::FNM_DOTMATCH) }
71
71
  end
72
- end
73
72
 
74
73
  # Ensure the destination directory exists
75
74
  FileUtils.mkdir_p(destination) unless File.directory?(destination)
@@ -88,9 +87,7 @@ module Berkshelf
88
87
  target = File.readlink(source_file)
89
88
 
90
89
  destination = File.expand_path(destination)
91
- Dir.chdir(destination) do
92
- FileUtils.ln_sf(target, "#{destination}/#{relative_path}")
93
- end
90
+ FileUtils.ln_sf(target, "#{destination}/#{relative_path}")
94
91
  when :file
95
92
  FileUtils.cp(source_file, "#{destination}/#{relative_path}")
96
93
  else
@@ -103,9 +100,7 @@ module Berkshelf
103
100
 
104
101
  if options[:delete]
105
102
  # Remove any files in the destination that are not in the source files
106
- destination_files = Dir.chdir(destination) do
107
- glob("**/*")
108
- end
103
+ destination_files = glob("**/*", base: destination)
109
104
 
110
105
  # Remove any extra files that are present in the destination, but are
111
106
  # not in the source list
@@ -28,9 +28,9 @@ module Berkshelf
28
28
 
29
29
  private
30
30
 
31
- # Load the correct location from the given options.
32
- #
33
- # @return [Class, nil]
31
+ # Load the correct location from the given options.
32
+ #
33
+ # @return [Class, nil]
34
34
  def klass_from_options(options)
35
35
  options.each do |key, _|
36
36
  id = key.to_s.capitalize
@@ -37,28 +37,22 @@ module Berkshelf
37
37
  scratch_path = Pathname.new(Dir.mktmpdir)
38
38
 
39
39
  if cached?
40
- Dir.chdir(cache_path) do
41
- git %{fetch --force --tags #{uri} "refs/heads/*:refs/heads/*"}
42
- end
40
+ git(%{fetch --force --tags #{uri} "refs/heads/*:refs/heads/*"}, cwd: cache_path.to_s)
43
41
  else
44
42
  git %{clone #{uri} "#{cache_path}" --bare --no-hardlinks}
45
43
  end
46
44
 
47
- Dir.chdir(cache_path) do
48
- @revision ||= git %{rev-parse #{@rev_parse}}
49
- end
45
+ @revision ||= git(%{rev-parse #{@rev_parse}}, cwd: cache_path.to_s)
50
46
 
51
47
  # Clone into a scratch directory for validations
52
48
  git %{clone --no-checkout "#{cache_path}" "#{scratch_path}"}
53
49
 
54
50
  # Make sure the scratch directory is up-to-date and account for rel paths
55
- Dir.chdir(scratch_path) do
56
- git %{fetch --force --tags "#{cache_path}"}
57
- git %{reset --hard #{@revision}}
51
+ git(%{fetch --force --tags "#{cache_path}"}, cwd: scratch_path.to_s)
52
+ git(%{reset --hard #{@revision}}, cwd: scratch_path.to_s)
58
53
 
59
- if rel
60
- git %{filter-branch --subdirectory-filter "#{rel}" --force}
61
- end
54
+ if rel
55
+ git(%{filter-branch --subdirectory-filter "#{rel}" --force}, cwd: scratch_path.to_s)
62
56
  end
63
57
 
64
58
  # Validate the scratched path is a valid cookbook
@@ -511,8 +511,8 @@ module Berkshelf
511
511
  "#<Berkshelf::Lockfile #{Pathname.new(filepath).basename}, dependencies: #{dependencies.inspect}>"
512
512
  end
513
513
 
514
- # The class responsible for parsing the lockfile and turning it into a
515
- # useful data structure.
514
+ # The class responsible for parsing the lockfile and turning it into a
515
+ # useful data structure.
516
516
  class LockfileParser
517
517
  NAME_VERSION = '(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'.freeze
518
518
  DEPENDENCY_PATTERN = /^ {2}#{NAME_VERSION}$/.freeze
@@ -599,9 +599,9 @@ module Berkshelf
599
599
 
600
600
  private
601
601
 
602
- # Parse a dependency line.
603
- #
604
- # @param [String] line
602
+ # Parse a dependency line.
603
+ #
604
+ # @param [String] line
605
605
  def parse_dependency(line)
606
606
  if line =~ DEPENDENCY_PATTERN
607
607
  name, version = $1, $2
@@ -615,9 +615,9 @@ module Berkshelf
615
615
  end
616
616
  end
617
617
 
618
- # Parse a graph line.
619
- #
620
- # @param [String] line
618
+ # Parse a graph line.
619
+ #
620
+ # @param [String] line
621
621
  def parse_graph(line)
622
622
  if line =~ DEPENDENCY_PATTERN
623
623
  name, version = $1, $2
@@ -631,7 +631,7 @@ module Berkshelf
631
631
  end
632
632
  end
633
633
 
634
- # The class representing an internal graph.
634
+ # The class representing an internal graph.
635
635
  class Graph
636
636
  include Enumerable
637
637
 
@@ -13,12 +13,12 @@ module Berkshelf
13
13
  #
14
14
  # @raise [String]
15
15
  # the +$stdout+ from the command
16
- def git(command, error = true)
16
+ def git(command, error = true, **kwargs)
17
17
  unless Berkshelf.which("git") || Berkshelf.which("git.exe") || Berkshelf.which("git.bat")
18
18
  raise GitNotInstalled.new
19
19
  end
20
20
 
21
- response = shell_out(%{git #{command}})
21
+ response = shell_out(%{git #{command}}, **kwargs)
22
22
 
23
23
  if response.error?
24
24
  raise GitCommandError.new(command, cache_path, response.stderr)
@@ -1,5 +1,5 @@
1
1
  require "archive/tar/minitar"
2
- require "zlib"
2
+ require "zlib" unless defined?(Zlib)
3
3
 
4
4
  module Berkshelf
5
5
  # A class for archiving and compressing directory containing one or more cookbooks.
@@ -40,10 +40,8 @@ module Berkshelf
40
40
  # @return [String]
41
41
  # path to the generated archive
42
42
  def run(source)
43
- Dir.chdir(source.to_s) do |dir|
44
- tgz = Zlib::GzipWriter.new(File.open(out_file, "wb"))
45
- Archive::Tar::Minitar.pack(Dir.glob("*"), tgz)
46
- end
43
+ tgz = Zlib::GzipWriter.new(File.open(out_file, "wb"))
44
+ Archive::Tar::Minitar.pack(Dir.glob("#{source}/*"), tgz)
47
45
 
48
46
  out_file
49
47
  rescue SystemCallError => ex
@@ -64,10 +62,10 @@ module Berkshelf
64
62
 
65
63
  private
66
64
 
67
- # @return [String]
65
+ # @return [String]
68
66
  attr_reader :out_dir
69
67
 
70
- # @return [String]
68
+ # @return [String]
71
69
  attr_reader :filename
72
70
  end
73
71
  end
@@ -1,4 +1,4 @@
1
- require "thor"
1
+ require "thor" unless defined?(Thor)
2
2
 
3
3
  module Berkshelf
4
4
  # Subclass the current shell (which is different based on the OS)
@@ -1,4 +1,4 @@
1
- require "mixlib/shellout"
1
+ require "mixlib/shellout" unless defined?(Mixlib::ShellOut)
2
2
 
3
3
  module Berkshelf
4
4
  module ShellOut
@@ -8,8 +8,9 @@ module Berkshelf
8
8
  cmd
9
9
  end
10
10
 
11
- def shell_out!(*args)
12
- cmd = shell_out(*args)
11
+ def shell_out!(*args, **options)
12
+ cmd = Mixlib::ShellOut.new(*args, **options)
13
+ cmd.run_command
13
14
  cmd.error!
14
15
  cmd
15
16
  end
@@ -1,7 +1,7 @@
1
1
  require_relative "api-client"
2
2
  require_relative "chef_repo_universe"
3
3
  require_relative "ssl_policies"
4
- require "openssl"
4
+ require "openssl" unless defined?(OpenSSL)
5
5
 
6
6
  module Berkshelf
7
7
  class Source
@@ -132,7 +132,7 @@ module Berkshelf
132
132
  #
133
133
  # @return [APIClient::RemoteCookbook]
134
134
  def latest(name)
135
- versions(name).sort.last
135
+ versions(name).max
136
136
  end
137
137
 
138
138
  # @param [String] name
@@ -1,4 +1,4 @@
1
- require "addressable/uri"
1
+ require "addressable/uri" unless defined?(Addressable::URI)
2
2
 
3
3
  module Berkshelf
4
4
  class SourceURI < Addressable::URI
@@ -1,4 +1,4 @@
1
- require "openssl"
1
+ require "openssl" unless defined?(OpenSSL)
2
2
 
3
3
  module Berkshelf
4
4
  class SSLPolicy
@@ -29,11 +29,9 @@ module Berkshelf
29
29
  end
30
30
 
31
31
  def set_custom_certs
32
- Dir.chdir(trusted_certs_dir) do
33
- ::Dir.glob("{*.crt,*.pem}").each do |cert|
34
- cert = OpenSSL::X509::Certificate.new(IO.read(cert))
35
- add_trusted_cert(cert)
36
- end
32
+ ::Dir.glob("#{trusted_certs_dir}/{*.crt,*.pem}").each do |cert|
33
+ cert = OpenSSL::X509::Certificate.new(IO.read(cert))
34
+ add_trusted_cert(cert)
37
35
  end
38
36
  end
39
37
  end
@@ -45,10 +45,10 @@ module Berkshelf
45
45
 
46
46
  private
47
47
 
48
- # Upload the list of cookbooks to the Chef Server, with some exception
49
- # wrapping.
50
- #
51
- # @param [Array<String>] cookbooks
48
+ # Upload the list of cookbooks to the Chef Server, with some exception
49
+ # wrapping.
50
+ #
51
+ # @param [Array<String>] cookbooks
52
52
  def upload(cookbooks)
53
53
  Berkshelf.log.info "Starting upload"
54
54
 
@@ -22,15 +22,9 @@ module Berkshelf
22
22
  # the Cookbook(s) to validate
23
23
  def validate_files(cookbooks)
24
24
  Array(cookbooks).each do |cookbook|
25
- path = cookbook.path.to_s
25
+ base, name = Pathname.new(cookbook.path.to_s).split
26
26
 
27
- files = Dir.chdir(path) do
28
- Dir.glob(File.join("**", "*.rb")).select do |f|
29
- f = File.join(path, f)
30
- parent = Pathname.new(path).dirname.to_s
31
- f.gsub(parent, "") =~ /[[:space:]]/
32
- end
33
- end
27
+ files = Dir.glob("#{name}/**/*.rb", base: base.to_s).select { |f| f =~ /[[:space:]]/ }
34
28
 
35
29
  raise InvalidCookbookFiles.new(cookbook, files) unless files.empty?
36
30
  end
@@ -1,3 +1,3 @@
1
1
  module Berkshelf
2
- VERSION = "7.0.10".freeze
2
+ VERSION = "7.2.0".freeze
3
3
  end
@@ -1,5 +1,5 @@
1
- require "set"
2
- require "tempfile"
1
+ require "set" unless defined?(Set)
2
+ require "tempfile" unless defined?(Tempfile)
3
3
  require_relative "shell_out"
4
4
 
5
5
  module Berkshelf
data/lib/berkshelf.rb CHANGED
@@ -10,14 +10,14 @@ rescue LoadError
10
10
  end
11
11
 
12
12
  require "cleanroom"
13
- require "digest/md5"
14
- require "forwardable"
15
- require "json"
16
- require "pathname"
13
+ require "digest/md5" unless defined?(Digest::MD5)
14
+ require "forwardable" unless defined?(Forwardable)
15
+ require "json" unless defined?(JSON)
16
+ require "pathname" unless defined?(Pathname)
17
17
  require "semverse"
18
18
  require "solve"
19
- require "thor"
20
- require "uri"
19
+ require "thor" unless defined?(Thor)
20
+ require "uri" unless defined?(URI)
21
21
 
22
22
  JSON.create_id = nil
23
23
 
@@ -169,7 +169,7 @@ module Berkshelf
169
169
  raise ChefConnectionError, "Missing required attribute in your Berkshelf configuration: chef.client_key"
170
170
  end
171
171
 
172
- RidleyCompat.new_client(ridley_options, &block)
172
+ RidleyCompat.new_client(**ridley_options, &block)
173
173
  rescue ChefConnectionError, BerkshelfError
174
174
  raise
175
175
  rescue => ex
@@ -222,7 +222,6 @@ require_relative "berkshelf/lockfile"
222
222
  require_relative "berkshelf/berksfile"
223
223
  require_relative "berkshelf/cached_cookbook"
224
224
  require_relative "berkshelf/cli"
225
- require_relative "berkshelf/chef_config_compat"
226
225
  require_relative "berkshelf/community_rest"
227
226
  require_relative "berkshelf/cookbook_store"
228
227
  require_relative "berkshelf/config"
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,7 @@ def windows?
2
2
  !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
3
3
  end
4
4
 
5
- BERKS_SPEC_DATA = File.expand_path("../data", __FILE__)
5
+ BERKS_SPEC_DATA = File.expand_path("data", __dir__)
6
6
 
7
7
  require "rspec"
8
8
  require "cleanroom/rspec"
data/spec/support/git.rb CHANGED
@@ -84,26 +84,26 @@ module Berkshelf
84
84
 
85
85
  private
86
86
 
87
- # The path to store the local git clones.
88
- #
89
- # @return [Pathname]
87
+ # The path to store the local git clones.
88
+ #
89
+ # @return [Pathname]
90
90
  def clones
91
91
  ensure_and_return(tmp_path.join("clones"))
92
92
  end
93
93
 
94
- # The path to store the git remotes.
95
- #
96
- # @return [Pathname]
94
+ # The path to store the git remotes.
95
+ #
96
+ # @return [Pathname]
97
97
  def remotes
98
98
  ensure_and_return(tmp_path.join("remotes"))
99
99
  end
100
100
 
101
- # Generate a cookbook by the given name.
102
- #
103
- # @param [#to_s] name
104
- # the name of the cookbook to create
105
- # @param [Hash] options
106
- # the list ooptions to pass to the generator
101
+ # Generate a cookbook by the given name.
102
+ #
103
+ # @param [#to_s] name
104
+ # the name of the cookbook to create
105
+ # @param [Hash] options
106
+ # the list ooptions to pass to the generator
107
107
  def generate_git_cookbook(name, options = {})
108
108
  options = {
109
109
  skip_vagrant: true,
@@ -114,12 +114,12 @@ module Berkshelf
114
114
  Berkshelf::Cli.new.invoke(:cookbook, [name.to_s], options)
115
115
  end
116
116
 
117
- # Make sure the given path exists and return the path
118
- #
119
- # @param [#to_s] path
120
- # the path to create and return
121
- #
122
- # @return [Pathname]
117
+ # Make sure the given path exists and return the path
118
+ #
119
+ # @param [#to_s] path
120
+ # the path to create and return
121
+ #
122
+ # @return [Pathname]
123
123
  def ensure_and_return(path)
124
124
  FileUtils.mkdir(path) unless File.exist?(path)
125
125
  Pathname.new(path).expand_path
@@ -50,10 +50,10 @@ module Berkshelf
50
50
 
51
51
  private
52
52
 
53
- # This is the magical "reset" function that gives us a clean working
54
- # directory on each run.
55
- #
56
- # @return [nil]
53
+ # This is the magical "reset" function that gives us a clean working
54
+ # directory on each run.
55
+ #
56
+ # @return [nil]
57
57
  def reload_configs
58
58
  Berkshelf.chef_config = chef_config
59
59
 
@@ -104,11 +104,10 @@ module Berkshelf
104
104
 
105
105
  context "when the repository is cached" do
106
106
  it "pulls a new version" do
107
- allow(Dir).to receive(:chdir) { |args, &b| b.call } # Force eval the chdir block
108
-
107
+ cache_path = subject.send(:cache_path)
109
108
  allow(subject).to receive(:cached?).and_return(true)
110
109
  expect(subject).to receive(:git).with(
111
- 'fetch --force --tags https://repo.com "refs/heads/*:refs/heads/*"'
110
+ 'fetch --force --tags https://repo.com "refs/heads/*:refs/heads/*"', cwd: cache_path.to_s
112
111
  )
113
112
  subject.install
114
113
  end
@@ -116,8 +115,6 @@ module Berkshelf
116
115
 
117
116
  context "when the revision is not cached" do
118
117
  it "clones the repository" do
119
- allow(Dir).to receive(:chdir) { |args, &b| b.call } # Force eval the chdir block
120
-
121
118
  cache_path = subject.send(:cache_path)
122
119
  allow(subject).to receive(:cached?).and_return(false)
123
120
  expect(subject).to receive(:git).with(
@@ -4,7 +4,7 @@ require "chef/cookbook_manifest"
4
4
  describe Berkshelf::RidleyCompat do
5
5
  let(:opts) { {} }
6
6
 
7
- subject { described_class.new(opts) }
7
+ subject { described_class.new(**opts) }
8
8
 
9
9
  context "default" do
10
10
  it "has a cookbook version_class" do
@@ -4,8 +4,9 @@ module Berkshelf
4
4
  describe Source do
5
5
  let(:berksfile) { double("Berksfile", filepath: "/test/Berksfile") }
6
6
  let(:arguments) { [] }
7
+ let(:kwargs) { {} }
7
8
  let(:config) { Config.new }
8
- subject(:instance) { described_class.new(berksfile, *arguments) }
9
+ subject(:instance) { described_class.new(berksfile, *arguments, **kwargs) }
9
10
  before do
10
11
  allow(Berkshelf::Config).to receive(:instance).and_return(config)
11
12
  end
@@ -19,7 +20,8 @@ module Berkshelf
19
20
  end
20
21
 
21
22
  context "with a string argument and options" do
22
- let(:arguments) { ["https://example.com", { key: "value" }] }
23
+ let(:arguments) { ["https://example.com" ] }
24
+ let(:kwargs) { { key: "value" } }
23
25
  it { is_expected.to eq :supermarket }
24
26
  end
25
27
 
@@ -29,7 +31,8 @@ module Berkshelf
29
31
  end
30
32
 
31
33
  context "with a symbol argument and options" do
32
- let(:arguments) { [:chef_server, { key: "value" }] }
34
+ let(:arguments) { [:chef_server ] }
35
+ let(:kwargs) { { key: "value" } }
33
36
  it { is_expected.to eq :chef_server }
34
37
  end
35
38
 
@@ -44,7 +47,8 @@ module Berkshelf
44
47
  end
45
48
 
46
49
  context "with a hash argument and disconnected options" do
47
- let(:arguments) { [{ artifactory: "https://example.com/api/chef/chef-virtual" }, { key: "value" }] }
50
+ let(:arguments) { [{ artifactory: "https://example.com/api/chef/chef-virtual" }] }
51
+ let(:kwargs) { { key: "value" } }
48
52
  it { is_expected.to eq :artifactory }
49
53
  end
50
54
  end
@@ -58,7 +62,8 @@ module Berkshelf
58
62
  end
59
63
 
60
64
  context "with a string argument and options" do
61
- let(:arguments) { ["https://example.com", { key: "value" }] }
65
+ let(:arguments) { ["https://example.com" ] }
66
+ let(:kwargs) { { key: "value" } }
62
67
  it { is_expected.to eq "https://example.com" }
63
68
  end
64
69
 
@@ -69,7 +74,8 @@ module Berkshelf
69
74
  end
70
75
 
71
76
  context "with a symbol argument and options" do
72
- let(:arguments) { [:chef_server, { key: "value" }] }
77
+ let(:arguments) { [:chef_server] }
78
+ let(:kwargs) { { key: "value" } }
73
79
  before { config.chef.chef_server_url = "https://chefserver/" }
74
80
  it { is_expected.to eq "https://chefserver/" }
75
81
  end
@@ -85,7 +91,8 @@ module Berkshelf
85
91
  end
86
92
 
87
93
  context "with a hash argument and disconnected options" do
88
- let(:arguments) { [{ artifactory: "https://example.com/api/chef/chef-virtual" }, { key: "value" }] }
94
+ let(:arguments) { [{ artifactory: "https://example.com/api/chef/chef-virtual" } ] }
95
+ let(:kwargs) { { key: "value" } }
89
96
  it { is_expected.to eq "https://example.com/api/chef/chef-virtual" }
90
97
  end
91
98
 
@@ -96,7 +103,7 @@ module Berkshelf
96
103
 
97
104
  context "with a chef_repo source" do
98
105
  let(:arguments) { [{ chef_repo: "." }] }
99
- it { is_expected.to eq(windows? ? "file://C/test" : "file:///test") }
106
+ it { is_expected.to eq(windows? ? "file://D/test" : "file:///test") }
100
107
  end
101
108
  end
102
109
 
@@ -119,7 +126,8 @@ module Berkshelf
119
126
  end
120
127
 
121
128
  context "with a string argument and options" do
122
- let(:arguments) { ["https://example.com", { key: "value" }] }
129
+ let(:arguments) { ["https://example.com"] }
130
+ let(:kwargs) { { key: "value" } }
123
131
  its([:key]) { is_expected.to eq "value" }
124
132
  end
125
133
 
@@ -129,7 +137,8 @@ module Berkshelf
129
137
  end
130
138
 
131
139
  context "with a symbol argument and options" do
132
- let(:arguments) { [:chef_server, { key: "value" }] }
140
+ let(:arguments) { [:chef_server] }
141
+ let(:kwargs) { { key: "value" } }
133
142
  its([:key]) { is_expected.to eq "value" }
134
143
  end
135
144
 
@@ -144,7 +153,8 @@ module Berkshelf
144
153
  end
145
154
 
146
155
  context "with a hash argument and disconnected options" do
147
- let(:arguments) { [{ artifactory: "https://example.com/api/chef/chef-virtual" }, { key: "value" }] }
156
+ let(:arguments) { [{ artifactory: "https://example.com/api/chef/chef-virtual" } ] }
157
+ let(:kwargs) { { key: "value" } }
148
158
  its([:key]) { is_expected.to eq "value" }
149
159
  end
150
160
 
@@ -156,7 +166,7 @@ module Berkshelf
156
166
 
157
167
  context "with a chef_repo source" do
158
168
  let(:arguments) { [{ chef_repo: "." }] }
159
- its([:path]) { is_expected.to eq(windows? ? "C:/test" : "/test") }
169
+ its([:path]) { is_expected.to eq(windows? ? "D:/test" : "/test") }
160
170
  end
161
171
  end
162
172
 
@@ -73,7 +73,6 @@ describe Berkshelf::SSLPolicy do
73
73
  before do
74
74
  allow(chef_config).to receive_messages(trusted_certs_dir: self_signed_crt_path_windows_backslashes)
75
75
  allow(File).to receive(:exist?).with(self_signed_crt_path_windows_forwardslashes).and_return(true)
76
- allow(Dir).to receive(:chdir).with(self_signed_crt_path_windows_forwardslashes)
77
76
  end
78
77
 
79
78
  it "replaces the backslashes in trusted_certs_dir from Berkshelf config with forwardslashes" do
@@ -4,10 +4,6 @@ describe Berkshelf::Validator do
4
4
  describe "#validate_files" do
5
5
  let(:cookbook) { double("cookbook", cookbook_name: "cookbook", path: "path") }
6
6
 
7
- before do
8
- allow(Dir).to receive(:chdir) { |&block| block.call }
9
- end
10
-
11
7
  it "raises an error when the cookbook has spaces in the files" do
12
8
  allow(Dir).to receive(:glob).and_return(["/there are/spaces/in this/recipes/default.rb"])
13
9
  expect do
@@ -21,14 +17,5 @@ describe Berkshelf::Validator do
21
17
  subject.validate_files(cookbook)
22
18
  end.to_not raise_error
23
19
  end
24
-
25
- it "does not raise an exception with spaces in the path" do
26
- allow(Dir).to receive(:glob).and_return(["/there are/spaces/in this/recipes/default.rb"])
27
- allow_any_instance_of(Pathname).to receive(:dirname).and_return("/there are/spaces/in this")
28
-
29
- expect do
30
- subject.validate_files(cookbook)
31
- end.to_not raise_error
32
- end
33
20
  end
34
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berkshelf
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.10
4
+ version: 7.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Winsor
@@ -9,10 +9,10 @@ authors:
9
9
  - Michael Ivey
10
10
  - Justin Campbell
11
11
  - Seth Vargo
12
- autorequire:
12
+ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2020-04-27 00:00:00.000000000 Z
15
+ date: 2021-02-12 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: mixlib-shellout
@@ -130,7 +130,7 @@ dependencies:
130
130
  requirements:
131
131
  - - ">="
132
132
  - !ruby/object:Gem::Version
133
- version: '0.4'
133
+ version: 1.1.4
134
134
  - - "<"
135
135
  - !ruby/object:Gem::Version
136
136
  version: '2.0'
@@ -140,7 +140,7 @@ dependencies:
140
140
  requirements:
141
141
  - - ">="
142
142
  - !ruby/object:Gem::Version
143
- version: '0.4'
143
+ version: 1.1.4
144
144
  - - "<"
145
145
  - !ruby/object:Gem::Version
146
146
  version: '2.0'
@@ -164,14 +164,14 @@ dependencies:
164
164
  requirements:
165
165
  - - ">="
166
166
  - !ruby/object:Gem::Version
167
- version: 13.6.52
167
+ version: 15.7.32
168
168
  type: :runtime
169
169
  prerelease: false
170
170
  version_requirements: !ruby/object:Gem::Requirement
171
171
  requirements:
172
172
  - - ">="
173
173
  - !ruby/object:Gem::Version
174
- version: 13.6.52
174
+ version: 15.7.32
175
175
  - !ruby/object:Gem::Dependency
176
176
  name: chef-config
177
177
  requirement: !ruby/object:Gem::Requirement
@@ -359,7 +359,7 @@ homepage: https://docs.chef.io/berkshelf.html
359
359
  licenses:
360
360
  - Apache-2.0
361
361
  metadata: {}
362
- post_install_message:
362
+ post_install_message:
363
363
  rdoc_options: []
364
364
  require_paths:
365
365
  - lib
@@ -374,8 +374,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
374
374
  - !ruby/object:Gem::Version
375
375
  version: 2.0.0
376
376
  requirements: []
377
- rubygems_version: 3.1.2
378
- signing_key:
377
+ rubygems_version: 3.1.4
378
+ signing_key:
379
379
  specification_version: 4
380
380
  summary: Manages a Chef cookbook's dependencies
381
381
  test_files: []