berkshelf 7.0.7 → 7.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -3
  3. data/Rakefile +4 -4
  4. data/berkshelf.gemspec +10 -12
  5. data/bin/berks +5 -0
  6. data/lib/berkshelf.rb +8 -9
  7. data/lib/berkshelf/api_client/chef_server_connection.rb +3 -2
  8. data/lib/berkshelf/api_client/connection.rb +1 -1
  9. data/lib/berkshelf/api_client/remote_cookbook.rb +1 -1
  10. data/lib/berkshelf/berksfile.rb +41 -39
  11. data/lib/berkshelf/cached_cookbook.rb +6 -4
  12. data/lib/berkshelf/chef_config_compat.rb +2 -1
  13. data/lib/berkshelf/chef_repo_universe.rb +6 -4
  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.rb +1 -1
  20. data/lib/berkshelf/core_ext/file_utils.rb +3 -3
  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 +7 -12
  25. data/lib/berkshelf/formatters/human.rb +1 -1
  26. data/lib/berkshelf/formatters/json.rb +4 -4
  27. data/lib/berkshelf/installer.rb +1 -1
  28. data/lib/berkshelf/location.rb +3 -3
  29. data/lib/berkshelf/locations/git.rb +6 -12
  30. data/lib/berkshelf/lockfile.rb +14 -14
  31. data/lib/berkshelf/logger.rb +4 -2
  32. data/lib/berkshelf/mixin/git.rb +3 -3
  33. data/lib/berkshelf/packager.rb +5 -7
  34. data/lib/berkshelf/resolver.rb +1 -1
  35. data/lib/berkshelf/ridley_compat.rb +1 -1
  36. data/lib/berkshelf/shell.rb +2 -1
  37. data/lib/berkshelf/shell_out.rb +4 -3
  38. data/lib/berkshelf/source.rb +8 -7
  39. data/lib/berkshelf/source_uri.rb +1 -1
  40. data/lib/berkshelf/ssl_policies.rb +5 -9
  41. data/lib/berkshelf/thor.rb +1 -1
  42. data/lib/berkshelf/thor_ext.rb +1 -1
  43. data/lib/berkshelf/uploader.rb +11 -9
  44. data/lib/berkshelf/validator.rb +2 -8
  45. data/lib/berkshelf/version.rb +1 -1
  46. data/lib/berkshelf/visualizer.rb +3 -3
  47. data/spec/config/knife.rb +1 -1
  48. data/spec/spec_helper.rb +1 -1
  49. data/spec/support/chef_server.rb +2 -2
  50. data/spec/support/git.rb +18 -18
  51. data/spec/support/path_helpers.rb +4 -4
  52. data/spec/unit/berkshelf/berksfile_spec.rb +7 -7
  53. data/spec/unit/berkshelf/cli_spec.rb +1 -2
  54. data/spec/unit/berkshelf/community_rest_spec.rb +1 -1
  55. data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +2 -2
  56. data/spec/unit/berkshelf/dependency_spec.rb +5 -5
  57. data/spec/unit/berkshelf/downloader_spec.rb +4 -8
  58. data/spec/unit/berkshelf/locations/base_spec.rb +1 -2
  59. data/spec/unit/berkshelf/locations/git_spec.rb +2 -5
  60. data/spec/unit/berkshelf/locations/path_spec.rb +1 -2
  61. data/spec/unit/berkshelf/lockfile_spec.rb +9 -18
  62. data/spec/unit/berkshelf/ridley_compat_spec.rb +2 -2
  63. data/spec/unit/berkshelf/source_spec.rb +30 -19
  64. data/spec/unit/berkshelf/ssl_policies_spec.rb +3 -6
  65. data/spec/unit/berkshelf/uploader_spec.rb +6 -10
  66. data/spec/unit/berkshelf/validator_spec.rb +0 -13
  67. metadata +39 -193
  68. data/.github/lock.yml +0 -1
  69. data/.gitignore +0 -30
  70. data/.rubocop.yml +0 -12
  71. data/.travis.yml +0 -73
  72. data/CHANGELOG.legacy.md +0 -307
  73. data/CHANGELOG.md +0 -1589
  74. data/CONTRIBUTING.md +0 -68
  75. data/Gemfile.lock +0 -292
  76. data/PLUGINS.md +0 -25
  77. data/README.md +0 -72
  78. data/Thorfile +0 -61
  79. data/appveyor.yml +0 -31
  80. data/docs/berkshelf_for_newcomers.md +0 -64
  81. data/features/artifactory.feature +0 -70
  82. data/features/berksfile.feature +0 -46
  83. data/features/commands/apply.feature +0 -41
  84. data/features/commands/contingent.feature +0 -47
  85. data/features/commands/info.feature +0 -141
  86. data/features/commands/install.feature +0 -646
  87. data/features/commands/list.feature +0 -78
  88. data/features/commands/outdated.feature +0 -176
  89. data/features/commands/package.feature +0 -17
  90. data/features/commands/search.feature +0 -17
  91. data/features/commands/shelf/list.feature +0 -32
  92. data/features/commands/shelf/show.feature +0 -113
  93. data/features/commands/shelf/uninstall.feature +0 -96
  94. data/features/commands/show.feature +0 -83
  95. data/features/commands/update.feature +0 -142
  96. data/features/commands/upload.feature +0 -499
  97. data/features/commands/vendor.feature +0 -154
  98. data/features/commands/verify.feature +0 -29
  99. data/features/commands/viz.feature +0 -66
  100. data/features/community_site.feature +0 -37
  101. data/features/help.feature +0 -11
  102. data/features/json_formatter.feature +0 -158
  103. data/features/lifecycle.feature +0 -378
  104. data/features/lockfile.feature +0 -378
  105. data/features/step_definitions/berksfile_steps.rb +0 -54
  106. data/features/step_definitions/chef/config_steps.rb +0 -12
  107. data/features/step_definitions/chef_server_steps.rb +0 -60
  108. data/features/step_definitions/cli_steps.rb +0 -18
  109. data/features/step_definitions/config_steps.rb +0 -46
  110. data/features/step_definitions/environment_steps.rb +0 -11
  111. data/features/step_definitions/filesystem_steps.rb +0 -286
  112. data/features/step_definitions/gem_steps.rb +0 -13
  113. data/features/step_definitions/json_steps.rb +0 -29
  114. data/features/step_definitions/utility_steps.rb +0 -11
  115. data/features/support/aruba.rb +0 -12
  116. data/features/support/env.rb +0 -77
  117. data/spec/fixtures/cookbooks/example_cookbook/.gitignore +0 -2
  118. data/spec/fixtures/cookbooks/example_cookbook/.kitchen.yml +0 -26
