chef 0.10.0.beta.2 → 0.10.0.beta.3

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.
@@ -84,7 +84,7 @@ class Chef
84
84
  output = edit_item(item)
85
85
  rest.put_rest("data/#{@name_args[0]}/#{@name_args[1]}", output)
86
86
  stdout.puts("Saved data_bag_item[#{@name_args[1]}]")
87
- output(format_for_display(object)) if config[:print_after]
87
+ output(format_for_display(object.raw_data)) if config[:print_after]
88
88
  end
89
89
  end
90
90
  end
@@ -58,21 +58,21 @@ class Chef
58
58
 
59
59
  def run
60
60
  display = case @name_args.length
61
- when 2
62
- if use_encryption
63
- raw = Chef::EncryptedDataBagItem.load(@name_args[0],
64
- @name_args[1],
65
- read_secret)
66
- format_for_display(raw.to_hash)
67
- else
68
- format_for_display(Chef::DataBagItem.load(@name_args[0], @name_args[1]))
69
- end
70
- when 1
71
- format_list_for_display(Chef::DataBag.load(@name_args[0]))
72
- else
73
- stdout.puts opt_parser
74
- exit(1)
75
- end
61
+ when 2
62
+ if use_encryption
63
+ raw = Chef::EncryptedDataBagItem.load(@name_args[0],
64
+ @name_args[1],
65
+ read_secret)
66
+ format_for_display(raw.to_hash)
67
+ else
68
+ format_for_display(Chef::DataBagItem.load(@name_args[0], @name_args[1]).raw_data)
69
+ end
70
+ when 1
71
+ format_list_for_display(Chef::DataBag.load(@name_args[0]))
72
+ else
73
+ stdout.puts opt_parser
74
+ exit(1)
75
+ end
76
76
  output(display)
77
77
  end
78
78
  end
@@ -114,9 +114,7 @@ class Chef
114
114
  config[:with_uri] ? list : list.keys.sort { |a,b| a <=> b }
115
115
  end
116
116
 
117
- def format_for_display(item)
118
- data = item.kind_of?(Chef::DataBagItem) ? item.raw_data : item
119
-
117
+ def format_for_display(data)
120
118
  if config[:attribute]
121
119
  config[:attribute].split(".").each do |attr|
122
120
  if data.respond_to?(:[])
@@ -127,12 +125,12 @@ class Chef
127
125
  data = data.send(attr.to_sym)
128
126
  end
129
127
  end
130
- { config[:attribute] => data.kind_of?(Chef::Node::Attribute) ? data.to_hash : data }
128
+ { config[:attribute] => data.respond_to?(:to_hash) ? data.to_hash : data }
131
129
  elsif config[:run_list]
132
130
  data = data.run_list.run_list
133
131
  { "run_list" => data }
134
132
  elsif config[:environment]
135
- if data.class == Chef::Node
133
+ if data.respond_to?(:chef_environment)
136
134
  {"chef_environment" => data.chef_environment}
137
135
  else
138
136
  # this is a place holder for now. Feel free to modify (i.e. add other cases). [nuo]
@@ -118,6 +118,7 @@ class Chef
118
118
  args[:ignore_failure] ||= false
119
119
  args[:output_on_failure] ||= false
120
120
 
121
+ # TODO: This is the wrong place for this responsibility.
121
122
  if args.has_key?(:creates)
122
123
  if File.exists?(args[:creates])
123
124
  Chef::Log.debug("Skipping #{args[:command]} - creates #{args[:creates]} exists.")
@@ -18,7 +18,11 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
- require 'win32/open3'
21
+ if RUBY_VERSION =~ /^1\.8/
22
+ require 'win32/open3'
23
+ else
24
+ require 'open3'
25
+ end
22
26
 
23
27
  class Chef
24
28
  module Mixin
@@ -6,9 +6,9 @@
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
8
8
  # You may obtain a copy of the License at
9
- #
9
+ #
10
10
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
  # Unless required by applicable law or agreed to in writing, software
13
13
  # distributed under the License is distributed on an "AS IS" BASIS,
14
14
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,16 +20,18 @@ require 'chef/shell_out'
20
20
  class Chef
21
21
  module Mixin
22
22
  module ShellOut
23
-
23
+
24
24
  def shell_out(*command_args)
25
25
  cmd = Chef::ShellOut.new(*command_args)
26
+ if STDOUT.tty? && !Chef::Config[:daemon] && Chef::Log.info?
27
+ cmd.live_stream ||= STDOUT
28
+ end
26
29
  cmd.run_command
27
30
  cmd
28
31
  end
29
-
32
+
30
33
  def shell_out!(*command_args)
31
- cmd = Chef::ShellOut.new(*command_args)
32
- cmd.run_command
34
+ cmd= shell_out(*command_args)
33
35
  cmd.error!
34
36
  cmd
35
37
  end
@@ -6,9 +6,9 @@
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
8
8
  # You may obtain a copy of the License at
9
- #
9
+ #
10
10
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
  # Unless required by applicable law or agreed to in writing, software
