berkshelf 7.0.8 → 8.0.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 (87) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -12
  3. data/Rakefile +3 -3
  4. data/berkshelf.gemspec +3 -4
  5. data/bin/berks +1 -1
  6. data/lib/berkshelf/api_client/chef_server_connection.rb +7 -8
  7. data/lib/berkshelf/api_client/connection.rb +1 -1
  8. data/lib/berkshelf/api_client/remote_cookbook.rb +1 -1
  9. data/lib/berkshelf/api_client.rb +2 -2
  10. data/lib/berkshelf/berksfile.rb +44 -42
  11. data/lib/berkshelf/cached_cookbook.rb +5 -3
  12. data/lib/berkshelf/chef_config_compat.rb +1 -1
  13. data/lib/berkshelf/chef_repo_universe.rb +4 -2
  14. data/lib/berkshelf/cli.rb +6 -6
  15. data/lib/berkshelf/commands/shelf.rb +1 -1
  16. data/lib/berkshelf/community_rest.rb +6 -6
  17. data/lib/berkshelf/config.rb +3 -3
  18. data/lib/berkshelf/cookbook_store.rb +2 -4
  19. data/lib/berkshelf/core_ext/file_utils.rb +3 -3
  20. data/lib/berkshelf/core_ext.rb +1 -1
  21. data/lib/berkshelf/dependency.rb +1 -1
  22. data/lib/berkshelf/downloader.rb +9 -6
  23. data/lib/berkshelf/errors.rb +5 -2
  24. data/lib/berkshelf/file_syncer.rb +10 -12
  25. data/lib/berkshelf/formatters/human.rb +1 -1
  26. data/lib/berkshelf/formatters/json.rb +1 -1
  27. data/lib/berkshelf/installer.rb +8 -8
  28. data/lib/berkshelf/location.rb +4 -4
  29. data/lib/berkshelf/locations/git.rb +6 -12
  30. data/lib/berkshelf/locations/github.rb +1 -1
  31. data/lib/berkshelf/lockfile.rb +11 -11
  32. data/lib/berkshelf/logger.rb +4 -2
  33. data/lib/berkshelf/mixin/git.rb +3 -3
  34. data/lib/berkshelf/packager.rb +5 -7
  35. data/lib/berkshelf/resolver.rb +1 -1
  36. data/lib/berkshelf/ridley_compat.rb +1 -1
  37. data/lib/berkshelf/shell.rb +2 -1
  38. data/lib/berkshelf/shell_out.rb +4 -3
  39. data/lib/berkshelf/source.rb +8 -7
  40. data/lib/berkshelf/source_uri.rb +1 -1
  41. data/lib/berkshelf/ssl_policies.rb +6 -10
  42. data/lib/berkshelf/thor.rb +1 -1
  43. data/lib/berkshelf/thor_ext/hash_with_indifferent_access.rb +1 -1
  44. data/lib/berkshelf/thor_ext.rb +1 -1
  45. data/lib/berkshelf/uploader.rb +37 -35
  46. data/lib/berkshelf/validator.rb +2 -8
  47. data/lib/berkshelf/version.rb +1 -1
  48. data/lib/berkshelf/visualizer.rb +3 -3
  49. data/lib/berkshelf.rb +8 -9
  50. data/spec/config/knife.rb +2 -2
  51. data/spec/spec_helper.rb +1 -1
  52. data/spec/support/chef_server.rb +2 -2
  53. data/spec/support/git.rb +19 -19
  54. data/spec/support/path_helpers.rb +4 -4
  55. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/attributes/default.rb +0 -0
  56. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/files/default/file.h +0 -0
  57. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/metadata.rb +2 -0
  58. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/recipes/default.rb +0 -0
  59. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/templates/default/template.erb +0 -0
  60. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/attributes/default.rb +0 -0
  61. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/files/default/file.h +0 -0
  62. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/metadata.rb +2 -0
  63. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/recipes/default.rb +0 -0
  64. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/templates/default/template.erb +0 -0
  65. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/attributes/default.rb +0 -0
  66. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/files/default/file.h +0 -0
  67. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/metadata.rb +2 -0
  68. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/recipes/default.rb +0 -0
  69. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/templates/default/template.erb +0 -0
  70. data/spec/unit/berkshelf/berksfile_spec.rb +7 -7
  71. data/spec/unit/berkshelf/berkshelf/api_client/chef_server_connection_spec.rb +65 -0
  72. data/spec/unit/berkshelf/cli_spec.rb +1 -2
  73. data/spec/unit/berkshelf/community_rest_spec.rb +1 -1
  74. data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +2 -2
  75. data/spec/unit/berkshelf/dependency_spec.rb +6 -6
  76. data/spec/unit/berkshelf/downloader_spec.rb +4 -8
  77. data/spec/unit/berkshelf/location_spec.rb +1 -1
  78. data/spec/unit/berkshelf/locations/base_spec.rb +1 -2
  79. data/spec/unit/berkshelf/locations/git_spec.rb +2 -5
  80. data/spec/unit/berkshelf/locations/path_spec.rb +1 -2
  81. data/spec/unit/berkshelf/lockfile_spec.rb +9 -18
  82. data/spec/unit/berkshelf/ridley_compat_spec.rb +2 -2
  83. data/spec/unit/berkshelf/source_spec.rb +30 -19
  84. data/spec/unit/berkshelf/ssl_policies_spec.rb +3 -6
  85. data/spec/unit/berkshelf/uploader_spec.rb +6 -10
  86. data/spec/unit/berkshelf/validator_spec.rb +0 -13
  87. metadata +26 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7106f564a5687739b6b869ddb82caab720210cb55ceaec843de5864321752591
