berkshelf 7.0.8 → 7.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +4 -12
- data/Rakefile +3 -3
- data/berkshelf.gemspec +3 -4
- data/bin/berks +1 -1
- data/lib/berkshelf.rb +8 -9
- data/lib/berkshelf/api_client/chef_server_connection.rb +3 -2
- data/lib/berkshelf/api_client/connection.rb +1 -1
- data/lib/berkshelf/api_client/remote_cookbook.rb +1 -1
- data/lib/berkshelf/berksfile.rb +41 -39
- data/lib/berkshelf/cached_cookbook.rb +5 -3
- data/lib/berkshelf/chef_config_compat.rb +1 -1
- data/lib/berkshelf/chef_repo_universe.rb +4 -2
- data/lib/berkshelf/cli.rb +6 -6
- data/lib/berkshelf/commands/shelf.rb +1 -1
- data/lib/berkshelf/community_rest.rb +6 -6
- data/lib/berkshelf/config.rb +3 -3
- data/lib/berkshelf/cookbook_store.rb +2 -4
- data/lib/berkshelf/core_ext.rb +1 -1
- data/lib/berkshelf/core_ext/file_utils.rb +3 -3
- data/lib/berkshelf/dependency.rb +1 -1
- data/lib/berkshelf/downloader.rb +9 -6
- data/lib/berkshelf/errors.rb +5 -2
- data/lib/berkshelf/file_syncer.rb +10 -12
- data/lib/berkshelf/formatters/human.rb +1 -1
- data/lib/berkshelf/formatters/json.rb +1 -1
- data/lib/berkshelf/installer.rb +1 -1
- data/lib/berkshelf/location.rb +3 -3
- data/lib/berkshelf/locations/git.rb +6 -12
- data/lib/berkshelf/lockfile.rb +11 -11
- data/lib/berkshelf/logger.rb +4 -2
- data/lib/berkshelf/mixin/git.rb +3 -3
- data/lib/berkshelf/packager.rb +5 -7
- data/lib/berkshelf/resolver.rb +1 -1
- data/lib/berkshelf/ridley_compat.rb +1 -1
- data/lib/berkshelf/shell.rb +2 -1
- data/lib/berkshelf/shell_out.rb +4 -3
- data/lib/berkshelf/source.rb +8 -7
- data/lib/berkshelf/source_uri.rb +1 -1
- data/lib/berkshelf/ssl_policies.rb +5 -9
- data/lib/berkshelf/thor.rb +1 -1
- data/lib/berkshelf/thor_ext.rb +1 -1
- data/lib/berkshelf/uploader.rb +8 -6
- data/lib/berkshelf/validator.rb +2 -8
- data/lib/berkshelf/version.rb +1 -1
- data/lib/berkshelf/visualizer.rb +3 -3
- data/spec/config/knife.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/chef_server.rb +2 -2
- data/spec/support/git.rb +18 -18
- data/spec/support/path_helpers.rb +4 -4
- data/spec/unit/berkshelf/berksfile_spec.rb +7 -7
- data/spec/unit/berkshelf/cli_spec.rb +1 -2
- data/spec/unit/berkshelf/community_rest_spec.rb +1 -1
- data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +2 -2
- data/spec/unit/berkshelf/dependency_spec.rb +5 -5
- data/spec/unit/berkshelf/downloader_spec.rb +4 -8
- data/spec/unit/berkshelf/locations/base_spec.rb +1 -2
- data/spec/unit/berkshelf/locations/git_spec.rb +2 -5
- data/spec/unit/berkshelf/locations/path_spec.rb +1 -2
- data/spec/unit/berkshelf/lockfile_spec.rb +9 -18
- data/spec/unit/berkshelf/ridley_compat_spec.rb +2 -2
- data/spec/unit/berkshelf/source_spec.rb +30 -19
- data/spec/unit/berkshelf/ssl_policies_spec.rb +3 -6
- data/spec/unit/berkshelf/uploader_spec.rb +6 -10
- data/spec/unit/berkshelf/validator_spec.rb +0 -13
- metadata +10 -10
data/lib/berkshelf/shell.rb
CHANGED
@@ -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
|
data/lib/berkshelf/shell_out.rb
CHANGED
@@ -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 =
|
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
|
data/lib/berkshelf/source.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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 =
|
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).
|
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
|
|
data/lib/berkshelf/source_uri.rb
CHANGED
@@ -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
|
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.
|
35
|
-
::
|
36
|
-
|
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
|
data/lib/berkshelf/thor.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
require_relative "cli"
|
data/lib/berkshelf/thor_ext.rb
CHANGED
data/lib/berkshelf/uploader.rb
CHANGED
@@ -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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
data/lib/berkshelf/validator.rb
CHANGED
@@ -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
|
-
|
25
|
+
base, name = Pathname.new(cookbook.path.to_s).split
|
26
26
|
|
27
|
-
files = Dir.
|
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
|
data/lib/berkshelf/version.rb
CHANGED
data/lib/berkshelf/visualizer.rb
CHANGED
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[
|
9
|
+
cache_options( path: "#{ENV["HOME"]}/.chef/checksums" )
|
10
10
|
cookbook_path []
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/chef_server.rb
CHANGED
data/spec/support/git.rb
CHANGED
@@ -84,26 +84,26 @@ module Berkshelf
|
|
84
84
|
|
85
85
|
private
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
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
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
205
|
-
|
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) {
|
239
|
-
allow(dependency_two).to receive(:groups) {
|
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) {
|
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
|
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) {
|
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(
|
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(
|
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(
|
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(
|
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
|