@@ -21,7 +21,7 @@ module Berkshelf
21
21
  def initialize(berksfile, demands = [])
22
22
  @berksfile = berksfile
23
23
  @graph = Graph.new
24
- @demands = Array.new
24
+ @demands = []
25
25
 
26
26
  Array(demands).each { |demand| add_demand(demand) }
27
27
  compute_solver_engine(berksfile)
@@ -1,7 +1,7 @@
1
1
  require "chef/server_api"
2
2
  require "chef/http/simple_json"
3
3
  require "chef/http/simple"
4
- require "berkshelf/api_client/errors"
4
+ require_relative "api_client/errors"
5
5
  require "chef/config"
6
6
  require "chef/cookbook_manifest"
7
7
 
@@ -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)
@@ -15,6 +15,7 @@ module Berkshelf
15
15
 
16
16
  def say(*args)
17
17
  return if quiet?
18
+
18
19
  super(*args)
19
20
  end
20
21
  alias_method :info, :say
@@ -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
- require "berkshelf/api-client"
2
- require "berkshelf/chef_repo_universe"
3
- require "berkshelf/ssl_policies"
4
- require "openssl"
1
+ require_relative "api-client"
2
+ require_relative "chef_repo_universe"
3
+ require_relative "ssl_policies"
4
+ require "openssl" unless defined?(OpenSSL)
5
5
 
6
6
  module Berkshelf
7
7
  class Source
@@ -84,7 +84,7 @@ module Berkshelf
84
84
  def build_universe
85
85
  @universe = api_client.universe
86
86
  rescue => ex
87
- @universe = Array.new
87
+ @universe = []
88
88
  raise ex
89
89
  end
90
90
 
@@ -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
@@ -154,7 +154,7 @@ module Berkshelf
154
154
  end
155
155
 
156
156
  def inspect
157
- "#<#{self.class.name} #{type}: #{uri.to_s.inspect}, #{options.map { |k, v| "#{k}: #{v.inspect}" }.join(', ')}>"
157
+ "#<#{self.class.name} #{type}: #{uri.to_s.inspect}, #{options.map { |k, v| "#{k}: #{v.inspect}" }.join(", ")}>"
158
158
  end
159
159
 
160
160
  def hash
@@ -163,6 +163,7 @@ module Berkshelf
163
163
 
164
164
  def ==(other)
165
165
  return false unless other.is_a?(self.class)
166
+
166
167
  type == other.type && uri == other.uri
167
168
  end
168
169
 
@@ -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
@@ -8,9 +8,7 @@ module Berkshelf
8
8
  attr_reader :store
