berkshelf 0.5.0.rc2 → 0.5.0.rc3

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.
data/lib/berkshelf.rb CHANGED
@@ -6,6 +6,7 @@ require 'zlib'
6
6
  require 'archive/tar/minitar'
7
7
  require 'solve'
8
8
  require 'ridley'
9
+ require 'thor'
9
10
  require 'chef/knife'
10
11
  require 'chef/platform'
11
12
  require 'chef/cookbook/metadata'
@@ -15,6 +16,7 @@ require 'active_support/core_ext'
15
16
  require 'berkshelf/version'
16
17
  require 'berkshelf/core_ext'
17
18
  require 'berkshelf/errors'
19
+ require 'thor/monkies'
18
20
 
19
21
  Chef::Config[:cache_options][:path] = Dir.mktmpdir
20
22
 
@@ -367,6 +367,17 @@ module Berkshelf
367
367
  # @option options [Symbol, Array] :only
368
368
  # Group(s) to include which will cause any sources marked as a member of the
369
369
  # group to be installed and all others to be ignored
370
+ # @option options [Integer] :thread_count
371
+ # @option options [Hash] :params
372
+ # URI query unencoded key/value pairs
373
+ # @option options [Hash] :headers
374
+ # unencoded HTTP header key/value pairs
375
+ # @option options [Hash] :request
376
+ # request options
377
+ # @option options [Hash] :ssl
378
+ # SSL options
379
+ # @option options [URI, String, Hash] :proxy
380
+ # URI, String, or Hash of HTTP proxy options
370
381
  def upload(options = {})
371
382
  uploader = Uploader.new(options)
372
383
  solution = resolve(options)
data/lib/berkshelf/cli.rb CHANGED
@@ -1,8 +1,8 @@
1
- require 'thor'
2
- require 'thor/monkies'
3
1
  require 'berkshelf'
4
2
 
5
3
  module Berkshelf
4
+ Thor::Base.shell = Berkshelf::UI
5
+
6
6
  # @author Jamie Winsor <jamie@vialstudios.com>
7
7
  class Cli < Thor
8
8
  class << self
@@ -14,7 +14,6 @@ module Berkshelf
14
14
 
15
15
  def initialize(*args)
16
16
  super(*args)
17
- self.shell = Berkshelf.ui
18
17
  Berkshelf.config_path = @options[:config]
19
18
  Berkshelf.set_format @options[:format]
20
19
  @options = options.dup # unfreeze frozen options Hash from Thor
@@ -108,6 +107,10 @@ module Berkshelf
108
107
  type: :boolean,
109
108
  default: false,
110
109
  desc: "Upload all cookbooks even if a frozen one exists on the target Chef Server"
110
+ option :ssl_verify,
111
+ type: :boolean,
112
+ default: true,
113
+ desc: "Disable/Enable SSL verification when uploading cookbooks"
111
114
  desc "upload", "Upload the Cookbooks specified by a Berksfile or a Berksfile.lock to a Chef Server."
112
115
  def upload
113
116
  Berkshelf.load_config
@@ -117,7 +120,10 @@ module Berkshelf
117
120
  server_url: Chef::Config[:chef_server_url],
118
121
  client_name: Chef::Config[:node_name],
119
122
  client_key: Chef::Config[:client_key],
120
- organization: ChefAPILocation.extract_organization(Chef::Config[:chef_server_url])
123
+ organization: ChefAPILocation.extract_organization(Chef::Config[:chef_server_url]),
124
+ ssl: {
125
+ verify: options[:ssl_verify]
126
+ }
121
127
  )
122
128
  end
123
129
 
data/lib/berkshelf/ui.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Berkshelf
2
- class UI < Thor::Shell::Color
2
+ class UI < ::Thor::Shell::Basic
3
3
  # Mute the output of this instance of UI until {#unmute!} is called
4
4
  def mute!
5
5
  @mute = true
@@ -10,10 +10,10 @@ module Berkshelf
10
10
  @mute = false
11
11
  end
12
12
 
13
- def say(message, color = nil, force_new_line = (message.to_s !~ /( |\t)$/))
13
+ def say(message = "", color = nil, force_new_line = nil)
14
14
  return if quiet?
15
15
 
16
- super(message, color, force_new_line)
16
+ super(message, color)
17
17
  end
18
18
  alias_method :info, :say
19
19
 
@@ -17,6 +17,17 @@ module Berkshelf
17
17
  # @option options [String] :organization
18
18
  # the Organization to connect to. This is only used if you are connecting to
19
19
  # private Chef or hosted Chef