4
- data.tar.gz: 4196d7280ddf0bcec16c38c6cde5b9829a8e7d37b3aed818671e23294d1af301
3
+ metadata.gz: 74b3f02281f737a99b466bb6e902b83e14dc4753eca57e4c53ebcc9d18147c4b
4
+ data.tar.gz: e8c566401ba73574604f2427b91a414af8a10e04d20d6c78df0e5cac58bc9ebc
5
5
  SHA512:
6
- metadata.gz: ba89f50812a6ffa647fc6c9cb349ce169e9fbb2c641d635157ed4410e75363f5eb2a4ab817002de907965bde4234fd9d7930dfe1a3f76bd8997aa4f2efe30a72
7
- data.tar.gz: 51c592e399c3213ec72755dca557b7926e1d8abd14659bcc6e2547d032b018eac8c4b3fb69037e4c26fefe7611b0d3c96465af6fe7f67e62915107476b6018d7
6
+ metadata.gz: ad41f78382168194e5e7289a58ddb2213724839c64a5cf033551d874f935af0b2f6343a64499649499aed797a63b5d5d261298733cd4131e56b072a1671e55ee
7
+ data.tar.gz: 19735889f013e0c9afca6ae0ab3b4496d2d35d09dc85592fb2b6d549a5e1224f19dc76926021f7ec5be735ff44d49299f0b6a69122e27f719a72611a91424dda
data/Gemfile CHANGED
@@ -2,18 +2,13 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- group :changelog do
6
- gem "github_changelog_generator"
7
- end
8
-
9
5
  group :build do
10
6
  gem "rake", ">= 10.1"
11
7
  end
12
8
 
13
9
  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
- gem "aruba", ">= 0.10.0"
10
+ gem "aruba", "~> 0.10" # Stay below 1 until aruba/in_process monkeypatching stops
11
+ gem "cucumber", "< 4.0" # until we identify what is generating the ~@no_run tag in CI
17
12
  gem "cucumber-expressions", "= 5.0.13"
18
13
  gem "chef-zero", ">= 4.0"
19
14
  gem "dep_selector", ">= 1.0"
@@ -22,11 +17,7 @@ group :development do
22
17
  gem "rspec-its", ">= 1.2"
23
18
  gem "webmock", ">= 1.11"
24
19
  gem "http", ">= 0.9.8"
25
- gem "chefstyle", git: "https://github.com/chef/chefstyle.git", branch: "master"
26
- end
27
-
28
- group :docs do
29
- gem "yard", ">= 0.8"
20
+ gem "chefstyle"
30
21
  end
31
22
 
32
23
  instance_eval(ENV["GEMFILE_MOD"]) if ENV["GEMFILE_MOD"]
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
@@ -35,7 +35,7 @@ begin
35
35
  rescue LoadError
36
36
  end
37
37
 
38
- task default: [:spec, :features]
38
+ task default: %i{spec features}
39
39
  task :ci do
40
40
  ENV["CI"] = "true"
