berkshelf 2.0.0.beta → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +19 -1
- data/CONTRIBUTING.md +1 -3
- data/Gemfile +0 -20
- data/Guardfile +3 -3
- data/LICENSE +6 -5
- data/README.md +1 -0
- data/Thorfile +48 -67
- data/berkshelf.gemspec +48 -37
- data/features/apply_command.feature +17 -11
- data/features/config.feature +11 -11
- data/features/configure_command.feature +8 -8
- data/features/contingent_command.feature +37 -8
- data/features/cookbook_command.feature +17 -14
- data/features/groups_install.feature +24 -20
- data/features/install_command.feature +24 -33
- data/features/licenses.feature +112 -0
- data/features/list_command.feature +17 -5
- data/features/lockfile.feature +307 -188
- data/features/outdated_command.feature +1 -4
- data/features/package_command.feature +41 -19
- data/features/shelf/list.feature +39 -0
- data/features/shelf/show.feature +152 -0
- data/features/shelf/uninstall.feature +103 -0
- data/features/show_command.feature +49 -17
- data/features/step_definitions/filesystem_steps.rb +12 -3
- data/features/step_definitions/utility_steps.rb +0 -1
- data/features/support/env.rb +11 -4
- data/features/update_command.feature +22 -10
- data/features/upload_command.feature +174 -127
- data/features/vendor_install.feature +6 -6
- data/generator_files/Berksfile.erb +1 -1
- data/generator_files/metadata.rb.erb +7 -7
- data/lib/berkshelf.rb +39 -27
- data/lib/berkshelf/base_generator.rb +2 -3
- data/lib/berkshelf/berksfile.rb +69 -17
- data/lib/berkshelf/cached_cookbook.rb +17 -1
- data/lib/berkshelf/chef.rb +2 -4
- data/lib/berkshelf/chef/config.rb +51 -75
- data/lib/berkshelf/chef/cookbook.rb +1 -2
- data/lib/berkshelf/chef/cookbook/chefignore.rb +1 -1
- data/lib/berkshelf/cli.rb +144 -194
- data/lib/berkshelf/command.rb +11 -12
- data/lib/berkshelf/commands/shelf.rb +130 -0
- data/lib/berkshelf/commands/test_command.rb +11 -0
- data/lib/berkshelf/community_rest.rb +1 -2
- data/lib/berkshelf/config.rb +14 -10
- data/lib/berkshelf/cookbook_generator.rb +30 -24
- data/lib/berkshelf/cookbook_source.rb +1 -1
- data/lib/berkshelf/cookbook_store.rb +0 -1
- data/lib/berkshelf/core_ext.rb +1 -1
- data/lib/berkshelf/core_ext/file.rb +1 -1
- data/lib/berkshelf/downloader.rb +3 -1
- data/lib/berkshelf/errors.rb +128 -53
- data/lib/berkshelf/formatters.rb +2 -6
- data/lib/berkshelf/formatters/human_readable.rb +8 -2
- data/lib/berkshelf/formatters/json.rb +7 -1
- data/lib/berkshelf/formatters/null.rb +0 -1
- data/lib/berkshelf/git.rb +16 -16
- data/lib/berkshelf/init_generator.rb +28 -26
- data/lib/berkshelf/location.rb +12 -11
- data/lib/berkshelf/locations/chef_api_location.rb +2 -2
- data/lib/berkshelf/locations/git_location.rb +0 -1
- data/lib/berkshelf/locations/github_location.rb +0 -1
- data/lib/berkshelf/locations/path_location.rb +1 -2
- data/lib/berkshelf/locations/site_location.rb +3 -2
- data/lib/berkshelf/lockfile.rb +29 -10
- data/lib/berkshelf/mixin/config.rb +155 -0
- data/lib/berkshelf/mixin/logging.rb +0 -1
- data/lib/berkshelf/mixin/shellout.rb +71 -0
- data/lib/berkshelf/resolver.rb +7 -4
- data/lib/berkshelf/test.rb +1 -3
- data/lib/berkshelf/ui.rb +8 -4
- data/lib/berkshelf/version.rb +1 -1
- data/lib/thor/monkies/shell.rb +0 -1
- data/spec/config/berkshelf.pem +27 -0
- data/spec/config/knife.rb +12 -0
- data/spec/config/validator.pem +27 -0
- data/spec/spec_helper.rb +4 -8
- data/spec/support/chef_api.rb +14 -9
- data/spec/support/chef_server.rb +3 -4
- data/spec/unit/berkshelf/berksfile_spec.rb +1 -1
- data/spec/unit/berkshelf/cookbook_generator_spec.rb +12 -6
- data/spec/unit/berkshelf/cookbook_source_spec.rb +13 -1
- data/spec/unit/berkshelf/init_generator_spec.rb +5 -0
- data/spec/unit/chef/config_spec.rb +9 -10
- metadata +216 -93
- data/features/info_command.feature +0 -39
- data/features/open_command.feature +0 -36
- data/lib/berkshelf/cli_commands/test_command.rb +0 -11
- data/lib/berkshelf/mixin.rb +0 -10
- data/lib/berkshelf/mixin/path_helpers.rb +0 -30
- data/spec/support/knife.rb +0 -18
@@ -1,19 +1,19 @@
|
|
1
|
-
Feature:
|
1
|
+
Feature: Vendoring cookbooks to a specific path
|
2
2
|
As a user of Berkshelf
|
3
3
|
I want to be able to install cookbooks to a specific directory
|
4
4
|
So I vendor my cookbooks and package them with my application
|
5
5
|
|
6
|
-
Scenario:
|
6
|
+
Scenario: With a path option
|
7
|
+
Given the cookbook store has the cookbooks:
|
8
|
+
| fake | 1.0.0 |
|
7
9
|
Given I write to "Berksfile" with:
|
8
10
|
"""
|
9
11
|
site :opscode
|
10
|
-
cookbook '
|
12
|
+
cookbook 'fake', '1.0.0'
|
11
13
|
"""
|
12
14
|
When I run the install command with flags:
|
13
15
|
| --path vendor/cookbooks |
|
14
|
-
Then the cookbook store should have the cookbooks:
|
15
|
-
| berkshelf-cookbook-fixture | 1.0.0 |
|
16
16
|
Then the following directories should exist:
|
17
17
|
| vendor/cookbooks |
|
18
|
-
| vendor/cookbooks/
|
18
|
+
| vendor/cookbooks/fake |
|
19
19
|
And the exit status should be 0
|
@@ -1,12 +1,12 @@
|
|
1
|
-
name
|
2
|
-
maintainer
|
3
|
-
maintainer_email
|
4
|
-
license
|
5
|
-
description
|
1
|
+
name '<%= name %>'
|
2
|
+
maintainer '<%= maintainer %>'
|
3
|
+
maintainer_email '<%= maintainer_email %>'
|
4
|
+
license '<%= license_name %>'
|
5
|
+
description 'Installs/Configures <%= name %>'
|
6
6
|
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
7
7
|
<% if options[:scmversion] -%>
|
8
|
-
version IO.read(File.join(File.dirname(__FILE__), 'VERSION')) rescue
|
8
|
+
version IO.read(File.join(File.dirname(__FILE__), 'VERSION')) rescue '0.1.0'
|
9
9
|
<% else -%>
|
10
|
-
version
|
10
|
+
version '0.1.0'
|
11
11
|
<% end -%>
|
12
12
|
|
data/lib/berkshelf.rb
CHANGED
@@ -2,6 +2,7 @@ require 'active_support/core_ext'
|
|
2
2
|
require 'archive/tar/minitar'
|
3
3
|
require 'celluloid'
|
4
4
|
require 'chozo/core_ext'
|
5
|
+
require 'digest/md5'
|
5
6
|
require 'forwardable'
|
6
7
|
require 'hashie'
|
7
8
|
require 'json'
|
@@ -15,8 +16,6 @@ require 'zlib'
|
|
15
16
|
|
16
17
|
require 'berkshelf/core_ext'
|
17
18
|
require 'berkshelf/errors'
|
18
|
-
require 'berkshelf/test' if ENV['RUBY_ENV'] == 'test'
|
19
|
-
require 'berkshelf/version'
|
20
19
|
require 'thor/monkies'
|
21
20
|
|
22
21
|
JSON.create_id = nil
|
@@ -24,28 +23,8 @@ JSON.create_id = nil
|
|
24
23
|
module Berkshelf
|
25
24
|
DEFAULT_FILENAME = 'Berksfile'.freeze
|
26
25
|
|
27
|
-
autoload :BaseGenerator, 'berkshelf/base_generator'
|
28
|
-
autoload :Berksfile, 'berkshelf/berksfile'
|
29
|
-
autoload :CachedCookbook, 'berkshelf/cached_cookbook'
|
30
|
-
autoload :Chef, 'berkshelf/chef'
|
31
|
-
autoload :Cli, 'berkshelf/cli'
|
32
|
-
autoload :CommunityREST, 'berkshelf/community_rest'
|
33
|
-
autoload :Config, 'berkshelf/config'
|
34
|
-
autoload :CookbookGenerator, 'berkshelf/cookbook_generator'
|
35
|
-
autoload :CookbookSource, 'berkshelf/cookbook_source'
|
36
|
-
autoload :CookbookStore, 'berkshelf/cookbook_store'
|
37
|
-
autoload :Downloader, 'berkshelf/downloader'
|
38
|
-
autoload :Git, 'berkshelf/git'
|
39
|
-
autoload :InitGenerator, 'berkshelf/init_generator'
|
40
|
-
autoload :Lockfile, 'berkshelf/lockfile'
|
41
|
-
autoload :Logger, 'berkshelf/logger'
|
42
|
-
autoload :Mixin, 'berkshelf/mixin'
|
43
|
-
autoload :Resolver, 'berkshelf/resolver'
|
44
|
-
autoload :UI, 'berkshelf/ui'
|
45
|
-
|
46
|
-
require 'berkshelf/location'
|
47
|
-
|
48
26
|
class << self
|
27
|
+
require 'berkshelf/mixin/logging'
|
49
28
|
include Berkshelf::Mixin::Logging
|
50
29
|
|
51
30
|
attr_accessor :ui
|
@@ -70,9 +49,22 @@ module Berkshelf
|
|
70
49
|
#
|
71
50
|
# @return [String]
|
72
51
|
def berkshelf_path
|
73
|
-
ENV[
|
52
|
+
ENV['BERKSHELF_PATH'] || File.expand_path('~/.berkshelf')
|
53
|
+
end
|
54
|
+
|
55
|
+
# The Chef configuration file.
|
56
|
+
#
|
57
|
+
# @return [Berkshelf::Chef::Config]
|
58
|
+
def chef_config
|
59
|
+
@chef_config ||= Berkshelf::Chef::Config.load
|
74
60
|
end
|
75
61
|
|
62
|
+
# Set the Chef configuration file.
|
63
|
+
#
|
64
|
+
# @param [Berkshelf::Chef::Config] new_config
|
65
|
+
# the new configuration file to use
|
66
|
+
attr_writer :chef_config
|
67
|
+
|
76
68
|
# @return [Logger]
|
77
69
|
def logger
|
78
70
|
Celluloid.logger
|
@@ -80,7 +72,7 @@ module Berkshelf
|
|
80
72
|
|
81
73
|
# @return [String]
|
82
74
|
def tmp_dir
|
83
|
-
File.join(berkshelf_path,
|
75
|
+
File.join(berkshelf_path, 'tmp')
|
84
76
|
end
|
85
77
|
|
86
78
|
# Creates a temporary directory within the Berkshelf path
|
@@ -93,7 +85,7 @@ module Berkshelf
|
|
93
85
|
end
|
94
86
|
|
95
87
|
def cookbooks_dir
|
96
|
-
File.join(berkshelf_path,
|
88
|
+
File.join(berkshelf_path, 'cookbooks')
|
97
89
|
end
|
98
90
|
|
99
91
|
# @return [Berkshelf::CookbookStore]
|
@@ -149,4 +141,24 @@ module Berkshelf
|
|
149
141
|
end
|
150
142
|
end
|
151
143
|
|
152
|
-
|
144
|
+
require_relative 'berkshelf/base_generator'
|
145
|
+
require_relative 'berkshelf/berksfile'
|
146
|
+
require_relative 'berkshelf/cached_cookbook'
|
147
|
+
require_relative 'berkshelf/chef'
|
148
|
+
require_relative 'berkshelf/cli'
|
149
|
+
require_relative 'berkshelf/community_rest'
|
150
|
+
require_relative 'berkshelf/cookbook_generator'
|
151
|
+
require_relative 'berkshelf/cookbook_source'
|
152
|
+
require_relative 'berkshelf/cookbook_store'
|
153
|
+
require_relative 'berkshelf/config'
|
154
|
+
require_relative 'berkshelf/downloader'
|
155
|
+
require_relative 'berkshelf/formatters'
|
156
|
+
require_relative 'berkshelf/git'
|
157
|
+
require_relative 'berkshelf/init_generator'
|
158
|
+
require_relative 'berkshelf/location'
|
159
|
+
require_relative 'berkshelf/lockfile'
|
160
|
+
require_relative 'berkshelf/logger'
|
161
|
+
require_relative 'berkshelf/resolver'
|
162
|
+
require_relative 'berkshelf/test' if ENV['RUBY_ENV'] == 'test'
|
163
|
+
require_relative 'berkshelf/ui'
|
164
|
+
require_relative 'berkshelf/version'
|
@@ -1,11 +1,10 @@
|
|
1
1
|
require 'thor/group'
|
2
2
|
|
3
3
|
module Berkshelf
|
4
|
-
# @author Jamie Winsor <reset@riotgames.com>
|
5
4
|
class BaseGenerator < Thor::Group
|
6
5
|
class << self
|
7
6
|
def source_root
|
8
|
-
Berkshelf.root.join(
|
7
|
+
Berkshelf.root.join('generator_files')
|
9
8
|
end
|
10
9
|
end
|
11
10
|
|
@@ -18,7 +17,7 @@ module Berkshelf
|
|
18
17
|
include Thor::Actions
|
19
18
|
|
20
19
|
private
|
21
|
-
|
20
|
+
|
22
21
|
def target
|
23
22
|
@target ||= Pathname.new(File.expand_path(path))
|
24
23
|
end
|
data/lib/berkshelf/berksfile.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
module Berkshelf
|
2
|
-
# @author Jamie Winsor <reset@riotgames.com>
|
3
2
|
class Berksfile
|
4
|
-
|
3
|
+
require 'berkshelf/mixin/logging'
|
5
4
|
include Berkshelf::Mixin::Logging
|
6
5
|
|
6
|
+
extend Forwardable
|
7
|
+
|
7
8
|
class << self
|
8
9
|
# @param [String] file
|
9
10
|
# a path on disk to a Berksfile to instantiate from
|
@@ -39,12 +40,12 @@ module Berkshelf
|
|
39
40
|
end
|
40
41
|
|
41
42
|
cookbooks.each do |cb|
|
42
|
-
dest = File.join(scratch, cb.cookbook_name,
|
43
|
+
dest = File.join(scratch, cb.cookbook_name, '/')
|
43
44
|
FileUtils.mkdir_p(dest)
|
44
45
|
|
45
46
|
# Dir.glob does not support backslash as a File separator
|
46
47
|
src = cb.path.to_s.gsub('\\', '/')
|
47
|
-
files = Dir.glob(File.join(src,
|
48
|
+
files = Dir.glob(File.join(src, '*'))
|
48
49
|
|
49
50
|
# Filter out files using chefignore
|
50
51
|
files = chefignore.remove_ignores_from(files) if chefignore
|
@@ -235,8 +236,8 @@ module Berkshelf
|
|
235
236
|
# chef_api :config
|
236
237
|
#
|
237
238
|
# @example using a URL, node_name, and client_key to add a Chef API default location
|
238
|
-
# chef_api
|
239
|
-
# client_key:
|
239
|
+
# chef_api 'https://api.opscode.com/organizations/vialstudios', node_name: 'reset',
|
240
|
+
# client_key: '/Users/reset/.chef/knife.rb'
|
240
241
|
#
|
241
242
|
# @param [String, Symbol] value
|
242
243
|
# @param [Hash] options
|
@@ -317,10 +318,10 @@ module Berkshelf
|
|
317
318
|
|
318
319
|
case
|
319
320
|
when !except.empty? && !only.empty?
|
320
|
-
raise Berkshelf::ArgumentError,
|
321
|
+
raise Berkshelf::ArgumentError, 'Cannot specify both :except and :only'
|
321
322
|
when !cookbooks.empty?
|
322
323
|
if !except.empty? && !only.empty?
|
323
|
-
Berkshelf.ui.warn
|
324
|
+
Berkshelf.ui.warn 'Cookbooks were specified, ignoring :except and :only'
|
324
325
|
end
|
325
326
|
l_sources.select { |source| cookbooks.include?(source.name) }
|
326
327
|
when !except.empty?
|
@@ -349,11 +350,11 @@ module Berkshelf
|
|
349
350
|
# Example:
|
350
351
|
# {
|
351
352
|
# nautilus: [
|
352
|
-
# #<Berkshelf::CookbookSource
|
353
|
-
# #<Berkshelf::CookbookSource
|
353
|
+
# #<Berkshelf::CookbookSource: nginx (~> 1.0.0)>,
|
354
|
+
# #<Berkshelf::CookbookSource: mysql (~> 1.2.4)>
|
354
355
|
# ],
|
355
356
|
# skarner: [
|
356
|
-
# #<Berkshelf::CookbookSource
|
357
|
+
# #<Berkshelf::CookbookSource: nginx (~> 1.0.0)>
|
357
358
|
# ]
|
358
359
|
# }
|
359
360
|
def groups
|
@@ -430,6 +431,8 @@ module Berkshelf
|
|
430
431
|
@cached_cookbooks = resolver[:solution]
|
431
432
|
local_sources = resolver[:sources]
|
432
433
|
|
434
|
+
verify_licenses!
|
435
|
+
|
433
436
|
self.class.vendor(@cached_cookbooks, options[:path]) if options[:path]
|
434
437
|
|
435
438
|
lockfile.update(local_sources, sha: self.sha)
|
@@ -475,7 +478,7 @@ module Berkshelf
|
|
475
478
|
#
|
476
479
|
# @example
|
477
480
|
# berksfile.outdated => {
|
478
|
-
#
|
481
|
+
# #<CachedCookbook name="artifact"> => "0.11.2"
|
479
482
|
# }
|
480
483
|
def outdated(options = {})
|
481
484
|
outdated = Hash.new
|
@@ -537,6 +540,8 @@ module Berkshelf
|
|
537
540
|
solution.each do |cb|
|
538
541
|
Berkshelf.formatter.upload(cb.cookbook_name, cb.version, conn.server_url)
|
539
542
|
|
543
|
+
validate_files!(cb)
|
544
|
+
|
540
545
|
begin
|
541
546
|
conn.cookbook.upload(cb.path, upload_opts.merge(name: cb.cookbook_name))
|
542
547
|
rescue Ridley::Errors::FrozenCookbook => ex
|
@@ -580,7 +585,7 @@ module Berkshelf
|
|
580
585
|
install
|
581
586
|
|
582
587
|
environment.cookbook_versions = {}.tap do |cookbook_versions|
|
583
|
-
lockfile.sources.each { |source| cookbook_versions[source.name] = source.locked_version }
|
588
|
+
lockfile.sources.each { |source| cookbook_versions[source.name] = source.locked_version.to_s }
|
584
589
|
end
|
585
590
|
|
586
591
|
environment.save
|
@@ -628,6 +633,10 @@ module Berkshelf
|
|
628
633
|
}
|
629
634
|
end
|
630
635
|
|
636
|
+
package.each do |cookbook|
|
637
|
+
validate_files!(cookbook)
|
638
|
+
end
|
639
|
+
|
631
640
|
Dir.mktmpdir do |tmp|
|
632
641
|
package.each do |cached_cookbook|
|
633
642
|
path = cached_cookbook.path.to_s
|
@@ -687,7 +696,7 @@ module Berkshelf
|
|
687
696
|
begin
|
688
697
|
instance_eval(content)
|
689
698
|
rescue => e
|
690
|
-
raise BerksfileReadError.new(e)
|
699
|
+
raise BerksfileReadError.new(e)
|
691
700
|
end
|
692
701
|
self
|
693
702
|
end
|
@@ -713,15 +722,15 @@ module Berkshelf
|
|
713
722
|
ridley_options[:ssl] = { verify: (options[:ssl_verify] || Berkshelf::Config.instance.ssl.verify) }
|
714
723
|
|
715
724
|
unless ridley_options[:server_url].present?
|
716
|
-
raise ChefConnectionError,
|
725
|
+
raise ChefConnectionError, 'Missing required attribute in your Berkshelf configuration: chef.server_url'
|
717
726
|
end
|
718
727
|
|
719
728
|
unless ridley_options[:client_name].present?
|
720
|
-
raise ChefConnectionError,
|
729
|
+
raise ChefConnectionError, 'Missing required attribute in your Berkshelf configuration: chef.node_name'
|
721
730
|
end
|
722
731
|
|
723
732
|
unless ridley_options[:client_key].present?
|
724
|
-
raise ChefConnectionError,
|
733
|
+
raise ChefConnectionError, 'Missing required attribute in your Berkshelf configuration: chef.client_key'
|
725
734
|
end
|
726
735
|
|
727
736
|
Ridley.new(ridley_options)
|
@@ -787,5 +796,48 @@ module Berkshelf
|
|
787
796
|
locked_source.version_constraint = source.version_constraint
|
788
797
|
locked_source
|
789
798
|
end
|
799
|
+
|
800
|
+
# Validate that the given cookbook does not have "bad" files. Currently
|
801
|
+
# this means including spaces in filenames (such as recipes)
|
802
|
+
#
|
803
|
+
# @param [Berkshelf::CachedCookbook] cookbook
|
804
|
+
# the Cookbook to validate
|
805
|
+
def validate_files!(cookbook)
|
806
|
+
path = cookbook.path.to_s
|
807
|
+
|
808
|
+
files = Dir.glob(File.join(path, '**', '*.rb')).select do |f|
|
809
|
+
f =~ /[[:space:]]/
|
810
|
+
end
|
811
|
+
|
812
|
+
raise Berkshelf::InvalidCookbookFiles.new(cookbook, files) unless files.empty?
|
813
|
+
end
|
814
|
+
|
815
|
+
# Verify that the licenses of all the cached cookbooks fall in the realm of
|
816
|
+
# allowed licenses from the Berkshelf Config.
|
817
|
+
#
|
818
|
+
# @raise [Berkshelf::LicenseNotAllowed]
|
819
|
+
# if the license is not permitted and `raise_license_exception` is true
|
820
|
+
def verify_licenses!
|
821
|
+
licenses = Array(Berkshelf::Config.instance.allowed_licenses)
|
822
|
+
return if licenses.empty?
|
823
|
+
|
824
|
+
sources.each do |source|
|
825
|
+
next if source.location.is_a?(Berkshelf::PathLocation)
|
826
|
+
cached = source.cached_cookbook
|
827
|
+
|
828
|
+
begin
|
829
|
+
unless licenses.include?(cached.metadata.license)
|
830
|
+
raise Berkshelf::LicenseNotAllowed.new(cached)
|
831
|
+
end
|
832
|
+
rescue Berkshelf::LicenseNotAllowed => e
|
833
|
+
if Berkshelf::Config.instance.raise_license_exception
|
834
|
+
FileUtils.rm_rf(cached.path)
|
835
|
+
raise
|
836
|
+
end
|
837
|
+
|
838
|
+
Berkshelf.ui.warn(e.to_s)
|
839
|
+
end
|
840
|
+
end
|
841
|
+
end
|
790
842
|
end
|
791
843
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
module Berkshelf
|
2
|
-
# @author Jamie Winsor <reset@riotgames.com>
|
3
2
|
class CachedCookbook < Ridley::Chef::Cookbook
|
4
3
|
class << self
|
5
4
|
# @param [#to_s] path
|
@@ -37,6 +36,23 @@ module Berkshelf
|
|
37
36
|
end.join("\n")
|
38
37
|
end
|
39
38
|
|
39
|
+
def pretty_json
|
40
|
+
pretty_hash.to_json
|
41
|
+
end
|
42
|
+
|
43
|
+
def pretty_hash
|
44
|
+
{}.tap do |h|
|
45
|
+
h[:name] = cookbook_name unless name.blank?
|
46
|
+
h[:version] = version unless version.blank?
|
47
|
+
h[:description] = metadata.description unless metadata.description.blank?
|
48
|
+
h[:author] = metadata.maintainer unless metadata.maintainer.blank?
|
49
|
+
h[:email] = metadata.maintainer_email unless metadata.maintainer_email.blank?
|
50
|
+
h[:license] = metadata.license unless metadata.license.blank?
|
51
|
+
h[:platforms] = metadata.platforms.to_hash unless metadata.platforms.blank?
|
52
|
+
h[:dependencies] = dependencies.to_hash unless dependencies.blank?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
40
56
|
private
|
41
57
|
def pretty_map(hash, padding)
|
42
58
|
hash.map { |k,v| "#{k} (#{v})" }.join("\n" + ' '*padding)
|
data/lib/berkshelf/chef.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
module Berkshelf
|
2
|
-
# @author Jamie Winsor <reset@riotgames.com>
|
3
|
-
#
|
4
2
|
# Classes and modules used for integrating with a Chef Server, the Chef community
|
5
3
|
# site, and Chef Cookbooks
|
6
4
|
module Chef
|
7
|
-
|
8
|
-
|
5
|
+
require_relative 'chef/config'
|
6
|
+
require_relative 'chef/cookbook'
|
9
7
|
end
|
10
8
|
end
|
@@ -1,91 +1,67 @@
|
|
1
1
|
require 'socket'
|
2
|
-
require 'tmpdir'
|
3
|
-
require 'berkshelf/mixin'
|
4
|
-
require 'mixlib/config'
|
5
2
|
|
6
|
-
module Berkshelf
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
class << self
|
12
|
-
# Load and return a Chef::Config for Berkshelf. The location of the configuration to be loaded
|
13
|
-
# can be configured by setting a value for {Berkshelf::Chef::Config.path=}
|
14
|
-
#
|
15
|
-
# @return [Berkshelf::Chef::Config]
|
16
|
-
def instance
|
17
|
-
@instance ||= begin
|
18
|
-
self.from_file(File.expand_path(path))
|
19
|
-
self
|
20
|
-
rescue
|
21
|
-
self
|
22
|
-
end
|
23
|
-
end
|
3
|
+
module Berkshelf
|
4
|
+
module Chef
|
5
|
+
class Config
|
6
|
+
require 'berkshelf/mixin/config'
|
7
|
+
include Berkshelf::Mixin::Config
|
24
8
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
9
|
+
class << self
|
10
|
+
private
|
11
|
+
# Return the most sensible path to the Chef configuration file. This can
|
12
|
+
# be configured by setting a value for the 'BERKSHELF_CHEF_CONFIG' environment
|
13
|
+
# variable.
|
14
|
+
#
|
15
|
+
# @return [String, nil]
|
16
|
+
def location
|
17
|
+
possibles = []
|
32
18
|
|
33
|
-
|
34
|
-
|
35
|
-
|
19
|
+
possibles << ENV['BERKSHELF_CHEF_CONFIG'] if ENV['BERKSHELF_CHEF_CONFIG']
|
20
|
+
possibles << File.join(ENV['KNIFE_HOME'], 'knife.rb') if ENV['KNIFE_HOME']
|
21
|
+
possibles << File.join(working_dir, 'knife.rb') if working_dir
|
36
22
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
23
|
+
# Ascending search for .chef directory siblings
|
24
|
+
Pathname.new(working_dir).ascend do |file|
|
25
|
+
sibling_chef = File.join(file, '.chef')
|
26
|
+
possibles << File.join(sibling_chef, 'knife.rb')
|
27
|
+
end if working_dir
|
42
28
|
|
43
|
-
|
44
|
-
|
29
|
+
possibles << File.join(ENV['HOME'], '.chef', 'knife.rb') if ENV['HOME']
|
30
|
+
possibles.compact!
|
45
31
|
|
46
|
-
|
32
|
+
location = possibles.find { |loc| File.exists?(File.expand_path(loc)) }
|
47
33
|
|
48
|
-
|
49
|
-
|
50
|
-
end
|
34
|
+
File.expand_path(location) unless location.nil?
|
35
|
+
end
|
51
36
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
37
|
+
# The current working directory
|
38
|
+
#
|
39
|
+
# @return [String]
|
40
|
+
def working_dir
|
41
|
+
ENV['PWD'] || Dir.pwd
|
42
|
+
end
|
58
43
|
end
|
59
44
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
45
|
+
default_option(:node_name, Socket.gethostname)
|
46
|
+
default_option(:chef_server_url, 'http://localhost:4000')
|
47
|
+
default_option(:client_key, platform_specific_path('/etc/chef/client.pem'))
|
48
|
+
default_option(:validation_key, platform_specific_path('/etc/chef/validation.pem'))
|
49
|
+
default_option(:validation_client_name, 'chef-validator')
|
66
50
|
|
67
|
-
|
68
|
-
|
51
|
+
default_option(:cookbook_copyright, 'YOUR_NAME')
|
52
|
+
default_option(:cookbook_email, 'YOUR_EMAIL')
|
53
|
+
default_option(:cookbook_license, 'reserved')
|
69
54
|
|
70
|
-
|
71
|
-
chef_server_url "http://localhost:4000"
|
72
|
-
client_key platform_specific_path("/etc/chef/client.pem")
|
73
|
-
validation_key platform_specific_path("/etc/chef/validation.pem")
|
74
|
-
validation_client_name "chef-validator"
|
55
|
+
default_option(:knife, {})
|
75
56
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
# configs will have `cache_options[:path]`. `cache_options` is marked
|
86
|
-
# deprecated in chef/config.rb but doesn't currently trigger a warning.
|
87
|
-
# See also: CHEF-3715
|
88
|
-
syntax_check_cache_path Dir.mktmpdir
|
89
|
-
cache_options path: syntax_check_cache_path
|
57
|
+
# Prior to Chef 11, the cache implementation was based on
|
58
|
+
# moneta and configured via cache_options[:path]. Knife configs
|
59
|
+
# generated with Chef 11 will have `syntax_check_cache_path`, but older
|
60
|
+
# configs will have `cache_options[:path]`. `cache_options` is marked
|
61
|
+
# deprecated in chef/config.rb but doesn't currently trigger a warning.
|
62
|
+
# See also: CHEF-3715
|
63
|
+
default_option(:syntax_check_cache_path, Dir.mktmpdir)
|
64
|
+
default_option(:cache_options, { path: defined?(syntax_check_cache_path) ? syntax_check_cache_path : Dir.mktmpdir })
|
65
|
+
end
|
90
66
|
end
|
91
67
|
end
|