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.
- checksums.yaml +4 -4
- data/Gemfile +3 -12
- data/Rakefile +3 -3
- data/berkshelf.gemspec +3 -4
- data/bin/berks +1 -1
- data/lib/berkshelf/api_client/chef_server_connection.rb +7 -8
- data/lib/berkshelf/api_client/connection.rb +1 -1
- data/lib/berkshelf/api_client/remote_cookbook.rb +1 -1
- data/lib/berkshelf/api_client.rb +2 -2
- data/lib/berkshelf/berksfile.rb +44 -42
- 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/file_utils.rb +3 -3
- data/lib/berkshelf/core_ext.rb +1 -1
- 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 +8 -8
- data/lib/berkshelf/location.rb +4 -4
- data/lib/berkshelf/locations/git.rb +6 -12
- data/lib/berkshelf/locations/github.rb +1 -1
- 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 +6 -10
- data/lib/berkshelf/thor.rb +1 -1
- data/lib/berkshelf/thor_ext/hash_with_indifferent_access.rb +1 -1
- data/lib/berkshelf/thor_ext.rb +1 -1
- data/lib/berkshelf/uploader.rb +37 -35
- data/lib/berkshelf/validator.rb +2 -8
- data/lib/berkshelf/version.rb +1 -1
- data/lib/berkshelf/visualizer.rb +3 -3
- data/lib/berkshelf.rb +8 -9
- data/spec/config/knife.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/support/chef_server.rb +2 -2
- data/spec/support/git.rb +19 -19
- data/spec/support/path_helpers.rb +4 -4
- data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/attributes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/files/default/file.h +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/metadata.rb +2 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/recipes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/templates/default/template.erb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/attributes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/files/default/file.h +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/metadata.rb +2 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/recipes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/templates/default/template.erb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/attributes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/files/default/file.h +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/metadata.rb +2 -0
- data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/recipes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/templates/default/template.erb +0 -0
- data/spec/unit/berkshelf/berksfile_spec.rb +7 -7
- data/spec/unit/berkshelf/berkshelf/api_client/chef_server_connection_spec.rb +65 -0
- 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 +6 -6
- data/spec/unit/berkshelf/downloader_spec.rb +4 -8
- data/spec/unit/berkshelf/location_spec.rb +1 -1
- 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 +26 -10
|
@@ -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 =
|
|
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,10 +87,11 @@ module Berkshelf
|
|
|
88
87
|
target = File.readlink(source_file)
|
|
89
88
|
|
|
90
89
|
destination = File.expand_path(destination)
|
|
91
|
-
|
|
92
|
-
FileUtils.ln_sf(target, "#{destination}/#{relative_path}")
|
|
93
|
-
end
|
|
90
|
+
FileUtils.ln_sf(target, "#{destination}/#{relative_path}")
|
|
94
91
|
when :file
|
|
92
|
+
# TODO: Workaround issue related to [1] which impacts running ChefSpec on Github Actions
|
|
93
|
+
# [1] https://github.com/docker/for-linux/issues/1015
|
|
94
|
+
FileUtils.touch(source_file)
|
|
95
95
|
FileUtils.cp(source_file, "#{destination}/#{relative_path}")
|
|
96
96
|
else
|
|
97
97
|
type = File.ftype(source_file)
|
|
@@ -103,9 +103,7 @@ module Berkshelf
|
|
|
103
103
|
|
|
104
104
|
if options[:delete]
|
|
105
105
|
# Remove any files in the destination that are not in the source files
|
|
106
|
-
destination_files =
|
|
107
|
-
glob("**/*")
|
|
108
|
-
end
|
|
106
|
+
destination_files = glob("**/*", base: destination)
|
|
109
107
|
|
|
110
108
|
# Remove any extra files that are present in the destination, but are
|
|
111
109
|
# not in the source list
|
|
@@ -68,7 +68,7 @@ module Berkshelf
|
|
|
68
68
|
|
|
69
69
|
hash.each do |name, info|
|
|
70
70
|
info["remote"].each do |remote_source, remote_version|
|
|
71
|
-
out = " * #{name} (#{info[
|
|
71
|
+
out = " * #{name} (#{info["local"]} => #{remote_version})"
|
|
72
72
|
|
|
73
73
|
unless remote_source.default?
|
|
74
74
|
out << " [#{remote_source.uri}]"
|
data/lib/berkshelf/installer.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative "api-client"
|
|
2
2
|
require "concurrent/executors"
|
|
3
3
|
require "concurrent/future"
|
|
4
4
|
|
|
@@ -19,13 +19,13 @@ module Berkshelf
|
|
|
19
19
|
def build_universe
|
|
20
20
|
berksfile.sources.collect do |source|
|
|
21
21
|
Thread.new do
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
|
|
23
|
+
Berkshelf.formatter.msg("Fetching cookbook index from #{source}...")
|
|
24
|
+
source.build_universe
|
|
25
|
+
rescue Berkshelf::APIClientError => ex
|
|
26
|
+
Berkshelf.formatter.warn "Error retrieving universe from source: #{source}"
|
|
27
|
+
Berkshelf.formatter.warn " * [#{ex.class}] #{ex}"
|
|
28
|
+
|
|
29
29
|
end
|
|
30
30
|
end.map(&:join)
|
|
31
31
|
end
|
data/lib/berkshelf/location.rb
CHANGED
|
@@ -9,7 +9,7 @@ module Berkshelf
|
|
|
9
9
|
# is returned.
|
|
10
10
|
#
|
|
11
11
|
# @example Create a git location
|
|
12
|
-
# Location.init(dependency, git: '
|
|
12
|
+
# Location.init(dependency, git: 'https://github.com/berkshelf/berkshelf.git')
|
|
13
13
|
#
|
|
14
14
|
# @example Create a GitHub location
|
|
15
15
|
# Location.init(dependency, github: 'berkshelf/berkshelf')
|
|
@@ -28,9 +28,9 @@ module Berkshelf
|
|
|
28
28
|
|
|
29
29
|
private
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
56
|
-
|
|
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
|
-
|
|
60
|
-
|
|
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
|
|
@@ -9,7 +9,7 @@ module Berkshelf
|
|
|
9
9
|
when :https
|
|
10
10
|
options[:git] = "https://#{HOST}/#{options.delete(:github)}.git"
|
|
11
11
|
when :git
|
|
12
|
-
options[:git] = "
|
|
12
|
+
options[:git] = "https://#{HOST}/#{options.delete(:github)}.git"
|
|
13
13
|
else
|
|
14
14
|
# if some bizarre value is provided, treat it as :https
|
|
15
15
|
options[:git] = "https://#{HOST}/#{options.delete(:github)}.git"
|
data/lib/berkshelf/lockfile.rb
CHANGED
|
@@ -228,7 +228,7 @@ module Berkshelf
|
|
|
228
228
|
|
|
229
229
|
# @return [Array<CachedCookbook>]
|
|
230
230
|
def cached
|
|
231
|
-
graph.locks.values.collect
|
|
231
|
+
graph.locks.values.collect(&:cached_cookbook)
|
|
232
232
|
end
|
|
233
233
|
|
|
234
234
|
# The list of dependencies constrained in this lockfile.
|
|
@@ -511,8 +511,8 @@ module Berkshelf
|
|
|
511
511
|
"#<Berkshelf::Lockfile #{Pathname.new(filepath).basename}, dependencies: #{dependencies.inspect}>"
|
|
512
512
|
end
|
|
513
513
|
|
|
514
|
-
|
|
515
|
-
|
|
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
|
|
@@ -570,7 +570,7 @@ module Berkshelf
|
|
|
570
570
|
end
|
|
571
571
|
end
|
|
572
572
|
|
|
573
|
-
graph << " #{name} (#{info[
|
|
573
|
+
graph << " #{name} (#{info["locked_version"]})\n"
|
|
574
574
|
end
|
|
575
575
|
|
|
576
576
|
contents = "#{dependencies}\n#{graph}"
|
|
@@ -599,9 +599,9 @@ module Berkshelf
|
|
|
599
599
|
|
|
600
600
|
private
|
|
601
601
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
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
|
-
|
|
619
|
-
|
|
620
|
-
|
|
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
|
-
|
|
634
|
+
# The class representing an internal graph.
|
|
635
635
|
class Graph
|
|
636
636
|
include Enumerable
|
|
637
637
|
|
data/lib/berkshelf/logger.rb
CHANGED
|
@@ -3,7 +3,7 @@ module Berkshelf
|
|
|
3
3
|
def initialize(device = STDOUT)
|
|
4
4
|
super
|
|
5
5
|
self.level = Logger::WARN
|
|
6
|
-
@filter_params =
|
|
6
|
+
@filter_params = []
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
# Reimplements Logger#add adding message filtering. The info,
|
|
@@ -28,6 +28,7 @@ module Berkshelf
|
|
|
28
28
|
if @logdev.nil? || severity < (@level)
|
|
29
29
|
return true
|
|
30
30
|
end
|
|
31
|
+
|
|
31
32
|
progname ||= @progname
|
|
32
33
|
if message.nil?
|
|
33
34
|
if block_given?
|
|
@@ -38,7 +39,8 @@ module Berkshelf
|
|
|
38
39
|
end
|
|
39
40
|
end
|
|
40
41
|
@logdev.write(
|
|
41
|
-
format_message(format_severity(severity), Time.now, progname, filter(message))
|
|
42
|
+
format_message(format_severity(severity), Time.now, progname, filter(message))
|
|
43
|
+
)
|
|
42
44
|
true
|
|
43
45
|
end
|
|
44
46
|
|
data/lib/berkshelf/mixin/git.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative "../shell_out"
|
|
2
2
|
|
|
3
3
|
module Berkshelf
|
|
4
4
|
module Mixin
|
|
@@ -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)
|
data/lib/berkshelf/packager.rb
CHANGED
|
@@ -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
|
-
|
|
44
|
-
|
|
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
|
-
|
|
65
|
+
# @return [String]
|
|
68
66
|
attr_reader :out_dir
|
|
69
67
|
|
|
70
|
-
|
|
68
|
+
# @return [String]
|
|
71
69
|
attr_reader :filename
|
|
72
70
|
end
|
|
73
71
|
end
|
data/lib/berkshelf/resolver.rb
CHANGED
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
|
|
@@ -22,7 +20,7 @@ module Berkshelf
|
|
|
22
20
|
end
|
|
23
21
|
|
|
24
22
|
def trusted_certs_dir
|
|
25
|
-
config_dir = Berkshelf.config.chef.trusted_certs_dir.to_s.tr(
|
|
23
|
+
config_dir = Berkshelf.config.chef.trusted_certs_dir.to_s.tr("\\", "/")
|
|
26
24
|
if config_dir.empty? || !::File.exist?(config_dir)
|
|
27
25
|
File.join(ENV["HOME"], ".chef", "trusted_certs")
|
|
28
26
|
else
|
|
@@ -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
|
|
|
@@ -59,39 +59,41 @@ module Berkshelf
|
|
|
59
59
|
connection.get("users/#{Berkshelf.config.chef.node_name}") rescue nil
|
|
60
60
|
|
|
61
61
|
cookbooks.map do |cookbook|
|
|
62
|
+
|
|
63
|
+
compiled_metadata = cookbook.compile_metadata
|
|
64
|
+
cookbook.reload if compiled_metadata
|
|
65
|
+
cookbook_version = cookbook.cookbook_version
|
|
66
|
+
Berkshelf.log.debug " Uploading #{cookbook.cookbook_name}"
|
|
67
|
+
cookbook_version.freeze_version if options[:freeze]
|
|
68
|
+
|
|
69
|
+
# another two lines that are necessary for chef < 13.2 support (affects 11.x/12.x as well)
|
|
70
|
+
cookbook_version.metadata.maintainer "" if cookbook_version.metadata.maintainer.nil?
|
|
71
|
+
cookbook_version.metadata.maintainer_email "" if cookbook_version.metadata.maintainer_email.nil?
|
|
72
|
+
|
|
62
73
|
begin
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
Chef::CookbookUploader.new(
|
|
75
|
-
[ cookbook_version ],
|
|
76
|
-
force: options[:force],
|
|
77
|
-
concurrency: 1, # sadly
|
|
78
|
-
rest: connection
|
|
79
|
-
).upload_cookbooks
|
|
80
|
-
Berkshelf.formatter.uploaded(cookbook, connection)
|
|
81
|
-
rescue Chef::Exceptions::CookbookFrozen
|
|
82
|
-
if options[:halt_on_frozen]
|
|
83
|
-
raise FrozenCookbook.new(cookbook)
|
|
84
|
-
end
|
|
85
|
-
Berkshelf.formatter.skipping(cookbook, connection)
|
|
86
|
-
end
|
|
87
|
-
ensure
|
|
88
|
-
if compiled_metadata
|
|
89
|
-
# this is necessary on windows to clean up the ruby object that was pointing at the file
|
|
90
|
-
# so that we can reliably delete it. windows is terrible.
|
|
91
|
-
GC.start
|
|
92
|
-
File.unlink(compiled_metadata)
|
|
74
|
+
Chef::CookbookUploader.new(
|
|
75
|
+
[ cookbook_version ],
|
|
76
|
+
force: options[:force],
|
|
77
|
+
concurrency: 1, # sadly
|
|
78
|
+
rest: connection,
|
|
79
|
+
skip_syntax_check: options[:skip_syntax_check]
|
|
80
|
+
).upload_cookbooks
|
|
81
|
+
Berkshelf.formatter.uploaded(cookbook, connection)
|
|
82
|
+
rescue Chef::Exceptions::CookbookFrozen
|
|
83
|
+
if options[:halt_on_frozen]
|
|
84
|
+
raise FrozenCookbook.new(cookbook)
|
|
93
85
|
end
|
|
86
|
+
|
|
87
|
+
Berkshelf.formatter.skipping(cookbook, connection)
|
|
94
88
|
end
|
|
89
|
+
ensure
|
|
90
|
+
if compiled_metadata
|
|
91
|
+
# this is necessary on windows to clean up the ruby object that was pointing at the file
|
|
92
|
+
# so that we can reliably delete it. windows is terrible.
|
|
93
|
+
GC.start
|
|
94
|
+
File.unlink(compiled_metadata)
|
|
95
|
+
end
|
|
96
|
+
|
|
95
97
|
end
|
|
96
98
|
end
|
|
97
99
|
end
|
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/lib/berkshelf.rb
CHANGED
|
@@ -10,20 +10,20 @@ 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
|
|
|
24
24
|
require_relative "berkshelf/core_ext"
|
|
25
25
|
require_relative "berkshelf/thor_ext"
|
|
26
|
-
|
|
26
|
+
require_relative "berkshelf/chef_config_compat"
|
|
27
27
|
|
|
28
28
|
module Berkshelf
|
|
29
29
|
Encoding.default_external = Encoding::UTF_8
|
|
@@ -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"
|