20
+ # @option options [Integer] :thread_count
21
+ # @option options [Hash] :params
22
+ # URI query unencoded key/value pairs
23
+ # @option options [Hash] :headers
24
+ # unencoded HTTP header key/value pairs
25
+ # @option options [Hash] :request
26
+ # request options
27
+ # @option options [Hash] :ssl
28
+ # SSL options
29
+ # @option options [URI, String, Hash] :proxy
30
+ # URI, String, or Hash of HTTP proxy options
20
31
  def initialize(options = {})
21
32
  @conn = Ridley.connection(options)
22
33
  end
@@ -10,6 +10,7 @@ module Berkshelf
10
10
  autoload :Upload, 'berkshelf/vagrant/action/upload'
11
11
  autoload :Clean, 'berkshelf/vagrant/action/clean'
12
12
  autoload :SetUI, 'berkshelf/vagrant/action/set_ui'
13
+ autoload :Validate, 'berkshelf/vagrant/action/validate'
13
14
  end
14
15
 
15
16
  autoload :Config, 'berkshelf/vagrant/config'
@@ -56,10 +57,13 @@ module Berkshelf
56
57
  # Initialize the Berkshelf Vagrant middleware stack
57
58
  def init!
58
59
  ::Vagrant.config_keys.register(:berkshelf) { Berkshelf::Vagrant::Config }
59
- ::Vagrant.actions[:provision].insert(::Vagrant::Action::VM::Provision, Berkshelf::Vagrant::Middleware.install)
60
- ::Vagrant.actions[:provision].insert(::Vagrant::Action::VM::Provision, Berkshelf::Vagrant::Middleware.upload)
61
- ::Vagrant.actions[:start].insert(::Vagrant::Action::VM::Provision, Berkshelf::Vagrant::Middleware.install)
62
- ::Vagrant.actions[:start].insert(::Vagrant::Action::VM::Provision, Berkshelf::Vagrant::Middleware.upload)
60
+
61
+ [ :provision, :start ].each do |action|
62
+ ::Vagrant.actions[action].insert(::Vagrant::Action::General::Validate, Berkshelf::Vagrant::Action::Validate)
63
+ ::Vagrant.actions[action].insert(::Vagrant::Action::VM::Provision, Berkshelf::Vagrant::Middleware.install)
64
+ ::Vagrant.actions[action].insert(::Vagrant::Action::VM::Provision, Berkshelf::Vagrant::Middleware.upload)
65
+ end
66
+
63
67
  ::Vagrant.actions[:destroy].insert(::Vagrant::Action::VM::CleanMachineFolder, Berkshelf::Vagrant::Middleware.clean)
64
68
  end
65
69
  end
@@ -6,16 +6,19 @@ module Berkshelf
6
6
  attr_reader :berksfile
7
7
  attr_reader :node_name
8
8
  attr_reader :client_key
9
+ attr_reader :ssl_verify
9
10
 
10
11
  def initialize(app, env)
11
12
  @app = app
12
13
  @node_name = env[:global_config].berkshelf.node_name
13
14
  @client_key = env[:global_config].berkshelf.client_key
15
+ @ssl_verify = env[:global_config].berkshelf.client_key
14
16
  @berksfile = Berksfile.from_file(env[:global_config].berkshelf.berksfile_path)
15
17
  end
16
18
 
17
19
  def call(env)
18
20
  if Berkshelf::Vagrant.chef_client?(env[:global_config])
21
+ p env[:global_config].berkshelf
19
22
  upload(env)
20
23
  end
21
24
 
@@ -28,9 +31,12 @@ module Berkshelf
28
31
  Berkshelf::Vagrant.provisioners(:chef_client, env[:global_config]).each do |provisioner|
29
32
  Berkshelf.formatter.msg "uploading cookbooks to '#{provisioner.config.chef_server_url}'"
30
33
  berksfile.upload(
31
- provisioner.config.chef_server_url,
32
- node_name: self.node_name,
33
- client_key: self.client_key
34
+ server_url: provisioner.config.chef_server_url,
35
+ client_name: self.node_name,
36
+ client_key: self.client_key,
37
+ ssl: {
38
+ verify: self.ssl_verify
39
+ }
34
40
  )
35
41
  end
36
42
  end