13
13
  # distributed under the License is distributed on an "AS IS" BASIS,
14
14
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,43 +16,45 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/mixin/command'
19
+ require 'chef/mixin/shell_out'
20
20
  require 'chef/log'
21
21
  require 'chef/provider'
22
22
 
23
23
  class Chef
24
24
  class Provider
25
25
  class Execute < Chef::Provider
26
-
27
- include Chef::Mixin::Command
28
-
26
+
27
+ include Chef::Mixin::ShellOut
28
+
29
29
  def load_current_resource
30
30
  true
31
31
  end
32
-
32
+
33
33
  def action_run
34
- command_args = {
35
- :command => @new_resource.command,
36
- :command_string => @new_resource.to_s,
37
- }
38
- command_args[:creates] = @new_resource.creates if @new_resource.creates
39
- command_args[:only_if] = @new_resource.only_if if @new_resource.only_if
40
- command_args[:not_if] = @new_resource.not_if if @new_resource.not_if
41
- command_args[:timeout] = @new_resource.timeout if @new_resource.timeout
42
- command_args[:returns] = @new_resource.returns if @new_resource.returns
43
- command_args[:environment] = @new_resource.environment if @new_resource.environment
44
- command_args[:user] = @new_resource.user if @new_resource.user
45
- command_args[:group] = @new_resource.group if @new_resource.group
46
- command_args[:cwd] = @new_resource.cwd if @new_resource.cwd
47
- command_args[:umask] = @new_resource.umask if @new_resource.umask
48
-
49
- status = run_command(command_args)
50
- if status
51
- @new_resource.updated_by_last_action(true)
52
- Chef::Log.info("Ran #{@new_resource} successfully")
34
+ opts = {}
35
+
36
+ if sentinel_file = @new_resource.creates
37
+ if File.exists?(sentinel_file)
38
+ Chef::Log.info("Skipping #{self} - sentinel file #{sentinel_file} exists.")
39
+ return false
40
+ end
53
41
  end
42
+
43
+ # original implementation did not specify a timeout, but ShellOut
44
+ # *always* times out. So, set a very long default timeout
45
+ opts[:timeout] = @new_resource.timeout || 3600
46
+ opts[:returns] = @new_resource.returns if @new_resource.returns
47
+ opts[:environment] = @new_resource.environment if @new_resource.environment
48
+ opts[:user] = @new_resource.user if @new_resource.user
49
+ opts[:group] = @new_resource.group if @new_resource.group
50
+ opts[:cwd] = @new_resource.cwd if @new_resource.cwd
51
+ opts[:umask] = @new_resource.umask if @new_resource.umask
52
+
53
+ result = shell_out!(@new_resource.command, opts)
54
+ @new_resource.updated_by_last_action(true)
55
+ Chef::Log.info("Ran #{@new_resource} successfully")
54
56
  end
55
-
57
+
56
58
  end
57
59
  end
58
60
  end
@@ -19,14 +19,14 @@
19
19
 
20
20
  require 'chef/log'
21
21
  require 'chef/provider'
22
- require 'chef/mixin/command'
22
+ require 'chef/mixin/shell_out'
23
23
  require 'fileutils'
24
24
 
25
25
  class Chef
26
26
  class Provider
27
27
  class Git < Chef::Provider
28
28
 
29
- include Chef::Mixin::Command
29
+ include Chef::Mixin::ShellOut
30
30
 
31
31
  def load_current_resource
32
32
  @current_resource = Chef::Resource::Git.new(@new_resource.name)
@@ -91,12 +91,8 @@ class Chef
91
91
 
92
92
  def find_current_revision
93
93
  if ::File.exist?(::File.join(cwd, ".git"))
94
- status, result, error_message = output_of_command("git rev-parse HEAD", run_options(:cwd=>cwd))
95
-
96
94
  # 128 is returned when we're not in a git repo. this is fine
97
- unless [0,128].include?(status.exitstatus)
98
- handle_command_failures(status, "STDOUT: #{result}\nSTDERR: #{error_message}")
99
- end
95
+ result = shell_out!('git rev-parse HEAD', :cwd => cwd, :returns => [0,128]).stdout.strip
100
96
  end
101
97
  sha_hash?(result) ? result : nil
102
98
  end
@@ -111,21 +107,21 @@ class Chef
111
107
  Chef::Log.info "Cloning repo #{@new_resource.repository} to #{@new_resource.destination}"
112
108
 
113
109
  clone_cmd = "git clone #{args.join(' ')} #{@new_resource.repository} #{@new_resource.destination}"
114
- run_command(run_options(:command => clone_cmd))
110
+ shell_out!(clone_cmd, run_options)
115
111
  end
116
112
 
117
113
  def checkout
118
114
  sha_ref = target_revision
119
115
  Chef::Log.info "Checking out branch: #{@new_resource.revision} reference: #{sha_ref}"
120
116
  # checkout into a local branch rather than a detached HEAD
