berkshelf 5.2.0 → 8.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (216) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +19 -47
  3. data/Rakefile +14 -4
  4. data/berkshelf.gemspec +61 -40
  5. data/bin/berks +2 -2
  6. data/lib/berkshelf/api-client.rb +1 -0
  7. data/lib/berkshelf/api_client/chef_server_connection.rb +29 -0
  8. data/lib/berkshelf/api_client/connection.rb +57 -0
  9. data/lib/berkshelf/api_client/errors.rb +10 -0
  10. data/lib/berkshelf/api_client/remote_cookbook.rb +56 -0
  11. data/lib/berkshelf/api_client/version.rb +5 -0
  12. data/lib/berkshelf/api_client.rb +24 -0
  13. data/lib/berkshelf/berksfile.rb +149 -122
  14. data/lib/berkshelf/cached_cookbook.rb +127 -24
  15. data/lib/berkshelf/chef_config_compat.rb +51 -0
  16. data/lib/berkshelf/chef_repo_universe.rb +47 -0
  17. data/lib/berkshelf/cli.rb +143 -174
  18. data/lib/berkshelf/commands/shelf.rb +20 -19
  19. data/lib/berkshelf/community_rest.rb +59 -94
  20. data/lib/berkshelf/config.rb +97 -127
  21. data/lib/berkshelf/cookbook_store.rb +7 -6
  22. data/lib/berkshelf/core_ext/file.rb +1 -1
  23. data/lib/berkshelf/core_ext/file_utils.rb +4 -4
  24. data/lib/berkshelf/core_ext.rb +1 -1
  25. data/lib/berkshelf/dependency.rb +25 -32
  26. data/lib/berkshelf/downloader.rb +66 -39
  27. data/lib/berkshelf/errors.rb +23 -17
  28. data/lib/berkshelf/file_syncer.rb +24 -47
  29. data/lib/berkshelf/formatters/human.rb +7 -5
  30. data/lib/berkshelf/formatters/json.rb +6 -6
  31. data/lib/berkshelf/installer.rb +120 -111
  32. data/lib/berkshelf/location.rb +14 -14
  33. data/lib/berkshelf/locations/base.rb +1 -1
  34. data/lib/berkshelf/locations/git.rb +16 -24
  35. data/lib/berkshelf/locations/github.rb +2 -2
  36. data/lib/berkshelf/locations/path.rb +2 -2
  37. data/lib/berkshelf/lockfile.rb +326 -328
  38. data/lib/berkshelf/logger.rb +64 -1
  39. data/lib/berkshelf/mixin/git.rb +6 -5
  40. data/lib/berkshelf/packager.rb +44 -10
  41. data/lib/berkshelf/resolver/graph.rb +1 -1
  42. data/lib/berkshelf/resolver.rb +4 -4
  43. data/lib/berkshelf/ridley_compat.rb +109 -0
  44. data/lib/berkshelf/shell.rb +2 -1
  45. data/lib/berkshelf/shell_out.rb +18 -0
  46. data/lib/berkshelf/source.rb +77 -33
  47. data/lib/berkshelf/source_uri.rb +4 -4
  48. data/lib/berkshelf/ssl_policies.rb +38 -0
  49. data/lib/berkshelf/thor.rb +1 -1
  50. data/lib/berkshelf/thor_ext/hash_with_indifferent_access.rb +1 -1
  51. data/lib/berkshelf/thor_ext.rb +1 -1
  52. data/lib/berkshelf/uploader.rb +106 -70
  53. data/lib/berkshelf/validator.rb +13 -5
  54. data/lib/berkshelf/version.rb +1 -1
  55. data/lib/berkshelf/visualizer.rb +16 -11
  56. data/lib/berkshelf.rb +106 -81
  57. data/spec/config/knife.rb +4 -4
  58. data/spec/data/trusted_certs/example.crt +22 -0
  59. data/spec/fixtures/Berksfile +3 -3
  60. data/spec/fixtures/complex-cookbook-path/cookbooks/app/metadata.rb +2 -0
  61. data/spec/fixtures/complex-cookbook-path/cookbooks/jenkins/metadata.rb +2 -0
  62. data/spec/fixtures/complex-cookbook-path/cookbooks/jenkins-config/metadata.rb +4 -0
  63. data/spec/fixtures/cookbook-path/jenkins-config/metadata.rb +3 -3
  64. data/spec/fixtures/cookbook-path-uploader/apt-2.3.6/metadata.rb +2 -0
  65. data/spec/fixtures/cookbook-path-uploader/build-essential-1.4.2/metadata.rb +2 -0
  66. data/spec/fixtures/cookbook-path-uploader/jenkins-2.0.3/metadata.rb +5 -0
  67. data/spec/fixtures/cookbook-path-uploader/jenkins-config-0.1.0/metadata.rb +4 -0
  68. data/spec/fixtures/cookbook-path-uploader/runit-1.5.8/metadata.rb +5 -0
  69. data/spec/fixtures/cookbook-path-uploader/yum-3.0.6/metadata.rb +2 -0
  70. data/spec/fixtures/cookbook-path-uploader/yum-epel-0.2.0/metadata.rb +3 -0
  71. data/spec/fixtures/cookbook-store/jenkins-2.0.3/metadata.rb +5 -5
  72. data/spec/fixtures/cookbook-store/jenkins-2.0.4/metadata.rb +4 -4
  73. data/spec/fixtures/cookbooks/example_cookbook/metadata.rb +3 -3
  74. data/spec/fixtures/cookbooks/example_cookbook-0.5.0/metadata.rb +3 -3
  75. data/spec/spec_helper.rb +56 -64
  76. data/spec/support/chef_api.rb +15 -16
  77. data/spec/support/chef_server.rb +71 -69
  78. data/spec/support/git.rb +59 -58
  79. data/spec/support/kitchen.rb +0 -14
  80. data/spec/support/matchers/file_system_matchers.rb +4 -5
  81. data/spec/support/matchers/filepath_matchers.rb +2 -2
  82. data/spec/support/path_helpers.rb +17 -17
  83. data/spec/support/shared_examples/formatter.rb +1 -1
  84. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/attributes/default.rb +0 -0
  85. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/files/default/file.h +0 -0
  86. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/metadata.rb +2 -0
  87. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/recipes/default.rb +0 -0
  88. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/templates/default/template.erb +0 -0
  89. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/attributes/default.rb +0 -0
  90. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/files/default/file.h +0 -0
  91. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/metadata.rb +2 -0
  92. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/recipes/default.rb +0 -0
  93. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/templates/default/template.erb +0 -0
  94. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/attributes/default.rb +0 -0
  95. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/files/default/file.h +0 -0
  96. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/metadata.rb +2 -0
  97. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/recipes/default.rb +0 -0
  98. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/templates/default/template.erb +0 -0
  99. data/spec/unit/berkshelf/berksfile_spec.rb +84 -105
  100. data/spec/unit/berkshelf/berkshelf/api_client/chef_server_connection_spec.rb +65 -0
  101. data/spec/unit/berkshelf/berkshelf/api_client/connection_spec.rb +157 -0
  102. data/spec/unit/berkshelf/berkshelf/api_client/remote_cookbook_spec.rb +23 -0
  103. data/spec/unit/berkshelf/berkshelf/api_client_spec.rb +9 -0
  104. data/spec/unit/berkshelf/cached_cookbook_spec.rb +45 -47
  105. data/spec/unit/berkshelf/chef_repo_universe_spec.rb +37 -0
  106. data/spec/unit/berkshelf/cli_spec.rb +7 -8
  107. data/spec/unit/berkshelf/community_rest_spec.rb +82 -90
  108. data/spec/unit/berkshelf/config_spec.rb +51 -22
  109. data/spec/unit/berkshelf/cookbook_store_spec.rb +41 -41
  110. data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +7 -8
  111. data/spec/unit/berkshelf/core_ext/pathname_spec.rb +1 -1
  112. data/spec/unit/berkshelf/dependency_spec.rb +48 -48
  113. data/spec/unit/berkshelf/downloader_spec.rb +191 -34
  114. data/spec/unit/berkshelf/errors_spec.rb +3 -3
  115. data/spec/unit/berkshelf/file_syncer_spec.rb +87 -87
  116. data/spec/unit/berkshelf/formatters/base_spec.rb +23 -23
  117. data/spec/unit/berkshelf/formatters/human_spec.rb +2 -2
  118. data/spec/unit/berkshelf/formatters/json_spec.rb +2 -2
  119. data/spec/unit/berkshelf/formatters/null_spec.rb +3 -3
  120. data/spec/unit/berkshelf/installer_spec.rb +8 -8
  121. data/spec/unit/berkshelf/location_spec.rb +11 -11
  122. data/spec/unit/berkshelf/locations/base_spec.rb +35 -36
  123. data/spec/unit/berkshelf/locations/git_spec.rb +90 -93
  124. data/spec/unit/berkshelf/locations/path_spec.rb +40 -41
  125. data/spec/unit/berkshelf/lockfile_parser_spec.rb +71 -71
  126. data/spec/unit/berkshelf/lockfile_spec.rb +205 -211
  127. data/spec/unit/berkshelf/logger_spec.rb +3 -3
  128. data/spec/unit/berkshelf/mixin/logging_spec.rb +5 -5
  129. data/spec/unit/berkshelf/packager_spec.rb +2 -2
  130. data/spec/unit/berkshelf/resolver/graph_spec.rb +10 -8
  131. data/spec/unit/berkshelf/resolver_spec.rb +17 -17
  132. data/spec/unit/berkshelf/ridley_compat_spec.rb +16 -0
  133. data/spec/unit/berkshelf/shell_spec.rb +34 -34
  134. data/spec/unit/berkshelf/source_spec.rb +186 -20
  135. data/spec/unit/berkshelf/source_uri_spec.rb +1 -1
  136. data/spec/unit/berkshelf/ssl_policies_spec.rb +86 -0
  137. data/spec/unit/berkshelf/uploader_spec.rb +146 -64
  138. data/spec/unit/berkshelf/validator_spec.rb +23 -16
  139. data/spec/unit/berkshelf/visualizer_spec.rb +24 -15
  140. data/spec/unit/berkshelf_spec.rb +18 -18
  141. metadata +138 -289
  142. data/.gitignore +0 -29
  143. data/.travis.yml +0 -64
  144. data/CHANGELOG.legacy.md +0 -307
  145. data/CHANGELOG.md +0 -1358
  146. data/CONTRIBUTING.md +0 -64
  147. data/Gemfile.lock +0 -399
  148. data/Guardfile +0 -23
  149. data/PLUGINS.md +0 -25
  150. data/README.md +0 -70
  151. data/Thorfile +0 -61
  152. data/appveyor.yml +0 -31
  153. data/docs/berkshelf_for_newcomers.md +0 -65
  154. data/features/berksfile.feature +0 -46
  155. data/features/commands/apply.feature +0 -41
  156. data/features/commands/contingent.feature +0 -48
  157. data/features/commands/cookbook.feature +0 -35
  158. data/features/commands/info.feature +0 -99
  159. data/features/commands/init.feature +0 -27
  160. data/features/commands/install.feature +0 -636
  161. data/features/commands/list.feature +0 -78
  162. data/features/commands/outdated.feature +0 -130
  163. data/features/commands/package.feature +0 -17
  164. data/features/commands/search.feature +0 -17
  165. data/features/commands/shelf/list.feature +0 -32
  166. data/features/commands/shelf/show.feature +0 -143
  167. data/features/commands/shelf/uninstall.feature +0 -96
  168. data/features/commands/show.feature +0 -83
  169. data/features/commands/update.feature +0 -142
  170. data/features/commands/upload.feature +0 -426
  171. data/features/commands/vendor.feature +0 -111
  172. data/features/commands/verify.feature +0 -29
  173. data/features/commands/viz.feature +0 -66
  174. data/features/community_site.feature +0 -37
  175. data/features/config.feature +0 -111
  176. data/features/help.feature +0 -11
  177. data/features/json_formatter.feature +0 -161
  178. data/features/lifecycle.feature +0 -378
  179. data/features/lockfile.feature +0 -378
  180. data/features/step_definitions/berksfile_steps.rb +0 -39
  181. data/features/step_definitions/chef/config_steps.rb +0 -12
  182. data/features/step_definitions/chef_server_steps.rb +0 -60
  183. data/features/step_definitions/cli_steps.rb +0 -18
  184. data/features/step_definitions/config_steps.rb +0 -46
  185. data/features/step_definitions/environment_steps.rb +0 -7
  186. data/features/step_definitions/filesystem_steps.rb +0 -269
  187. data/features/step_definitions/gem_steps.rb +0 -13
  188. data/features/step_definitions/json_steps.rb +0 -23
  189. data/features/step_definitions/utility_steps.rb +0 -11
  190. data/features/support/aruba.rb +0 -12
  191. data/features/support/env.rb +0 -82
  192. data/generator_files/Berksfile.erb +0 -11
  193. data/generator_files/CHANGELOG.md.erb +0 -3
  194. data/generator_files/Gemfile.erb +0 -8
  195. data/generator_files/README.md.erb +0 -42
  196. data/generator_files/Thorfile.erb +0 -11
  197. data/generator_files/Vagrantfile.erb +0 -117
  198. data/generator_files/chefignore +0 -94
  199. data/generator_files/default_recipe.erb +0 -6
  200. data/generator_files/default_test.rb.erb +0 -11
  201. data/generator_files/gitignore.erb +0 -23
  202. data/generator_files/helpers.rb.erb +0 -7
  203. data/generator_files/licenses/apachev2.erb +0 -13
  204. data/generator_files/licenses/gplv2.erb +0 -15
  205. data/generator_files/licenses/gplv3.erb +0 -14
  206. data/generator_files/licenses/mit.erb +0 -20
  207. data/generator_files/licenses/reserved.erb +0 -3
  208. data/generator_files/metadata.rb.erb +0 -11
  209. data/lib/berkshelf/base_generator.rb +0 -43
  210. data/lib/berkshelf/commands/test_command.rb +0 -13
  211. data/lib/berkshelf/cookbook_generator.rb +0 -133
  212. data/lib/berkshelf/init_generator.rb +0 -195
  213. data/spec/fixtures/cookbooks/example_cookbook/.gitignore +0 -2
  214. data/spec/fixtures/cookbooks/example_cookbook/.kitchen.yml +0 -26
  215. data/spec/unit/berkshelf/cookbook_generator_spec.rb +0 -110
  216. data/spec/unit/berkshelf/init_generator_spec.rb +0 -263