41
41
  Rake::Task[:spec].invoke
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,25 +1,24 @@
1
- require "berkshelf/ridley_compat"
1
+ require_relative "../ridley_compat"
2
2
 
3
3
  module Berkshelf
4
4
  module APIClient
5
5
  require_relative "errors"
6
6
 
7
7
  class ChefServerConnection
8
- attr_reader :client
9
-
10
- def initialize(*args)
11
- @client = Berkshelf::RidleyCompat.new(*args)
12
- @url = args[0][:server_url]
8
+ def initialize(**args)
9
+ @client = Berkshelf::RidleyCompat.new(**args)
10
+ @url = args[:server_url]
13
11
  end
14
12
 
15
13
  def universe
16
- response = client.get("universe")
14
+ response = @client.get("universe")
17
15
 
18
16
  [].tap do |cookbooks|
19
17
  response.each do |name, versions|
20
18
  versions.each do |version, attributes|
21
19
  attributes[:location_path] = @url
22
- cookbooks << RemoteCookbook.new(name, version, attributes) end
20
+ cookbooks << RemoteCookbook.new(name, version, attributes)
21
+ end
23
22
  end
24
23
  end
25
24
  rescue Ridley::Errors::HTTPNotFound
@@ -1,4 +1,4 @@
1
- require "berkshelf/ridley_compat"
1
+ require_relative "../ridley_compat"
2
2
 
3
3
  module Berkshelf
4
4
  module APIClient
@@ -1,4 +1,4 @@
1
- require "json"
1
+ require "json" unless defined?(JSON)
2
2
  require "chef/mash"
3
3
 
4
4
  module Berkshelf
@@ -16,8 +16,8 @@ module Berkshelf
16
16
  Connection.new(*args)
17
17
  end
18
18
 
19
- def chef_server(*args)
20
- ChefServerConnection.new(*args)
19
+ def chef_server(**args)
20
+ ChefServerConnection.new(**args)
21
21
  end
22
22
  end
23
23
  end
@@ -13,7 +13,7 @@ module Berkshelf
13
13
  def from_options(options = {})
14
14
  options[:berksfile] ||= File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME)
15
15
  symbolized = Hash[options.map { |k, v| [k.to_sym, v] }]
16
- from_file(options[:berksfile], symbolized.select { |k,| [:except, :only, :delete].include? k })
16
+ from_file(options[:berksfile], symbolized.select { |k,| %i{except only delete}.include? k })
17
17
  end
18
18
 
19
19
  # @param [#to_s] file
@@ -66,8 +66,8 @@ module Berkshelf
66
66
  # group to be installed and all others to be ignored
67
67
  def initialize(path, options = {})
68
68
  @filepath = File.expand_path(path)
69
- @dependencies = Hash.new
70
- @sources = Hash.new
69
+ @dependencies = {}
70
+ @sources = {}
71
71
  @delete = options[:delete]
72
72
 
73
73
  # defaults for what solvers to use
@@ -118,7 +118,7 @@ module Berkshelf
118
118
  # cookbook 'artifact', path: '/Users/reset/code/artifact'
119
119
  #
120
120
  # @example a cookbook dependency that will be retrieved from a Git server
121
- # cookbook 'artifact', git: 'git://github.com/RiotGames/artifact-cookbook.git'
121
+ # cookbook 'artifact', git: 'https://github.com/chef/artifact-cookbook.git'
122
122
  #
123
123
  # @overload cookbook(name, version_constraint, options = {})
124
124
  # @param [#to_s] name
@@ -146,7 +146,7 @@ module Berkshelf
146
146
  # @see PathLocation
147
147
  # @see GitLocation
148
148
  def cookbook(*args)
149
- options = args.last.is_a?(Hash) ? args.pop : Hash.new
149
+ options = args.last.is_a?(Hash) ? args.pop : {}
150
150
  name, constraint = args
151
151
 
152
152
  options[:path] &&= File.expand_path(options[:path], File.dirname(filepath))
@@ -156,7 +156,7 @@ module Berkshelf
156
156
  options[:group] += @active_group
157
157
  end
158
158
 
159
- add_dependency(name, constraint, options)
159
+ add_dependency(name, constraint, **options)
160
160
  end
161
161
  expose :cookbook
162
162
 
@@ -176,10 +176,10 @@ module Berkshelf
176
176
  # @option options [String] :path
177
177
  # path to the metadata file