121
- run_command(run_options(:command => "git checkout -b deploy #{sha_ref}", :cwd => @new_resource.destination))
117
+ shell_out!("git checkout -b deploy #{sha_ref}", run_options(:cwd => @new_resource.destination))
122
118
  end
123
119
 
124
120
  def enable_submodules
125
121
  if @new_resource.enable_submodules
126
122
  Chef::Log.info "Enabling git submodules"
127
123
  command = "git submodule init && git submodule update"
128
- run_command(run_options(:command => command, :cwd => @new_resource.destination))
124
+ shell_out!(command, run_options(:cwd => @new_resource.destination))
129
125
  end
130
126
  end
131
127
 
@@ -135,7 +131,7 @@ class Chef
135
131
  # since we're in a local branch already, just reset to specified revision rather than merge
136
132
  fetch_command = "git fetch #{@new_resource.remote} && git fetch #{@new_resource.remote} --tags && git reset --hard #{target_revision}"
137
133
  Chef::Log.debug "Fetching updates from #{new_resource.remote} and resetting to revison #{target_revision}"
138
- run_command(run_options(:command => fetch_command, :cwd => @new_resource.destination))
134
+ shell_out!(fetch_command, run_options(:cwd => @new_resource.destination))
139
135
  end
140
136
 
141
137
  # Use git-config to setup a remote tracking branches. Could use
@@ -151,7 +147,7 @@ class Chef
151
147
  "at remote #{@new_resource.remote}"
152
148
  command << "git config remote.#{@new_resource.remote}.url #{@new_resource.repository}"
153
149
  command << "git config remote.#{@new_resource.remote}.fetch +refs/heads/*:refs/remotes/#{@new_resource.remote}/*"
154
- run_command(run_options(:command => command.join(" && "), :cwd => @new_resource.destination))
150
+ shell_out!(command.join(" && "), run_options(:cwd => @new_resource.destination))
155
151
  end
156
152
 
157
153
  def current_revision_matches_target_revision?
@@ -175,17 +171,7 @@ class Chef
175
171
 
176
172
  def remote_resolve_reference
177
173
  command = git('ls-remote', @new_resource.repository, @new_resource.revision)
178
- Chef::Log.debug("Executing #{command}")
179
- begin
180
- status, result, error_message = output_of_command(command, run_options)
181
- handle_command_failures(status, "STDOUT: #{result}\nSTDERR: #{error_message}")
182
- rescue Chef::Exceptions::Exec => e
183
- msg = "Could not access the remote Git repository. If this is a private repository, "
184
- msg << "verify that the deploy key for your application has been added to your remote Git account.\n"
185
- msg << e.message
186
- raise Chef::Exceptions::Exec, msg
187
- end
188
- result
174
+ shell_out!(command, run_options).stdout
189
175
  end
190
176
 
191
177
  private
@@ -31,6 +31,7 @@ class Chef
31
31
  alias :branch :revision
32
32
  alias :reference :revision
33
33
 
34
+ alias :repo :repository
34
35
  end
35
36
  end
36
37
  end
@@ -169,8 +169,7 @@ class Chef
169
169
  # * Chef::Exceptions::CommandTimeout when the command does not complete
170
170
  # within +timeout+ seconds (default: 60s)
171
171
  def run_command
172
- # Implemented by unix/windows backend module, we just want to define it
173
- # here for documentation purposes
172
+ Chef::Log.info("sh(#{@command})")
174
173
  super
175
174
  end
176
175
 
@@ -14,7 +14,6 @@ class Chef
14
14
  # * Chef::Exceptions::CommandTimeout when the command does not complete
15
15
  # within +timeout+ seconds (default: 60s)
16
16
  def run_command
17
- Chef::Log.debug("sh(#{@command})")
18
17
  @child_pid = fork_subprocess
19
18
 
20
19
  configure_parent_process_file_descriptors
@@ -17,7 +17,11 @@
17
17
  #
18
18
 
19
19
  require 'timeout'
20
- require 'win32/open3'
20
+ if RUBY_VERSION =~ /^1\.8/
21
+ require 'win32/open3'
22
+ else
23
+ require 'open3'
24
+ end
21
25
 
22
26
  class Chef
23
27
  class ShellOut
@@ -27,7 +31,6 @@ class Chef
27
31
  # Missing lots of features from the UNIX version, such as
28
32
  # environment, cwd, etc.
29
33
  def run_command
30
- Chef::Log.debug("sh(#{@command})")
31
34
  # win32 open4 is really just open3.
32
35
  Open3.popen3(@command) do |stdin,stdout,stderr|
33
36
  @finished_stdout = false
@@ -17,7 +17,7 @@
17
17
 
18
18
  class Chef
19
19
  CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
20
- VERSION = '0.10.0.beta.2'
20
+ VERSION = '0.10.0.beta.3'
21
21
  end
22
22
 
23
23
  # NOTE: the Chef::Version class is defined in version_class.rb
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: chef
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 7
5
- version: 0.10.0.beta.2
5
+ version: 0.10.0.beta.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Adam Jacob