@@ -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.symbolize_keys : {}
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: false,
15
- freeze: true,
19
+ force: false,
20
+ freeze: true,
16
21
  halt_on_frozen: false,
17
- validate: true,
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
- # Upload the list of cookbooks to the Chef Server, with some exception
44
- # wrapping.
45
- #
46
- # @param [Array<String>] cookbooks
47
- def upload(cookbooks)
48
- Berkshelf.log.info "Starting upload"
49
-
50
- Berkshelf.ridley_connection(options) do |connection|
51
- cookbooks.each do |cookbook|
52
- Berkshelf.log.debug " Uploading #{cookbook}"
53
-
54
- begin
55
- connection.cookbook.upload(cookbook.path,
56
- name: cookbook.cookbook_name,
57
- force: options[:force],
58
- freeze: options[:freeze],
59
- validate: options[:validate],
60
- )
61
-
62
- Berkshelf.formatter.uploaded(cookbook, connection)
63
- rescue Ridley::Errors::FrozenCookbook
64
- if options[:halt_on_frozen]
65
- raise FrozenCookbook.new(cookbook)
66
- end
67
-
68
- Berkshelf.formatter.skipping(cookbook, connection)
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
- # Filter cookbooks based off the list of dependencies in the Berksfile.
75
- #
76
- # This method is secretly recursive. It iterates over each dependency in
77
- # the Berksfile (using {Berksfile#dependencies} to account for filters)
78
- # and retrieves that cookbook, it's dependencies, and the recusive
79
- # dependencies, but iteratively.
80
- #
81
- # @return [Array<CachedCookbook>]
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
- # This is a temporary change and will be removed in a future release. We should
105
- # add the ability to define a custom uploader which would allow the authors of Chef-Guard
106
- # to define their upload strategy instead of using Ridley.
107
- #
108
- # See https://github.com/berkshelf/berkshelf/pull/1316 for details.
109
- if Berkshelf.chef_config.knife[:chef_guard] == true
110
- cookbooks.values
111
- else
112
- cookbooks.values.sort
113
- end
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
@@ -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
- path = cookbook.path.to_s
27
+ base, name = Pathname.new(cookbook.path.to_s).split
26
28
 