178
178
  def metadata(options = {})
179
- path = options[:path] || File.dirname(filepath)
179
+ path = options[:path] || File.dirname(filepath)
180
180
 
181
181
  loader = Chef::Cookbook::CookbookVersionLoader.new(path)
182
- loader.load_cookbooks
182
+ loader.load!
183
183
  cookbook_version = loader.cookbook_version
184
184
  metadata = cookbook_version.metadata
185
185
 
@@ -282,7 +282,7 @@ module Berkshelf
282
282
  if @dependencies[name]
283
283
  # Only raise an exception if the dependency is a true duplicate
284
284
  groups = (options[:group].nil? || options[:group].empty?) ? [:default] : options[:group]
285
- if !(@dependencies[name].groups & groups).empty?
285
+ unless (@dependencies[name].groups & groups).empty?
286
286
  raise DuplicateDependencyDefined.new(name)
287
287
  end
288
288
  end
@@ -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 { |cookbook| cookbook.version }.last
503
+ end.max_by(&:version)
504
504
 
505
505
  unless latest.nil?
506
506
  hash[name] ||= {
@@ -644,7 +644,7 @@ module Berkshelf
644
644
  FileUtils.mkdir_p(cookbook_destination)
645
645
 
646
646
  # Dir.glob does not support backslash as a File separator
647
- src = cookbook.path.to_s.tr('\\', "/")
647
+ src = cookbook.path.to_s.tr("\\", "/")
648
648
  files = FileSyncer.glob(File.join(src, "**/*"))
649
649
 
650
650
  # strip directories
@@ -659,7 +659,7 @@ module Berkshelf
659
659
  files.reject! { |file_path| chefignore.ignored?(file_path) }
660
660
 
661
661
  # convert Pathname objects back to strings
662
- files.map! { |f| f.to_s }
662
+ files.map!(&:to_s)
663
663
 
664
664
  # copy each file to destination
665
665
  files.each do |rpath|
@@ -740,39 +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
  true
752
753
  end
753
754
 
754
- # Ensure that all dependencies defined in the Berksfile exist in this
755
- # lockfile.
756
- #
757
- # @raise [LockfileOutOfSync]
758
- # if there are dependencies specified in the Berksfile which do not
759
- # exist (or are not satisifed by) the lockfile
760
- #
761
- # @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]
762
763
  def validate_lockfile_trusted!
763
764
  raise LockfileOutOfSync unless lockfile.trusted?
765
+
764
766
  true
765
767
  end
766
768
 
767
- # Ensure that all dependencies in the lockfile are installed on this
768
- # system. You should validate that the lockfile can be trusted before
769
- # using this method.
770
- #
771
- # @raise [DependencyNotInstalled]
772
- # if the dependency in the lockfile is not in the Berkshelf shelf on
773
- # this system
774
- #
775
- # @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]
776
778
  def validate_dependencies_installed!
777
779
  lockfile.graph.locks.each do |_, dependency|
778
780
  unless dependency.installed?
@@ -783,13 +785,13 @@ module Berkshelf
783
785
  true
784
786
  end
785
787
 
786
- # Determine if any cookbooks were specified that aren't in our shelf.
787
- #
788
- # @param [Array<String>] names
789
- # a list of cookbook names
790
- #
791
- # @raise [DependencyNotFound]
792
- # 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
793
795
  def validate_cookbook_names!(names)
794
796
  missing = names - lockfile.graph.locks.keys
795
797
 
@@ -1,6 +1,6 @@
1
1
  require "chef/cookbook/cookbook_version_loader"
2
2
  require "chef/cookbook/syntax_check"
3
- require "berkshelf/errors"
3
+ require_relative "errors"
4
4
  require "chef/json_compat"
5
5
 
6
6
  module Berkshelf
@@ -66,7 +66,7 @@ module Berkshelf
66
66
  @loader ||=
67
67
  begin
68
68
  loader = Chef::Cookbook::CookbookVersionLoader.new(@path)
69
- loader.load_cookbooks
69
+ loader.load!
70
70
  loader
71
71
  end
72
72
  end
@@ -151,7 +151,8 @@ module Berkshelf
151
151
  def validate
152
152
  raise IOError, "No Cookbook found at: #{path}" unless path.exist?
153
153
 
154
- syntax_checker = Chef::Cookbook::SyntaxCheck.for_cookbook(cookbook_name, path)
154
+ syntax_checker = Chef::Cookbook::SyntaxCheck.new(path.to_path)
155
+
155
156
  unless syntax_checker.validate_ruby_files
156
157
  raise Berkshelf::Errors::CookbookSyntaxError, "Invalid ruby files in cookbook: #{cookbook_name} (#{version})."
157
158
  end
@@ -166,6 +167,7 @@ module Berkshelf
166
167
  json_file = "#{path}/metadata.json"
167
168
  rb_file = "#{path}/metadata.rb"
168
169
  return nil if File.exist?(json_file)
170
+
169
171
  md = Chef::Cookbook::Metadata.new
170
172
  md.from_file(rb_file)
171
173
  f = File.open(json_file, "w")
@@ -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
@@ -1,5 +1,5 @@
1
- require "berkshelf/api_client/remote_cookbook"
2
- require "berkshelf/cached_cookbook"
1
+ require_relative "api_client/remote_cookbook"
2
+ require_relative "cached_cookbook"
3
3
 
4
4
  module Berkshelf
5
5
  # Shim to look like a Berkshelf::APIClient but for a chef repo folder.
@@ -15,8 +15,10 @@ module Berkshelf
15
15
  def universe
16
16
  Dir.entries(cookbooks_path).sort.each_with_object([]) do |entry, cookbooks|
17
17
  next if entry[0] == "." # Skip hidden folders.
18
+
18
19
  entry_path = "#{cookbooks_path}/#{entry}"
19
20
  next unless File.directory?(entry_path) # Skip non-dirs.
21
+
20
22
  cookbook = begin
21
23
  Berkshelf::CachedCookbook.from_path(entry_path)
22
24
  rescue IOError
data/lib/berkshelf/cli.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "berkshelf"
1
+ require_relative "../berkshelf"
2
2
  require_relative "config"
3
3
  require_relative "commands/shelf"
4
4
 
@@ -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})"
@@ -13,7 +13,7 @@ module Berkshelf
13
13
  else