9
9
 
10
10
  def initialize
11
- @store = OpenSSL::X509::Store.new.tap do |store|
12
- store.set_default_paths
13
- end
11
+ @store = OpenSSL::X509::Store.new.tap(&:set_default_paths)
14
12
 
15
13
  set_custom_certs if ::File.exist?(trusted_certs_dir)
16
14
  end
@@ -31,11 +29,9 @@ module Berkshelf
31
29
  end
32
30
 
33
31
  def set_custom_certs
34
- Dir.chdir(trusted_certs_dir) do
35
- ::Dir.glob("{*.crt,*.pem}").each do |cert|
36
- cert = OpenSSL::X509::Certificate.new(IO.read(cert))
37
- add_trusted_cert(cert)
38
- 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)
39
35
  end
40
36
  end
41
37
  end
@@ -1 +1 @@
1
- require "berkshelf/cli"
1
+ require_relative "cli"
@@ -1,3 +1,3 @@
1
1
  Dir["#{File.dirname(__FILE__)}/thor_ext/*.rb"].sort.each do |path|
2
- require_relative "thor_ext/#{File.basename(path, '.rb')}"
2
+ require_relative "thor_ext/#{File.basename(path, ".rb")}"
3
3
  end
@@ -16,10 +16,10 @@ module Berkshelf
16
16
  opts = args.last.respond_to?(:to_hash) ? args.pop.to_hash.each_with_object({}) { |(k, v), m| m[k.to_sym] = v } : {}
17
17
 
18
18
  @options = {
19
- force: false,
20
- freeze: true,
19
+ force: false,
20
+ freeze: true,
21
21
  halt_on_frozen: false,
22
- validate: true,
22
+ validate: true,
23
23
  }.merge(opts)
24
24
 
25
25
  @names = Array(args).flatten
@@ -32,7 +32,7 @@ module Berkshelf
32
32
  Berkshelf.log.debug " No names given, using all cookbooks"
33
33
  filtered_cookbooks
34
34
  else
35
- Berkshelf.log.debug " Names given (#{names.join(', ')})"
35
+ Berkshelf.log.debug " Names given (#{names.join(", ")})"
36
36
  names.map { |name| lockfile.retrieve(name) }
37
37
  end
38
38
 
@@ -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
 
@@ -75,13 +75,15 @@ module Berkshelf
75
75
  [ cookbook_version ],
76
76
  force: options[:force],
77
77
  concurrency: 1, # sadly
78
- rest: connection
78
+ rest: connection,
79
+ skip_syntax_check: options[:skip_syntax_check]
79
80
  ).upload_cookbooks
80
81
  Berkshelf.formatter.uploaded(cookbook, connection)
81
82
  rescue Chef::Exceptions::CookbookFrozen
82
83
  if options[:halt_on_frozen]
83
84
  raise FrozenCookbook.new(cookbook)
84
85
  end
86
+
85
87
  Berkshelf.formatter.skipping(cookbook, connection)
86
88
  end
87
89
  ensure
@@ -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.7".freeze
2
+ VERSION = "7.2.0".freeze
3
3
  end
@@ -1,6 +1,6 @@
1
- require "set"
2
- require "tempfile"
3
- require "berkshelf/shell_out"
1
+ require "set" unless defined?(Set)
2
+ require "tempfile" unless defined?(Tempfile)
3
+ require_relative "shell_out"
4
4
 
5
5
  module Berkshelf
6
6
  class Visualizer
data/spec/config/knife.rb CHANGED
@@ -6,5 +6,5 @@ validation_client_name "validator"
6
6
  validation_key File.expand_path("spec/config/validator.pem")
7
7
  chef_server_url "http://localhost:26310"
8
8
  cache_type "BasicFile"
9
- cache_options( path: "#{ENV['HOME']}/.chef/checksums" )
9
+ cache_options( path: "#{ENV["HOME"]}/.chef/checksums" )
10
10
  cookbook_path []
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"
@@ -10,11 +10,11 @@ module Berkshelf
10
10
  attr_reader :server
11
11
 
12
12
  def clear_request_log
13
- @request_log = Array.new
13
+ @request_log = []
14
14
  end
15
15
 
16
16
  def request_log
17
- @request_log ||= Array.new
17
+ @request_log ||= []
18
18
  end
19
19
 
20
20
  def server_url
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
 
@@ -200,10 +200,10 @@ describe Berkshelf::Berksfile do
200
200
 
201
201
  describe "#dependencies" do
202
202
  let(:groups) do
203
- [
204
- :nautilus,
205
- :skarner,
206
- ]
203
+ %i{
204
+ nautilus
205
+ skarner
206
+ }
207
207
  end
