berkshelf 7.0.8 → 7.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -12
  3. data/Rakefile +3 -3
  4. data/berkshelf.gemspec +3 -4
  5. data/bin/berks +1 -1
  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 +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.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 +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 +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 +11 -11
  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 +8 -6
  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 +10 -10
@@ -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
@@ -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.8".freeze
2
+ VERSION = "7.2.1".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
 
@@ -5,14 +5,12 @@ module Berkshelf
5
5
  let(:berksfile) do
6
6
  double(Berksfile,
7
7
  lockfile: lockfile,
8
- dependencies: []
9
- )
8
+ dependencies: [])
10
9
  end
11
10
 
12
11
  let(:lockfile) do
13
12
  double(Lockfile,
14
- graph: graph
15
- )
13
+ graph: graph)
16
14
  end
17
15
 
18
16
  let(:graph) { double(Lockfile::Graph, locks: {}) }
@@ -124,15 +122,13 @@ module Berkshelf
124
122
  cookbook_copyright: "user",
125
123
  cookbook_email: "user@example.com",
126
124
  cookbook_license: "apachev2",
127
- trusted_certs_dir: self_signed_crt_path
128
- )
125
+ trusted_certs_dir: self_signed_crt_path)
129
126
  end
130
127
 
131
128
  let(:berkshelf_config) do
132
129
  double(Config,
133
130
  ssl: double(verify: true),
134
- chef: chef_config
135
- )
131
+ chef: chef_config)
136
132
  end
137
133
 
138
134
  before do