14
14
  Berkshelf.formatter.msg "Cookbooks in the Berkshelf shelf:"
15
15
  cookbooks.sort.each do |cookbook, versions|
16
- Berkshelf.formatter.msg(" * #{cookbook} (#{versions.sort.join(', ')})")
16
+ Berkshelf.formatter.msg(" * #{cookbook} (#{versions.sort.join(", ")})")
17
17
  end
18
18
  end
19
19
  end
@@ -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
@@ -69,13 +69,13 @@ module Berkshelf
69
69
  # how often we should pause between retries
70
70
  def initialize(uri = V1_API, options = {})
71
71
  options = options.dup
72
- options = { retries: 5, retry_interval: 0.5, ssl: Berkshelf::Config.instance.ssl }.merge(options)
73
- @api_uri = uri
72
+ options = { retries: 5, retry_interval: 0.5, ssl: Berkshelf::Config.instance.ssl }.merge(options)
73
+ @api_uri = uri
74
74
  options[:server_url] = uri
75
- @retries = options.delete(:retries)
75
+ @retries = options.delete(:retries)
76
76
  @retry_interval = options.delete(:retry_interval)
77
77
 
78
- @connection = Berkshelf::RidleyCompatJSON.new(options)
78
+ @connection = Berkshelf::RidleyCompatJSON.new(**options)
79
79
  end
80
80
 
81
81
  # Download and extract target cookbook archive to the local file system,
@@ -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
@@ -122,7 +122,7 @@ module Berkshelf
122
122
  default :email, nil
123
123
  default :license, nil
124
124
  end
125
- default :allowed_licenses, Array.new
125
+ default :allowed_licenses, []
126
126
  default :raise_license_exception, false
127
127
  config_context :vagrant do
128
128
  config_context :vm do
@@ -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
@@ -14,10 +14,10 @@ module FileUtils
14
14
  # symlink on Linux
15
15
  # @see {FileUtils::mv}
16
16
  def mv(src, dest, options = {})
17
- old_mv(src, dest, options)
17
+ old_mv(src, dest, **options)
18
18
  rescue Errno::EACCES, Errno::ENOENT
19
19
  options.delete(:force) if options.key?(:force)
20
- FileUtils.cp_r(src, dest, options)
20
+ FileUtils.cp_r(src, dest, **options)
21
21
  FileUtils.rm_rf(src)