208
208
 
209
209
  it "returns all Berkshelf::Dependencys added to the instance of Berksfile" do
@@ -235,8 +235,8 @@ describe Berkshelf::Berksfile do
235
235
  describe "#groups" do
236
236
  before do
237
237
  allow(subject).to receive(:dependencies) { [dependency_one, dependency_two] }
238
- allow(dependency_one).to receive(:groups) { [:nautilus, :skarner] }
239
- allow(dependency_two).to receive(:groups) { [:nautilus, :riven] }
238
+ allow(dependency_one).to receive(:groups) { %i{nautilus skarner} }
239
+ allow(dependency_two).to receive(:groups) { %i{nautilus riven} }
240
240
  end
241
241
 
242
242
  it "returns a hash containing keys for every group a dependency is a member of" do
@@ -255,7 +255,7 @@ describe Berkshelf::Berksfile do
255
255
  describe "#add_dependency" do
256
256
  let(:name) { "cookbook_one" }
257
257
  let(:constraint) { "= 1.2.0" }
258
- let(:options) { Hash.new }
258
+ let(:options) { {} }
259
259
 
260
260
  before(:each) do
261
261
  subject.add_dependency(name, constraint, options)
@@ -13,8 +13,7 @@ module Berkshelf
13
13
  describe "#upload" do
14
14
  it "calls to upload with params if passed in cli" do
15
15
  expect(berksfile).to receive(:upload).with(cookbooks,
16
- include(skip_syntax_check: true, freeze: false)
17
- )
16
+ include(skip_syntax_check: true, freeze: false))
18
17
 
19
18
  subject.options[:skip_syntax_check] = true
20
19
  subject.options[:no_freeze] = true
@@ -68,7 +68,7 @@ describe Berkshelf::CommunityREST do
68
68
  let(:archive) { double("archive", path: "/foo/bar", unlink: true) }
69
69
 
70
70
  before do
71
- allow(subject).to receive(:stream).with(any_args()).and_return(archive)
71
+ allow(subject).to receive(:stream).with(any_args).and_return(archive)
72
72
  allow(Berkshelf::CommunityREST).to receive(:unpack)
73
73
  .and_return("/some/path")
74
74
  end
@@ -7,12 +7,12 @@ describe FileUtils do
7
7
  let(:options) { {} }
8
8
 
9
9
  it "uses mv by default" do
10
- expect(FileUtils).to receive(:old_mv).with(src, dest, options)
10
+ expect(FileUtils).to receive(:old_mv).with(src, dest, **options)
11
11
  FileUtils.mv(src, dest, options)
12
12
  end
13
13
 
14
14
  it "replaces mv with cp_r and rm_rf" do
15
- expect(FileUtils).to receive(:cp_r).with(src, dest, options)
15
+ expect(FileUtils).to receive(:cp_r).with(src, dest, **options)
16
16
  expect(FileUtils).to receive(:rm_rf).with(src)
17
17
 
18
18
  FileUtils.mv(src, dest, options)
@@ -71,7 +71,7 @@ describe Berkshelf::Dependency do
71
71
  end
72
72
 
73
73
  context "given a group option containing an array of groups" do
74
- let(:groups) { [ :development, :test ] }
74
+ let(:groups) { %i{development test} }
75
75
  let(:source) { described_class.new(berksfile, cookbook_name, group: groups) }
76
76
 
77
77
  it "assigns all the groups to the group attribute" do
@@ -95,24 +95,24 @@ describe Berkshelf::Dependency do
95
95
  describe "#add_group" do
96
96
  it "stores strings as symbols" do
97
97
  subject.add_group "foo"
98
- expect(subject.groups).to eq([:default, :foo])
98
+ expect(subject.groups).to eq(%i{default foo})
99
99
  end
100
100
 
101
101
  it "does not store duplicate groups" do
102
102
  subject.add_group "bar"
103
103
  subject.add_group "bar"
104
104
  subject.add_group :bar
105
- expect(subject.groups).to eq([:default, :bar])
105
+ expect(subject.groups).to eq(%i{default bar})
106
106
  end
107
107
 
108
108
  it "adds multiple groups" do
109
109
  subject.add_group "baz", "quux"
110
- expect(subject.groups).to eq([:default, :baz, :quux])
110
+ expect(subject.groups).to eq(%i{default baz quux})
111
111
  end
112
112
 
113
113
  it "handles multiple groups as an array" do
114
114
  subject.add_group %w{baz quux}
115
- expect(subject.groups).to eq([:default, :baz, :quux])
115
+ expect(subject.groups).to eq(%i{default baz quux})
116
116
  end
117
117
  end
118
118