@@ -0,0 +1,30 @@
1
+ module Berkshelf
2
+ module Vagrant
3
+ module Action
4
+ # @author Jamie Winsor <jamie@vialstudios.com>
5
+ #
6
+ # As of Vagrant 1.0.5 it is not possible to validate configuration values of
7
+ # a configuraiton that was not explicitly described in a Vagrant::Config.run block.
8
+ #
9
+ # In our case we want some values set for our middleware stacks even if the user does
10
+ # not explicitly set values for settings in `config.berkshelf`.
11
+ class Validate
12
+ def initialize(app, env)
13
+ @app = app
14
+ end
15
+
16
+ def call(env)
17
+ recorder = ::Vagrant::Config::ErrorRecorder.new
18
+ env[:vm].config.berkshelf.validate(env[:vm].env, recorder)
19
+
20
+ unless recorder.errors.empty?
21
+ raise ::Vagrant::Errors::ConfigValidationFailed,
22
+ messages: ::Vagrant::Util::TemplateRenderer.render("config/validation_failed", errors: { berkshelf: recorder })
23
+ end
24
+
25
+ @app.call(env)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -2,20 +2,43 @@ module Berkshelf
2
2
  module Vagrant
3
3
  # @author Jamie Winsor <jamie@vialstudios.com>
4
4
  # @author Andrew Garson <andrew.garson@gmail.com>
5
+ #
6
+ # @note according to <http://vagrantup.com/v1/docs/extending/configuration.html> instance
7
+ # variables should not be instantiated with default values in the initializer of a Config file.
8
+ # Instead explicit getters which set and return the default value should be used.
5
9
  class Config < ::Vagrant::Config::Base
6
- # return [String]
10
+ # @return [String]
7
11
  # path to a knife configuration file
8
- attr_reader :config_path
12
+ def config_path
13
+ @config_path ||= Berkshelf::DEFAULT_CONFIG
14
+ end
15
+
16
+ # @param [String] value
17
+ def config_path=(value)
18
+ @config_path = File.expand_path(value)
19
+ end
9
20
 
10
21
  # @return [String]
11
22
  # path to the Berksfile to use with Vagrant
12
- attr_reader :berksfile_path
23
+ def berksfile_path
24
+ @berksfile_path ||= File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME)
25
+ end
26
+
27
+ # @param [String] value
28
+ def berksfile_path=(value)
29
+ @berksfile_path = File.expand_path(value)
30
+ end
13
31
 
14
32
  # @return [String]
15
33
  # A path to a client key on disk to use with the Chef Client provisioner to
16
34
  # upload cookbooks installed by Berkshelf.
17
35
  attr_reader :client_key
18
36
 
37
+ # @param [String] value
38
+ def client_key=(value)
39
+ @client_key = File.expand_path(value)
40
+ end
41
+
19
42
  # @return [String]
20
43
  # A client name (node_name) to use with the Chef Client provisioner to upload
21
44
  # cookbooks installed by Berkshelf.
@@ -24,31 +47,25 @@ module Berkshelf
24
47
  # @return [Array<Symbol>]
25
48
  # cookbooks in all other groups except for these will be installed
26
49
  # and copied to Vagrant's shelf
27
- attr_accessor :except
50
+ def except
51
+ @except ||= Array.new
52
+ end
53
+ attr_writer :except
28
54
 
29
55
  # @return [Array<Symbol>]
30
56
  # only cookbooks in these groups will be installed and copied to
31
57
  # Vagrant's shelf
32
- attr_accessor :only
33
-
34
- def initialize
35
- @config_path = Berkshelf::DEFAULT_CONFIG
36
- @berksfile_path = File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME)
37
- @only = Array.new
38
- @except = Array.new
39
- end
40
-
41
- def config_path=(value)
42
- @config_path = File.expand_path(value)
58
+ def only
59
+ @only ||= Array.new
43
60
  end
61
+ attr_writer :only
44
62
 
45
- def berksfile_path=(value)
46
- @berksfile_path = File.expand_path(value)
47
- end
48
-
49
- def client_key=(value)
50
- @client_key = File.expand_path(value)
63
+ # @return [Boolean]
64
+ # should connections to a Chef API use SSL verification
65
+ def ssl_verify
66
+ @ssl_verify ||= true
51
67
  end
68
+ attr_writer :ssl_verify
52
69
 
53
70
  def validate(env, errors)
54
71
  if !except.empty? && !only.empty?
@@ -1,3 +1,3 @@
1
1
  module Berkshelf
2
- VERSION = "0.5.0.rc2"
2
+ VERSION = "0.5.0.rc3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berkshelf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.rc2
4
+ version: 0.5.0.rc3
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-09-20 00:00:00.000000000 Z
15
+ date: 2012-09-21 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: ridley
@@ -514,6 +514,7 @@ files:
514
514
  - lib/berkshelf/vagrant/action/install.rb
515
515
  - lib/berkshelf/vagrant/action/set_ui.rb
516
516
  - lib/berkshelf/vagrant/action/upload.rb
517
+ - lib/berkshelf/vagrant/action/validate.rb
517
518
  - lib/berkshelf/vagrant/config.rb
518
519
  - lib/berkshelf/vagrant/middleware.rb
519
520
  - lib/berkshelf/version.rb