22
22
  end
23
23
  end
@@ -1,3 +1,3 @@
1
1
  Dir["#{File.dirname(__FILE__)}/core_ext/*.rb"].sort.each do |path|
2
- require_relative "core_ext/#{File.basename(path, '.rb')}"
2
+ require_relative "core_ext/#{File.basename(path, ".rb")}"
3
3
  end
@@ -171,7 +171,7 @@ module Berkshelf
171
171
  "#{name} (#{version_constraint})",
172
172
  "locked_version: #{locked_version.inspect}",
173
173
  "groups: #{groups}",
174
- "location: #{location || 'default'}>",
174
+ "location: #{location || "default"}>",
175
175
  ].join(", ")
176
176
  end
177
177
 
@@ -1,6 +1,7 @@
1
- require "net/http"
2
- require "mixlib/archive"
3
- require "berkshelf/ssl_policies"
1
+ require "net/http" unless defined?(Net::HTTP)
2
+ require "mixlib/archive" unless defined?(Mixlib::Archive)
3
+ require_relative "ssl_policies"
4
+ require "faraday" unless defined?(Faraday)
4
5
 
5
6
  module Berkshelf
6
7
  class Downloader
@@ -83,7 +84,7 @@ module Berkshelf
83
84
  client_key: source.options[:client_key] || Berkshelf::Config.instance.chef.client_key,
84
85
  ssl: source.options[:ssl],
85
86
  }
86
- RidleyCompat.new_client(credentials) do |conn|
87
+ RidleyCompat.new_client(**credentials) do |conn|
87
88
  cookbook = Chef::CookbookVersion.load(name, version)
88
89
  manifest = cookbook.cookbook_manifest
89
90
  manifest.by_parent_directory.each do |segment, files|
@@ -120,7 +121,7 @@ module Berkshelf
120
121
  )
121
122
 
122
123
  begin
123
- url = URI(github_client.archive_link(cookbook_uri.path.gsub(/^\//, ""), ref: "v#{version}"))
124
+ url = URI(github_client.archive_link(cookbook_uri.path.gsub(%r{^/}, ""), ref: "v#{version}"))
124
125
  rescue Octokit::Unauthorized
125
126
  return nil
126
127
  end
@@ -131,6 +132,7 @@ module Berkshelf
131
132
  http.verify_mode = (options["ssl_verify"].nil? || options["ssl_verify"]) ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
132
133
  resp = http.get(url.request_uri)
133
134
  return nil unless resp.is_a?(Net::HTTPSuccess)
135
+
134
136
  open(archive_path, "wb") { |file| file.write(resp.body) }
135
137
 
136
138
  Mixlib::Archive.new(archive_path).extract(unpack_dir)
@@ -143,7 +145,7 @@ module Berkshelf
143
145
 
144
146
  File.join(unpack_dir, cookbook_directory)
145
147
  when :uri
146
- require "open-uri"
148
+ require "open-uri" unless defined?(OpenURI)
147
149
 
148
150
  tmp_dir = Dir.mktmpdir
149
151
  archive_path = Pathname.new(tmp_dir) + "#{name}-#{version}.tar.gz"
@@ -183,6 +185,7 @@ module Berkshelf
183
185
 
184
186
  resp = connection.get(cookbook_uri.request_uri + "&private_token=" + options["private_token"])
185
187
  return nil unless resp.status == 200
188
+
186
189
  open(archive_path, "wb") { |file| file.write(resp.body) }
187
190
 
188
191
  Mixlib::Archive.new(archive_path).extract(unpack_dir)
@@ -83,7 +83,7 @@ module Berkshelf
83
83
 
84
84
  def to_s
85
85
  @original_exception.to_s +
86
- "Unable to find a solution for demands: #{demands.join(', ')}"
86
+ "Unable to find a solution for demands: #{demands.join(", ")}"
87
87
  end
88
88
 
89
89
  alias_method :message, :to_s
@@ -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
 
@@ -372,7 +374,7 @@ module Berkshelf
372
374
 
373
375
  def to_s
374
376
  "Unknown license: '#{license}'\n" +
375
- "Available licenses: #{CookbookGenerator::LICENSES.join(', ')}"
377
+ "Available licenses: #{CookbookGenerator::LICENSES.join(", ")}"
376
378
  end
377
379
 
378
380
  alias_method :message, :to_s
@@ -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