berkshelf 5.2.0 → 8.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +19 -47
- data/Rakefile +14 -4
- data/berkshelf.gemspec +61 -40
- data/bin/berks +2 -2
- data/lib/berkshelf/api-client.rb +1 -0
- data/lib/berkshelf/api_client/chef_server_connection.rb +29 -0
- data/lib/berkshelf/api_client/connection.rb +57 -0
- data/lib/berkshelf/api_client/errors.rb +10 -0
- data/lib/berkshelf/api_client/remote_cookbook.rb +56 -0
- data/lib/berkshelf/api_client/version.rb +5 -0
- data/lib/berkshelf/api_client.rb +24 -0
- data/lib/berkshelf/berksfile.rb +149 -122
- data/lib/berkshelf/cached_cookbook.rb +127 -24
- data/lib/berkshelf/chef_config_compat.rb +51 -0
- data/lib/berkshelf/chef_repo_universe.rb +47 -0
- data/lib/berkshelf/cli.rb +143 -174
- data/lib/berkshelf/commands/shelf.rb +20 -19
- data/lib/berkshelf/community_rest.rb +59 -94
- data/lib/berkshelf/config.rb +97 -127
- data/lib/berkshelf/cookbook_store.rb +7 -6
- data/lib/berkshelf/core_ext/file.rb +1 -1
- data/lib/berkshelf/core_ext/file_utils.rb +4 -4
- data/lib/berkshelf/core_ext.rb +1 -1
- data/lib/berkshelf/dependency.rb +25 -32
- data/lib/berkshelf/downloader.rb +66 -39
- data/lib/berkshelf/errors.rb +23 -17
- data/lib/berkshelf/file_syncer.rb +24 -47
- data/lib/berkshelf/formatters/human.rb +7 -5
- data/lib/berkshelf/formatters/json.rb +6 -6
- data/lib/berkshelf/installer.rb +120 -111
- data/lib/berkshelf/location.rb +14 -14
- data/lib/berkshelf/locations/base.rb +1 -1
- data/lib/berkshelf/locations/git.rb +16 -24
- data/lib/berkshelf/locations/github.rb +2 -2
- data/lib/berkshelf/locations/path.rb +2 -2
- data/lib/berkshelf/lockfile.rb +326 -328
- data/lib/berkshelf/logger.rb +64 -1
- data/lib/berkshelf/mixin/git.rb +6 -5
- data/lib/berkshelf/packager.rb +44 -10
- data/lib/berkshelf/resolver/graph.rb +1 -1
- data/lib/berkshelf/resolver.rb +4 -4
- data/lib/berkshelf/ridley_compat.rb +109 -0
- data/lib/berkshelf/shell.rb +2 -1
- data/lib/berkshelf/shell_out.rb +18 -0
- data/lib/berkshelf/source.rb +77 -33
- data/lib/berkshelf/source_uri.rb +4 -4
- data/lib/berkshelf/ssl_policies.rb +38 -0
- 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 +106 -70
- data/lib/berkshelf/validator.rb +13 -5
- data/lib/berkshelf/version.rb +1 -1
- data/lib/berkshelf/visualizer.rb +16 -11
- data/lib/berkshelf.rb +106 -81
- data/spec/config/knife.rb +4 -4
- data/spec/data/trusted_certs/example.crt +22 -0
- data/spec/fixtures/Berksfile +3 -3
- data/spec/fixtures/complex-cookbook-path/cookbooks/app/metadata.rb +2 -0
- data/spec/fixtures/complex-cookbook-path/cookbooks/jenkins/metadata.rb +2 -0
- data/spec/fixtures/complex-cookbook-path/cookbooks/jenkins-config/metadata.rb +4 -0
- data/spec/fixtures/cookbook-path/jenkins-config/metadata.rb +3 -3
- data/spec/fixtures/cookbook-path-uploader/apt-2.3.6/metadata.rb +2 -0
- data/spec/fixtures/cookbook-path-uploader/build-essential-1.4.2/metadata.rb +2 -0
- data/spec/fixtures/cookbook-path-uploader/jenkins-2.0.3/metadata.rb +5 -0
- data/spec/fixtures/cookbook-path-uploader/jenkins-config-0.1.0/metadata.rb +4 -0
- data/spec/fixtures/cookbook-path-uploader/runit-1.5.8/metadata.rb +5 -0
- data/spec/fixtures/cookbook-path-uploader/yum-3.0.6/metadata.rb +2 -0
- data/spec/fixtures/cookbook-path-uploader/yum-epel-0.2.0/metadata.rb +3 -0
- data/spec/fixtures/cookbook-store/jenkins-2.0.3/metadata.rb +5 -5
- data/spec/fixtures/cookbook-store/jenkins-2.0.4/metadata.rb +4 -4
- data/spec/fixtures/cookbooks/example_cookbook/metadata.rb +3 -3
- data/spec/fixtures/cookbooks/example_cookbook-0.5.0/metadata.rb +3 -3
- data/spec/spec_helper.rb +56 -64
- data/spec/support/chef_api.rb +15 -16
- data/spec/support/chef_server.rb +71 -69
- data/spec/support/git.rb +59 -58
- data/spec/support/kitchen.rb +0 -14
- data/spec/support/matchers/file_system_matchers.rb +4 -5
- data/spec/support/matchers/filepath_matchers.rb +2 -2
- data/spec/support/path_helpers.rb +17 -17
- data/spec/support/shared_examples/formatter.rb +1 -1
- 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 +84 -105
- data/spec/unit/berkshelf/berkshelf/api_client/chef_server_connection_spec.rb +65 -0
- data/spec/unit/berkshelf/berkshelf/api_client/connection_spec.rb +157 -0
- data/spec/unit/berkshelf/berkshelf/api_client/remote_cookbook_spec.rb +23 -0
- data/spec/unit/berkshelf/berkshelf/api_client_spec.rb +9 -0
- data/spec/unit/berkshelf/cached_cookbook_spec.rb +45 -47
- data/spec/unit/berkshelf/chef_repo_universe_spec.rb +37 -0
- data/spec/unit/berkshelf/cli_spec.rb +7 -8
- data/spec/unit/berkshelf/community_rest_spec.rb +82 -90
- data/spec/unit/berkshelf/config_spec.rb +51 -22
- data/spec/unit/berkshelf/cookbook_store_spec.rb +41 -41
- data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +7 -8
- data/spec/unit/berkshelf/core_ext/pathname_spec.rb +1 -1
- data/spec/unit/berkshelf/dependency_spec.rb +48 -48
- data/spec/unit/berkshelf/downloader_spec.rb +191 -34
- data/spec/unit/berkshelf/errors_spec.rb +3 -3
- data/spec/unit/berkshelf/file_syncer_spec.rb +87 -87
- data/spec/unit/berkshelf/formatters/base_spec.rb +23 -23
- data/spec/unit/berkshelf/formatters/human_spec.rb +2 -2
- data/spec/unit/berkshelf/formatters/json_spec.rb +2 -2
- data/spec/unit/berkshelf/formatters/null_spec.rb +3 -3
- data/spec/unit/berkshelf/installer_spec.rb +8 -8
- data/spec/unit/berkshelf/location_spec.rb +11 -11
- data/spec/unit/berkshelf/locations/base_spec.rb +35 -36
- data/spec/unit/berkshelf/locations/git_spec.rb +90 -93
- data/spec/unit/berkshelf/locations/path_spec.rb +40 -41
- data/spec/unit/berkshelf/lockfile_parser_spec.rb +71 -71
- data/spec/unit/berkshelf/lockfile_spec.rb +205 -211
- data/spec/unit/berkshelf/logger_spec.rb +3 -3
- data/spec/unit/berkshelf/mixin/logging_spec.rb +5 -5
- data/spec/unit/berkshelf/packager_spec.rb +2 -2
- data/spec/unit/berkshelf/resolver/graph_spec.rb +10 -8
- data/spec/unit/berkshelf/resolver_spec.rb +17 -17
- data/spec/unit/berkshelf/ridley_compat_spec.rb +16 -0
- data/spec/unit/berkshelf/shell_spec.rb +34 -34
- data/spec/unit/berkshelf/source_spec.rb +186 -20
- data/spec/unit/berkshelf/source_uri_spec.rb +1 -1
- data/spec/unit/berkshelf/ssl_policies_spec.rb +86 -0
- data/spec/unit/berkshelf/uploader_spec.rb +146 -64
- data/spec/unit/berkshelf/validator_spec.rb +23 -16
- data/spec/unit/berkshelf/visualizer_spec.rb +24 -15
- data/spec/unit/berkshelf_spec.rb +18 -18
- metadata +138 -289
- data/.gitignore +0 -29
- data/.travis.yml +0 -64
- data/CHANGELOG.legacy.md +0 -307
- data/CHANGELOG.md +0 -1358
- data/CONTRIBUTING.md +0 -64
- data/Gemfile.lock +0 -399
- data/Guardfile +0 -23
- data/PLUGINS.md +0 -25
- data/README.md +0 -70
- data/Thorfile +0 -61
- data/appveyor.yml +0 -31
- data/docs/berkshelf_for_newcomers.md +0 -65
- data/features/berksfile.feature +0 -46
- data/features/commands/apply.feature +0 -41
- data/features/commands/contingent.feature +0 -48
- data/features/commands/cookbook.feature +0 -35
- data/features/commands/info.feature +0 -99
- data/features/commands/init.feature +0 -27
- data/features/commands/install.feature +0 -636
- data/features/commands/list.feature +0 -78
- data/features/commands/outdated.feature +0 -130
- data/features/commands/package.feature +0 -17
- data/features/commands/search.feature +0 -17
- data/features/commands/shelf/list.feature +0 -32
- data/features/commands/shelf/show.feature +0 -143
- data/features/commands/shelf/uninstall.feature +0 -96
- data/features/commands/show.feature +0 -83
- data/features/commands/update.feature +0 -142
- data/features/commands/upload.feature +0 -426
- data/features/commands/vendor.feature +0 -111
- data/features/commands/verify.feature +0 -29
- data/features/commands/viz.feature +0 -66
- data/features/community_site.feature +0 -37
- data/features/config.feature +0 -111
- data/features/help.feature +0 -11
- data/features/json_formatter.feature +0 -161
- data/features/lifecycle.feature +0 -378
- data/features/lockfile.feature +0 -378
- data/features/step_definitions/berksfile_steps.rb +0 -39
- data/features/step_definitions/chef/config_steps.rb +0 -12
- data/features/step_definitions/chef_server_steps.rb +0 -60
- data/features/step_definitions/cli_steps.rb +0 -18
- data/features/step_definitions/config_steps.rb +0 -46
- data/features/step_definitions/environment_steps.rb +0 -7
- data/features/step_definitions/filesystem_steps.rb +0 -269
- data/features/step_definitions/gem_steps.rb +0 -13
- data/features/step_definitions/json_steps.rb +0 -23
- data/features/step_definitions/utility_steps.rb +0 -11
- data/features/support/aruba.rb +0 -12
- data/features/support/env.rb +0 -82
- data/generator_files/Berksfile.erb +0 -11
- data/generator_files/CHANGELOG.md.erb +0 -3
- data/generator_files/Gemfile.erb +0 -8
- data/generator_files/README.md.erb +0 -42
- data/generator_files/Thorfile.erb +0 -11
- data/generator_files/Vagrantfile.erb +0 -117
- data/generator_files/chefignore +0 -94
- data/generator_files/default_recipe.erb +0 -6
- data/generator_files/default_test.rb.erb +0 -11
- data/generator_files/gitignore.erb +0 -23
- data/generator_files/helpers.rb.erb +0 -7
- data/generator_files/licenses/apachev2.erb +0 -13
- data/generator_files/licenses/gplv2.erb +0 -15
- data/generator_files/licenses/gplv3.erb +0 -14
- data/generator_files/licenses/mit.erb +0 -20
- data/generator_files/licenses/reserved.erb +0 -3
- data/generator_files/metadata.rb.erb +0 -11
- data/lib/berkshelf/base_generator.rb +0 -43
- data/lib/berkshelf/commands/test_command.rb +0 -13
- data/lib/berkshelf/cookbook_generator.rb +0 -133
- data/lib/berkshelf/init_generator.rb +0 -195
- data/spec/fixtures/cookbooks/example_cookbook/.gitignore +0 -2
- data/spec/fixtures/cookbooks/example_cookbook/.kitchen.yml +0 -26
- data/spec/unit/berkshelf/cookbook_generator_spec.rb +0 -110
- data/spec/unit/berkshelf/init_generator_spec.rb +0 -263
data/lib/berkshelf/uploader.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
require "chef/cookbook/chefignore"
|
2
|
+
require "chef/cookbook/cookbook_version_loader"
|
3
|
+
require "chef/cookbook_uploader"
|
4
|
+
require "chef/exceptions"
|
5
|
+
|
1
6
|
module Berkshelf
|
2
7
|
class Uploader
|
3
8
|
attr_reader :berksfile
|
@@ -8,13 +13,13 @@ module Berkshelf
|
|
8
13
|
def initialize(berksfile, *args)
|
9
14
|
@berksfile = berksfile
|
10
15
|
@lockfile = berksfile.lockfile
|
11
|
-
opts = args.last.respond_to?(:to_hash) ? args.pop.to_hash.
|
16
|
+
opts = args.last.respond_to?(:to_hash) ? args.pop.to_hash.each_with_object({}) { |(k, v), m| m[k.to_sym] = v } : {}
|
12
17
|
|
13
18
|
@options = {
|
14
|
-
force:
|
15
|
-
freeze:
|
19
|
+
force: false,
|
20
|
+
freeze: true,
|
16
21
|
halt_on_frozen: false,
|
17
|
-
validate:
|
22
|
+
validate: true,
|
18
23
|
}.merge(opts)
|
19
24
|
|
20
25
|
@names = Array(args).flatten
|
@@ -27,7 +32,7 @@ module Berkshelf
|
|
27
32
|
Berkshelf.log.debug " No names given, using all cookbooks"
|
28
33
|
filtered_cookbooks
|
29
34
|
else
|
30
|
-
Berkshelf.log.debug " Names given (#{names.join(
|
35
|
+
Berkshelf.log.debug " Names given (#{names.join(", ")})"
|
31
36
|
names.map { |name| lockfile.retrieve(name) }
|
32
37
|
end
|
33
38
|
|
@@ -40,77 +45,108 @@ module Berkshelf
|
|
40
45
|
|
41
46
|
private
|
42
47
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
48
|
+
# Upload the list of cookbooks to the Chef Server, with some exception
|
49
|
+
# wrapping.
|
50
|
+
#
|
51
|
+
# @param [Array<String>] cookbooks
|
52
|
+
def upload(cookbooks)
|
53
|
+
Berkshelf.log.info "Starting upload"
|
54
|
+
|
55
|
+
Berkshelf.ridley_connection(options) do |connection|
|
56
|
+
# this is a hack to work around a bug in chef 13.0-13.2 protocol negotiation on POST requests, its only
|
57
|
+
# use is to force protocol negotiation via a GET request -- it doesn't matter if it 404s. once we do not
|
58
|
+
# support those early 13.x versions this line can be safely deleted.
|
59
|
+
connection.get("users/#{Berkshelf.config.chef.node_name}") rescue nil
|
60
|
+
|
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
|
+
|
73
|
+
begin
|
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)
|
69
85
|
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
86
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
#
|
83
|
-
def filtered_cookbooks
|
84
|
-
# Create a copy of the dependencies. We need to make a copy, or else
|
85
|
-
# we would be adding dependencies directly to the Berksfile object, and
|
86
|
-
# that would be a bad idea...
|
87
|
-
dependencies = berksfile.dependencies.map(&:name)
|
88
|
-
|
89
|
-
checked = {}
|
90
|
-
cookbooks = {}
|
91
|
-
|
92
|
-
dependencies.each do |dependency|
|
93
|
-
next if checked[dependency]
|
94
|
-
|
95
|
-
lockfile.graph.find(dependency).dependencies.each do |name, _|
|
96
|
-
cookbooks[name] ||= lockfile.retrieve(name)
|
97
|
-
dependencies << name
|
87
|
+
Berkshelf.formatter.skipping(cookbook, connection)
|
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)
|
98
95
|
end
|
99
96
|
|
100
|
-
checked[dependency] = true
|
101
|
-
cookbooks[dependency] ||= lockfile.retrieve(dependency)
|
102
97
|
end
|
98
|
+
end
|
99
|
+
end
|
103
100
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
101
|
+
# Lookup dependencies in a cookbook and iterate to return dependencies of dependencies.
|
102
|
+
#
|
103
|
+
# This method is recursive. It iterates over a cookbook's dependencies
|
104
|
+
# and their dependencies in order to return an array of cookbooks, starting
|
105
|
+
# with the cookbook passed and followed by it's dependencies.
|
106
|
+
#
|
107
|
+
# @return [Array<CachedCookbook>]
|
108
|
+
#
|
109
|
+
def lookup_dependencies(cookbook, checked = {})
|
110
|
+
Berkshelf.log.debug " Looking up dependencies for #{cookbook}"
|
111
|
+
|
112
|
+
dependencies = []
|
113
|
+
|
114
|
+
lockfile.graph.find(cookbook).dependencies.each do |name, _|
|
115
|
+
next if checked[name]
|
116
|
+
|
117
|
+
# break cyclic graphs
|
118
|
+
checked[name] = true
|
119
|
+
|
120
|
+
# this is your standard depth-first tree traversal with the deps first...
|
121
|
+
dependencies += lookup_dependencies(name, checked)
|
122
|
+
# ..then the node itself
|
123
|
+
dependencies << name
|
114
124
|
end
|
125
|
+
dependencies
|
126
|
+
end
|
127
|
+
|
128
|
+
# Filter cookbooks based off the list of dependencies in the Berksfile.
|
129
|
+
#
|
130
|
+
# This method is secretly recursive. It iterates over each dependency in
|
131
|
+
# the Berksfile (using {Berksfile#dependencies} to account for filters)
|
132
|
+
# and retrieves that cookbook, it's dependencies, and the recusive
|
133
|
+
# dependencies, but iteratively.
|
134
|
+
#
|
135
|
+
# @return [Array<CachedCookbook>]
|
136
|
+
#
|
137
|
+
def filtered_cookbooks
|
138
|
+
# Create a copy of the dependencies. We need to make a copy, or else
|
139
|
+
# we would be adding dependencies directly to the Berksfile object, and
|
140
|
+
# that would be a bad idea...
|
141
|
+
dependencies = berksfile.dependencies.map(&:name)
|
142
|
+
|
143
|
+
checked = {}
|
144
|
+
cookbook_order = dependencies.map do |dependency|
|
145
|
+
# for each dep add all its deps first, then the dep itself
|
146
|
+
lookup_dependencies(dependency, checked) + [ dependency ]
|
147
|
+
end.flatten
|
148
|
+
|
149
|
+
cookbook_order.uniq.map { |dependency| lockfile.retrieve(dependency) }
|
150
|
+
end
|
115
151
|
end
|
116
152
|
end
|
data/lib/berkshelf/validator.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'chef/version_class'
|
2
|
+
|
1
3
|
module Berkshelf
|
2
4
|
module Validator
|
3
5
|
class << self
|
@@ -22,16 +24,22 @@ module Berkshelf
|
|
22
24
|
# the Cookbook(s) to validate
|
23
25
|
def validate_files(cookbooks)
|
24
26
|
Array(cookbooks).each do |cookbook|
|
25
|
-
|
27
|
+
base, name = Pathname.new(cookbook.path.to_s).split
|
26
28
|
|
27
|
-
files = Dir.glob(
|
28
|
-
|
29
|
-
f.gsub(parent, '') =~ /[[:space:]]/
|
30
|
-
end
|
29
|
+
files = Dir.glob("#{name}/**/*.rb", base: base.to_s).select { |f| f =~ /[[:space:]]/ }
|
30
|
+
validate_versions(cookbook)
|
31
31
|
|
32
32
|
raise InvalidCookbookFiles.new(cookbook, files) unless files.empty?
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
def validate_versions(cookbook)
|
37
|
+
cookbook_dependencies = cookbook.dependencies
|
38
|
+
cookbook_dependencies.each do |cookbook_name, cookbook_version|
|
39
|
+
version = cookbook_version.gsub(/[^\d,\.]/, '')
|
40
|
+
Chef::Version.new(version)
|
41
|
+
end
|
42
|
+
end
|
35
43
|
end
|
36
44
|
end
|
37
45
|
end
|
data/lib/berkshelf/version.rb
CHANGED
data/lib/berkshelf/visualizer.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
|
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
|
@@ -18,7 +18,7 @@ module Berkshelf
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
include
|
21
|
+
include Berkshelf::ShellOut
|
22
22
|
|
23
23
|
def initialize
|
24
24
|
@nodes = {}
|
@@ -56,7 +56,7 @@ module Berkshelf
|
|
56
56
|
out = %|digraph Solve__Graph {\n|
|
57
57
|
|
58
58
|
nodes.each do |node|
|
59
|
-
out <<
|
59
|
+
out << %{ "#{node}" [ fontsize = 10, label = "#{node}" ]\n}
|
60
60
|
end
|
61
61
|
|
62
62
|
nodes.each do |node|
|
@@ -67,7 +67,7 @@ module Berkshelf
|
|
67
67
|
else
|
68
68
|
label = " #{version}"
|
69
69
|
end
|
70
|
-
out <<
|
70
|
+
out << %{ "#{node}" -> "#{name}" [ fontsize = 10, label = "#{label}" ]\n}
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -76,6 +76,11 @@ module Berkshelf
|
|
76
76
|
out
|
77
77
|
end
|
78
78
|
|
79
|
+
def to_dot_file(outfile = "graph.dot")
|
80
|
+
File.open(outfile, "w") { |f| f.write(to_dot) }
|
81
|
+
File.expand_path(outfile)
|
82
|
+
end
|
83
|
+
|
79
84
|
# Save the graph visually as a PNG.
|
80
85
|
#
|
81
86
|
# @param [String] outfile
|
@@ -83,19 +88,19 @@ module Berkshelf
|
|
83
88
|
#
|
84
89
|
# @return [String]
|
85
90
|
# the path where the file was written
|
86
|
-
def to_png(outfile =
|
87
|
-
tempfile = Tempfile.new(
|
91
|
+
def to_png(outfile = "graph.png")
|
92
|
+
tempfile = Tempfile.new("dotdotfile")
|
88
93
|
tempfile.write(to_dot)
|
89
94
|
tempfile.rewind
|
90
95
|
|
91
|
-
unless Berkshelf.which(
|
96
|
+
unless Berkshelf.which("dot") || Berkshelf.which("dot.exe")
|
92
97
|
raise GraphvizNotInstalled.new
|
93
98
|
end
|
94
99
|
|
95
|
-
command =
|
100
|
+
command = %{dot -T png #{tempfile.path} -o "#{outfile}"}
|
96
101
|
response = shell_out(command)
|
97
102
|
|
98
|
-
|
103
|
+
if response.error?
|
99
104
|
raise GraphvizCommandFailed.new(command, response.stderr)
|
100
105
|
end
|
101
106
|
|
data/lib/berkshelf.rb
CHANGED
@@ -1,59 +1,77 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require
|
6
|
-
require
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
require
|
1
|
+
|
2
|
+
# XXX: work around logger spam from hashie
|
3
|
+
# https://github.com/intridea/hashie/issues/394
|
4
|
+
begin
|
5
|
+
require "hashie"
|
6
|
+
require "hashie/logger"
|
7
|
+
Hashie.logger = Logger.new(nil)
|
8
|
+
rescue LoadError
|
9
|
+
# intentionally left blank
|
10
|
+
end
|
11
|
+
|
12
|
+
require "cleanroom"
|
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
|
+
require "semverse"
|
18
|
+
require "solve"
|
19
|
+
require "thor" unless defined?(Thor)
|
20
|
+
require "uri" unless defined?(URI)
|
13
21
|
|
14
22
|
JSON.create_id = nil
|
15
23
|
|
16
|
-
require_relative
|
17
|
-
require_relative
|
24
|
+
require_relative "berkshelf/core_ext"
|
25
|
+
require_relative "berkshelf/thor_ext"
|
26
|
+
require_relative "berkshelf/chef_config_compat"
|
18
27
|
|
19
28
|
module Berkshelf
|
20
29
|
Encoding.default_external = Encoding::UTF_8
|
21
30
|
|
22
|
-
|
23
|
-
|
31
|
+
def self.fix_proxies
|
32
|
+
ENV["http_proxy"] = ENV["HTTP_PROXY"] if ENV["HTTP_PROXY"] && !ENV["http_proxy"]
|
33
|
+
ENV["https_proxy"] = ENV["HTTPS_PROXY"] if ENV["HTTPS_PROXY"] && !ENV["https_proxy"]
|
34
|
+
ENV["ftp_proxy"] = ENV["FTP_PROXY"] if ENV["FTP_PROXY"] && !ENV["ftp_proxy"]
|
35
|
+
ENV["no_proxy"] = ENV["NO_PROXY"] if ENV["NO_PROXY"] && !ENV["no_proxy"]
|
36
|
+
end
|
37
|
+
|
38
|
+
fix_proxies
|
39
|
+
|
40
|
+
require_relative "berkshelf/version"
|
41
|
+
require_relative "berkshelf/errors"
|
24
42
|
|
25
43
|
module Mixin
|
26
|
-
autoload :Git,
|
27
|
-
autoload :Logging,
|
44
|
+
autoload :Git, "berkshelf/mixin/git"
|
45
|
+
autoload :Logging, "berkshelf/mixin/logging"
|
28
46
|
end
|
29
47
|
|
30
|
-
autoload :FileSyncer,
|
31
|
-
autoload :Shell,
|
32
|
-
autoload :Uploader,
|
33
|
-
autoload :Visualizer,
|
48
|
+
autoload :FileSyncer, "berkshelf/file_syncer"
|
49
|
+
autoload :Shell, "berkshelf/shell"
|
50
|
+
autoload :Uploader, "berkshelf/uploader"
|
51
|
+
autoload :Visualizer, "berkshelf/visualizer"
|
34
52
|
|
35
|
-
autoload :BaseFormatter,
|
36
|
-
autoload :HumanFormatter,
|
37
|
-
autoload :JsonFormatter,
|
38
|
-
autoload :NullFormatter,
|
53
|
+
autoload :BaseFormatter, "berkshelf/formatters/base"
|
54
|
+
autoload :HumanFormatter, "berkshelf/formatters/human"
|
55
|
+
autoload :JsonFormatter, "berkshelf/formatters/json"
|
56
|
+
autoload :NullFormatter, "berkshelf/formatters/null"
|
39
57
|
|
40
|
-
autoload :Location,
|
41
|
-
autoload :BaseLocation,
|
42
|
-
autoload :GitLocation,
|
43
|
-
autoload :GithubLocation,
|
44
|
-
autoload :PathLocation,
|
58
|
+
autoload :Location, "berkshelf/location"
|
59
|
+
autoload :BaseLocation, "berkshelf/locations/base"
|
60
|
+
autoload :GitLocation, "berkshelf/locations/git"
|
61
|
+
autoload :GithubLocation, "berkshelf/locations/github"
|
62
|
+
autoload :PathLocation, "berkshelf/locations/path"
|
45
63
|
|
46
|
-
DEFAULT_FILENAME =
|
64
|
+
DEFAULT_FILENAME = "Berksfile".freeze
|
47
65
|
|
48
66
|
class << self
|
49
67
|
include Mixin::Logging
|
50
68
|
|
51
69
|
attr_writer :berkshelf_path
|
52
|
-
|
70
|
+
attr_writer :ui
|
53
71
|
|
54
72
|
# @return [Pathname]
|
55
73
|
def root
|
56
|
-
@root ||= Pathname.new(File.expand_path(
|
74
|
+
@root ||= Pathname.new(File.expand_path("../", File.dirname(__FILE__)))
|
57
75
|
end
|
58
76
|
|
59
77
|
# @return [Berkshelf::Shell]
|
@@ -69,7 +87,7 @@ module Berkshelf
|
|
69
87
|
#
|
70
88
|
# @return [String]
|
71
89
|
def berkshelf_path
|
72
|
-
@berkshelf_path ||= File.expand_path(ENV[
|
90
|
+
@berkshelf_path ||= File.expand_path(ENV["BERKSHELF_PATH"] || "~/.berkshelf")
|
73
91
|
end
|
74
92
|
|
75
93
|
# The Berkshelf configuration.
|
@@ -86,9 +104,9 @@ module Berkshelf
|
|
86
104
|
|
87
105
|
# The Chef configuration file.
|
88
106
|
#
|
89
|
-
# @return [
|
107
|
+
# @return [Berkshelf::ChefConfigCompat]
|
90
108
|
def chef_config
|
91
|
-
@chef_config ||=
|
109
|
+
@chef_config ||= Berkshelf::ChefConfigCompat.new(ENV["BERKSHELF_CHEF_CONFIG"])
|
92
110
|
end
|
93
111
|
|
94
112
|
# @param [Ridley::Chef::Config]
|
@@ -118,32 +136,43 @@ module Berkshelf
|
|
118
136
|
@formatter ||= HumanFormatter.new
|
119
137
|
end
|
120
138
|
|
139
|
+
def ssl_policy
|
140
|
+
@ssl_policy ||= SSLPolicy.new
|
141
|
+
end
|
142
|
+
|
121
143
|
# @raise [Berkshelf::ChefConnectionError]
|
122
144
|
def ridley_connection(options = {}, &block)
|
123
|
-
|
124
|
-
|
145
|
+
ssl_options = {}
|
146
|
+
ssl_options[:verify] = if options[:ssl_verify].nil?
|
147
|
+
Berkshelf.config.ssl.verify
|
148
|
+
else
|
149
|
+
options[:ssl_verify]
|
150
|
+
end
|
151
|
+
ssl_options[:cert_store] = ssl_policy.store if ssl_policy.store
|
152
|
+
|
153
|
+
ridley_options = {}
|
154
|
+
ridley_options[:ssl] = options[:ssl] if options.key?(:ssl)
|
125
155
|
ridley_options[:server_url] = options[:server_url] || Berkshelf.config.chef.chef_server_url
|
126
156
|
ridley_options[:client_name] = options[:client_name] || Berkshelf.config.chef.node_name
|
127
157
|
ridley_options[:client_key] = options[:client_key] || Berkshelf.config.chef.client_key
|
128
|
-
ridley_options[:ssl] =
|
158
|
+
ridley_options[:ssl] = ssl_options
|
129
159
|
|
130
|
-
|
131
|
-
raise ChefConnectionError,
|
160
|
+
if !ridley_options[:server_url] || ridley_options[:server_url] =~ /^\s*$/
|
161
|
+
raise ChefConnectionError, "Missing required attribute in your Berkshelf configuration: chef.server_url"
|
132
162
|
end
|
133
163
|
|
134
|
-
|
135
|
-
raise ChefConnectionError,
|
164
|
+
if !ridley_options[:client_name] || ridley_options[:client_name] =~ /^\s*$/
|
165
|
+
raise ChefConnectionError, "Missing required attribute in your Berkshelf configuration: chef.node_name"
|
136
166
|
end
|
137
167
|
|
138
|
-
|
139
|
-
raise ChefConnectionError,
|
168
|
+
if !ridley_options[:client_key] || ridley_options[:client_key].to_s =~ /^\s*$/
|
169
|
+
raise ChefConnectionError, "Missing required attribute in your Berkshelf configuration: chef.client_key"
|
140
170
|
end
|
141
171
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
rescue Ridley::Errors::RidleyError => ex
|
172
|
+
RidleyCompat.new_client(**ridley_options, &block)
|
173
|
+
rescue ChefConnectionError, BerkshelfError
|
174
|
+
raise
|
175
|
+
rescue => ex
|
147
176
|
log.exception(ex)
|
148
177
|
raise ChefConnectionError, ex # todo implement
|
149
178
|
end
|
@@ -168,8 +197,8 @@ module Berkshelf
|
|
168
197
|
def which(executable)
|
169
198
|
if File.file?(executable) && File.executable?(executable)
|
170
199
|
executable
|
171
|
-
elsif ENV[
|
172
|
-
path = ENV[
|
200
|
+
elsif ENV["PATH"]
|
201
|
+
path = ENV["PATH"].split(File::PATH_SEPARATOR).find do |p|
|
173
202
|
File.executable?(File.join(p, executable))
|
174
203
|
end
|
175
204
|
path && File.expand_path(executable, path)
|
@@ -178,36 +207,32 @@ module Berkshelf
|
|
178
207
|
|
179
208
|
private
|
180
209
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
end
|
210
|
+
def null_stream
|
211
|
+
@null ||= begin
|
212
|
+
strm = STDOUT.clone
|
213
|
+
strm.reopen(RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ ? "NUL:" : "/dev/null")
|
214
|
+
strm.sync = true
|
215
|
+
strm
|
188
216
|
end
|
217
|
+
end
|
189
218
|
end
|
190
219
|
end
|
191
220
|
|
192
|
-
require_relative
|
193
|
-
require_relative
|
194
|
-
require_relative
|
195
|
-
require_relative
|
196
|
-
require_relative
|
197
|
-
require_relative
|
198
|
-
require_relative
|
199
|
-
require_relative
|
200
|
-
require_relative
|
201
|
-
require_relative
|
202
|
-
require_relative
|
203
|
-
require_relative
|
204
|
-
require_relative
|
205
|
-
require_relative
|
206
|
-
require_relative
|
207
|
-
require_relative
|
208
|
-
|
209
|
-
require_relative 'berkshelf/validator'
|
210
|
-
|
211
|
-
Ridley.logger = Berkshelf.logger
|
221
|
+
require_relative "berkshelf/lockfile"
|
222
|
+
require_relative "berkshelf/berksfile"
|
223
|
+
require_relative "berkshelf/cached_cookbook"
|
224
|
+
require_relative "berkshelf/cli"
|
225
|
+
require_relative "berkshelf/community_rest"
|
226
|
+
require_relative "berkshelf/cookbook_store"
|
227
|
+
require_relative "berkshelf/config"
|
228
|
+
require_relative "berkshelf/dependency"
|
229
|
+
require_relative "berkshelf/downloader"
|
230
|
+
require_relative "berkshelf/installer"
|
231
|
+
require_relative "berkshelf/logger"
|
232
|
+
require_relative "berkshelf/resolver"
|
233
|
+
require_relative "berkshelf/source"
|
234
|
+
require_relative "berkshelf/source_uri"
|
235
|
+
require_relative "berkshelf/validator"
|
236
|
+
require_relative "berkshelf/ssl_policies"
|
237
|
+
|
212
238
|
Berkshelf.logger.level = Logger::WARN
|
213
|
-
Celluloid.logger.level = Logger::ERROR
|
data/spec/config/knife.rb
CHANGED
@@ -4,7 +4,7 @@ node_name "berkshelf"
|
|
4
4
|
client_key File.expand_path("spec/config/berkshelf.pem")
|
5
5
|
validation_client_name "validator"
|
6
6
|
validation_key File.expand_path("spec/config/validator.pem")
|
7
|
-
chef_server_url "http://
|
8
|
-
cache_type
|
9
|
-
cache_options( :
|
10
|
-
cookbook_path
|
7
|
+
chef_server_url "http://127.0.0.1:26310"
|
8
|
+
cache_type "BasicFile"
|
9
|
+
cache_options( path: "#{ENV["HOME"]}/.chef/checksums" )
|
10
|
+
cookbook_path []
|
@@ -0,0 +1,22 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDkjCCAnoCCQDihI8kxGYTFTANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMC
|
3
|
+
VVMxCzAJBgNVBAgTAldBMRAwDgYDVQQHEwdTZWF0dGxlMRAwDgYDVQQKEwdZb3VD
|
4
|
+
b3JwMRMwEQYDVQQLEwpPcGVyYXRpb25zMRYwFAYDVQQDEw1leGFtcGxlLmxvY2Fs
|
5
|
+
MR0wGwYJKoZIhvcNAQkBFg5tZUBleGFtcGxlLmNvbTAeFw0xMzEwMTcxODAxMzVa
|
6
|
+
Fw0yMzEwMTUxODAxMzVaMIGKMQswCQYDVQQGEwJVUzELMAkGA1UECBMCV0ExEDAO
|
7
|
+
BgNVBAcTB1NlYXR0bGUxEDAOBgNVBAoTB1lvdUNvcnAxEzARBgNVBAsTCk9wZXJh
|
8
|
+
dGlvbnMxFjAUBgNVBAMTDWV4YW1wbGUubG9jYWwxHTAbBgkqhkiG9w0BCQEWDm1l
|
9
|
+
QGV4YW1wbGUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyKBo
|
10
|
+
U+Bdni0xZK/NCzdLdi2X+TyW5eahbYMx+r1GDcVqCICvrthBCVLVFsQ8rvOHwTPi
|
11
|
+
AxQJGxb9TLSXRgXQSlH6FLjIUceuOtpan3qYVJ1v7AxY4DgNvYBpbtJz5MQedJnT
|
12
|
+
g2F+rXzkwaD6CWBqWHeGU0oP3r7bq1AMD6XEsK2w2/zHtG7TEnL45ARv1PsyrU5M
|
13
|
+
ZAW/XyoMyq1k2Lpv7YR5kAvTq1+4RSt/it2RFE7R0AVbaQ0MeAnllfySiHHHlaOT
|
14
|
+
FVd/qPSiGISxsUmmzA3Z08+0sfJwkrnJXbLscCBYndd7gMGgtczGjJtul0Ch3GFa
|
15
|
+
/Pn5McjwF272+usJ1wIDAQABMA0GCSqGSIb3DQEBBQUAA4IBAQCzPePWifWNECsG
|
16
|
+
nL8on1AtFMkczE1/pdRS4YUl/Tc926MpezptSja8rL31+4Bom37/wYPG7HygtAQl
|
17
|
+
R4FHpAtuqJKPOfjUmDNsIXRFnytrnflTpctDu/Nbj4PDCy01k/sTDUQt+s+lEBL8
|
18
|
+
M8ArmfLZ8PCfAwnXmJQ5rggDFKqegjt6z1RsSglbMiASE7+KkpBnzaqH6fET6IQz
|
19
|
+
WgAjv6WdRfwgfJjOTSX4XMpCSet9KaWmXExKrxiVng2Uu6E+ShVAyKaGMuc1B7VA
|
20
|
+
oxnnVaVapFv5lOWucQr4KkC7EgaUZnyt8duOc8+Yvd+y3Xd2dcHUnmegRxly4jRV
|
21
|
+
/lXbFAUb
|
22
|
+
-----END CERTIFICATE-----
|
data/spec/fixtures/Berksfile
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
cookbook
|
2
|
-
cookbook
|
3
|
-
cookbook
|
1
|
+
cookbook "ntp", "<= 1.0.0"
|
2
|
+
cookbook "mysql"
|
3
|
+
cookbook "nginx", "< 0.101.2"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
name
|
2
|
-
version
|
1
|
+
name "jenkins-config"
|
2
|
+
version "0.1.0"
|
3
3
|
|
4
|
-
depends
|
4
|
+
depends "jenkins", "~> 2.0"
|