27
- files = Dir.glob(File.join(path, '**', '*.rb')).select do |f|
28
- parent = Pathname.new(path).dirname.to_s
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
@@ -1,3 +1,3 @@
1
1
  module Berkshelf
2
- VERSION = "5.2.0"
2
+ VERSION = "8.0.15".freeze
3
3
  end
@@ -1,6 +1,6 @@
1
- require 'buff/shell_out'
2
- require 'set'
3
- require 'tempfile'
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 Buff::ShellOut
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 << %| "#{node}" [ fontsize = 10, label = "#{node}" ]\n|
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 << %| "#{node}" -> "#{name}" [ fontsize = 10, label = "#{label}" ]\n|
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 = 'graph.png')
87
- tempfile = Tempfile.new('dotdotfile')
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('dot') || Berkshelf.which('dot.exe')
96
+ unless Berkshelf.which("dot") || Berkshelf.which("dot.exe")
92
97
  raise GraphvizNotInstalled.new
93
98
  end
94
99
 
95
- command = %|dot -T png #{tempfile.path} -o "#{outfile}"|
100
+ command = %{dot -T png #{tempfile.path} -o "#{outfile}"}
96
101
  response = shell_out(command)
97
102
 
98
- unless response.success?
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
- require 'buff/extensions'
2
- require 'cleanroom'
3
- require 'digest/md5'
4
- require 'forwardable'
5
- require 'json'
6
- require 'pathname'
7
- require 'ridley'
8
- require 'semverse'
9
- require 'solve'
10
- require 'thor'
11
- require 'uri'
12
- require 'celluloid'
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 'berkshelf/core_ext'
17
- require_relative 'berkshelf/thor_ext'
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
- require_relative 'berkshelf/version'
23
- require_relative 'berkshelf/errors'
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, 'berkshelf/mixin/git'
27
- autoload :Logging, 'berkshelf/mixin/logging'
44
+ autoload :Git, "berkshelf/mixin/git"
45
+ autoload :Logging, "berkshelf/mixin/logging"
28
46
  end
29
47
 
30
- autoload :FileSyncer, 'berkshelf/file_syncer'
31
- autoload :Shell, 'berkshelf/shell'
32
- autoload :Uploader, 'berkshelf/uploader'
33
- autoload :Visualizer, 'berkshelf/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, 'berkshelf/formatters/base'
36
- autoload :HumanFormatter, 'berkshelf/formatters/human'
37
- autoload :JsonFormatter, 'berkshelf/formatters/json'
38
- autoload :NullFormatter, 'berkshelf/formatters/null'
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, 'berkshelf/location'
41
- autoload :BaseLocation, 'berkshelf/locations/base'
42
- autoload :GitLocation, 'berkshelf/locations/git'
43
- autoload :GithubLocation, 'berkshelf/locations/github'
44
- autoload :PathLocation, 'berkshelf/locations/path'
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 = 'Berksfile'.freeze
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
- attr_accessor :ui
70
+ attr_writer :ui
53
71
 
54
72
  # @return [Pathname]
55
73
  def root
56
- @root ||= Pathname.new(File.expand_path('../', File.dirname(__FILE__)))
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['BERKSHELF_PATH'] || '~/.berkshelf')
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 [Ridley::Chef::Config]
107
+ # @return [Berkshelf::ChefConfigCompat]
90
108
  def chef_config
91
- @chef_config ||= Ridley::Chef::Config.new(ENV['BERKSHELF_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
- ridley_options = options.slice(:ssl)
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] = { verify: (options[:ssl_verify].nil?) ? Berkshelf.config.ssl.verify : options[:ssl_verify]}
158
+ ridley_options[:ssl] = ssl_options
129
159
 
130
- unless ridley_options[:server_url].present?
131
- raise ChefConnectionError, 'Missing required attribute in your Berkshelf configuration: chef.server_url'
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
- unless ridley_options[:client_name].present?
135
- raise ChefConnectionError, 'Missing required attribute in your Berkshelf configuration: chef.node_name'
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
- unless ridley_options[:client_key].present?
139
- raise ChefConnectionError, 'Missing required attribute in your Berkshelf configuration: chef.client_key'
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
- # @todo Something scary going on here - getting an instance of Kitchen::Logger from test-kitchen
143
- # https://github.com/opscode/test-kitchen/blob/master/lib/kitchen.rb#L99
144
- Celluloid.logger = nil unless ENV["DEBUG_CELLULOID"]
145
- Ridley.open(ridley_options, &block)
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['PATH']
172
- path = ENV['PATH'].split(File::PATH_SEPARATOR).find do |p|
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
- def null_stream
182
- @null ||= begin
183
- strm = STDOUT.clone
184
- strm.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
185
- strm.sync = true
186
- strm
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 'berkshelf/lockfile'
193
- require_relative 'berkshelf/base_generator'
194
- require_relative 'berkshelf/berksfile'
195
- require_relative 'berkshelf/cached_cookbook'
196
- require_relative 'berkshelf/cli'
197
- require_relative 'berkshelf/community_rest'
198
- require_relative 'berkshelf/cookbook_generator'
199
- require_relative 'berkshelf/cookbook_store'
200
- require_relative 'berkshelf/config'
201
- require_relative 'berkshelf/dependency'
202
- require_relative 'berkshelf/downloader'
203
- require_relative 'berkshelf/init_generator'
204
- require_relative 'berkshelf/installer'
205
- require_relative 'berkshelf/logger'
206
- require_relative 'berkshelf/resolver'
207
- require_relative 'berkshelf/source'
208
- require_relative 'berkshelf/source_uri'
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://localhost:26310"
8
- cache_type 'BasicFile'
9
- cache_options( :path => "#{ENV['HOME']}/.chef/checksums" )
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-----
@@ -1,3 +1,3 @@
1
- cookbook 'ntp', '<= 1.0.0'
2
- cookbook 'mysql'
3
- cookbook 'nginx', '< 0.101.2'
1
+ cookbook "ntp", "<= 1.0.0"
2
+ cookbook "mysql"
3
+ cookbook "nginx", "< 0.101.2"
@@ -0,0 +1,2 @@
1
+ name "app"
2
+ version "1.2.3"
@@ -0,0 +1,2 @@
1
+ name "jenkins"
2
+ version "2.0.1"
@@ -0,0 +1,4 @@
1
+ name "jenkins-config"
2
+ version "0.1.0"
3
+
4
+ depends "jenkins", "~> 2.0"
@@ -1,4 +1,4 @@
1
- name 'jenkins-config'
2
- version '0.1.0'
1
+ name "jenkins-config"
2
+ version "0.1.0"
3
3
 
4
- depends 'jenkins', '~> 2.0'
4
+ depends "jenkins", "~> 2.0"
@@ -0,0 +1,2 @@
1
+ name "apt"
2
+ version "2.3.6"