chef-config 12.6.0 → 12.7.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
2
+ # Copyright:: Copyright 2015-2016, Chef Software, Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,8 +15,8 @@
15
15
  # limitations under the License.
16
16
  #
17
17
 
18
- require 'chef-config/windows'
19
- require 'chef-config/logger'
18
+ require "chef-config/windows"
19
+ require "chef-config/logger"
20
20
 
21
21
  module ChefConfig
22
22
 
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
2
+ # Copyright:: Copyright 2015-2016, Chef Software, Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,7 +15,6 @@
15
15
  # limitations under the License.
16
16
  #
17
17
 
18
-
19
18
  module ChefConfig
20
19
 
21
20
  # Implements enough of Logger's API that we can use it in place of a real
@@ -58,5 +57,3 @@ module ChefConfig
58
57
  @logger
59
58
  end
60
59
  end
61
-
62
-
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Kartik Null Cating-Subramanian (<ksubramanian@chef.io>)
3
- # Copyright:: Copyright (c) 2015 Chef, Inc.
3
+ # Copyright:: Copyright 2015-2016, Chef, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,9 +16,9 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'rake'
20
- require 'rubygems'
21
- require 'rubygems/package_task'
19
+ require "rake"
20
+ require "rubygems"
21
+ require "rubygems/package_task"
22
22
 
23
23
  module ChefConfig
24
24
  class PackageTask < Rake::TaskLib
@@ -47,10 +47,6 @@ module ChefConfig
47
47
  @module_path || module_name.downcase
48
48
  end
49
49
 
50
- # Path to a VERSION file with a single string that contains the package version.
51
- # By default, this is root_path/VERSION
52
- attr_accessor :version_file_path
53
-
54
50
  # Directory used to store package files and output that is generated.
55
51
  # This has the same meaning (or lack thereof) as package_dir in
56
52
  # rake/packagetask.
@@ -59,7 +55,7 @@ module ChefConfig
59
55
  # Name of git remote used to push tags during a release. Default is origin.
60
56
  attr_accessor :git_remote
61
57
 
62
- def initialize(root_path=nil, module_name=nil)
58
+ def initialize(root_path = nil, module_name = nil)
63
59
  init(root_path, module_name)
64
60
  yield self if block_given?
65
61
  define unless root_path.nil? || module_name.nil?
@@ -70,22 +66,25 @@ module ChefConfig
70
66
  @module_name = module_name
71
67
  @component_paths = []
72
68
  @module_path = nil
73
- @version_file_path = 'VERSION'
74
- @package_dir = 'pkg'
75
- @git_remote = 'origin'
69
+ @package_dir = "pkg"
70
+ @git_remote = "origin"
76
71
  @generate_version_class = false
77
72
  end
78
73
 
79
74
  def component_full_paths
80
- component_paths.map { |path| File.expand_path(path, root_path)}
75
+ component_paths.map { |path| File.expand_path(path, root_path) }
81
76
  end
82
77
 
83
78
  def version_rb_path
84
79
  File.expand_path("lib/#{module_path}/version.rb", root_path)
85
80
  end
86
81
 
82
+ def chef_root_path
83
+ module_name == "Chef" ? root_path : File.dirname(root_path)
84
+ end
85
+
87
86
  def version
88
- IO.read(File.expand_path(version_file_path, root_path)).strip
87
+ IO.read(File.join(chef_root_path, "VERSION")).strip
89
88
  end
90
89
 
91
90
  def full_package_dir
@@ -93,7 +92,7 @@ module ChefConfig
93
92
  end
94
93
 
95
94
  def class_or_module
96
- generate_version_class ? 'class' : 'module'
95
+ generate_version_class ? "class" : "module"
97
96
  end
98
97
 
99
98
  def with_clean_env(&block)
@@ -105,46 +104,46 @@ module ChefConfig
105
104
  end
106
105
 
107
106
  def define
108
- fail 'Need to provide package root and module name' if root_path.nil? || module_name.nil?
107
+ raise "Need to provide package root and module name" if root_path.nil? || module_name.nil?
109
108
 
110
- desc 'Build Gems of component dependencies'
109
+ desc "Build Gems of component dependencies"
111
110
  task :package_components do
112
111
  component_full_paths.each do |component_path|
113
112
  Dir.chdir(component_path) do
114
- sh 'rake package'
113
+ sh "rake package"
115
114
  end
116
115
  end
117
116
  end
118
117
 
119
118
  task :package => :package_components
120
119
 
121
- desc 'Build and install component dependencies'
120
+ desc "Build and install component dependencies"
122
121
  task :install_components => :package_components do
123
122
  component_full_paths.each do |component_path|
124
123
  Dir.chdir(component_path) do
125
- sh 'rake install'
124
+ sh "rake install"
126
125
  end
127
126
  end
128
127
  end
129
128
 
130
129
  task :install => :install_components
131
130
 
132
- desc 'Clean up builds of component dependencies'
131
+ desc "Clean up builds of component dependencies"
133
132
  task :clobber_component_packages do
134
133
  component_full_paths.each do |component_path|
135
134
  Dir.chdir(component_path) do
136
- sh 'rake clobber_package'
135
+ sh "rake clobber_package"
137
136
  end
138
137
  end
139
138
  end
140
139
 
141
140
  task :clobber_package => :clobber_component_packages
142
141
 
143
- desc 'Update the version number for component dependencies'
142
+ desc "Update the version number for component dependencies"
144
143
  task :update_components_versions do
145
144
  component_full_paths.each do |component_path|
146
145
  Dir.chdir(component_path) do
147
- sh 'rake version'
146
+ sh "rake version"
148
147
  end
149
148
  end
150
149
  end
@@ -152,7 +151,7 @@ module ChefConfig
152
151
  desc 'Regenerate lib/#{@module_path}/version.rb from VERSION file'
153
152
  task :version => :update_components_versions do
154
153
  contents = <<-VERSION_RB
155
- # Copyright:: Copyright (c) 2010-2015 Chef Software, Inc.
154
+ # Copyright:: Copyright 2010-2016, Chef Software, Inc.
156
155
  # License:: Apache License, Version 2.0
157
156
  #
158
157
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -175,7 +174,7 @@ module ChefConfig
175
174
 
176
175
  #{class_or_module} #{module_name}
177
176
  #{module_name.upcase}_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
178
- VERSION = '#{version}'
177
+ VERSION = "#{version}"
179
178
  end
180
179
 
181
180
  #
@@ -209,11 +208,11 @@ end
209
208
  sh %{gem uninstall #{module_path} -x -v #{version} }
210
209
  end
211
210
 
212
- desc 'Build it, tag it and ship it'
211
+ desc "Build it, tag it and ship it"
213
212
  task :ship => [:clobber_package, :gem] do
214
213
  sh("git tag #{version}")
215
214
  sh("git push #{git_remote} --tags")
216
- Dir[File.expand_path('*.gem', full_package_dir)].reverse.each do |built_gem|
215
+ Dir[File.expand_path("*.gem", full_package_dir)].reverse.each do |built_gem|
217
216
  sh("gem push #{built_gem}")
218
217
  end
219
218
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Bryan McLellan <btm@loftninjas.org>
3
- # Copyright:: Copyright (c) 2014 Chef Software, Inc.
3
+ # Copyright:: Copyright 2014-2016, Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,9 +16,9 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef-config/windows'
20
- require 'chef-config/logger'
21
- require 'chef-config/exceptions'
19
+ require "chef-config/windows"
20
+ require "chef-config/logger"
21
+ require "chef-config/exceptions"
22
22
 
23
23
  module ChefConfig
24
24
  class PathHelper
@@ -32,11 +32,11 @@ module ChefConfig
32
32
  loop do
33
33
  slash = path.rindex(/[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator)}]/, end_slash - 1)
34
34
  if !slash
35
- return end_slash == path.size ? '.' : path_separator
35
+ return end_slash == path.size ? "." : path_separator
36
36
  elsif slash == end_slash - 1
37
37
  end_slash = slash
38
38
  else
39
- return path[0..slash-1]
39
+ return path[0..slash - 1]
40
40
  end
41
41
  end
42
42
  else
@@ -64,8 +64,8 @@ module ChefConfig
64
64
  leading_slashes = /^[#{path_separator_regex}]+/
65
65
 
66
66
  args.flatten.inject() do |joined_path, component|
67
- joined_path = joined_path.sub(trailing_slashes, '')
68
- component = component.sub(leading_slashes, '')
67
+ joined_path = joined_path.sub(trailing_slashes, "")
68
+ component = component.sub(leading_slashes, "")
69
69
  joined_path += "#{path_separator}#{component}"
70
70
  end
71
71
  end
@@ -110,7 +110,7 @@ module ChefConfig
110
110
  end
111
111
 
112
112
  # Produces a comparable path.
113
- def self.canonical_path(path, add_prefix=true)
113
+ def self.canonical_path(path, add_prefix = true)
114
114
  # First remove extra separators and resolve any relative paths
115
115
  abs_path = File.absolute_path(path)
116
116
 
@@ -146,7 +146,7 @@ module ChefConfig
146
146
  # http://stackoverflow.com/questions/14127343
147
147
  def self.escape_glob(*parts)
148
148
  path = cleanpath(join(*parts))
149
- path.gsub(/[\\\{\}\[\]\*\?]/) { |x| "\\"+x }
149
+ path.gsub(/[\\\{\}\[\]\*\?]/) { |x| "\\" + x }
150
150
  end
151
151
 
152
152
  def self.relative_path_from(from, to)
@@ -201,12 +201,12 @@ module ChefConfig
201
201
  # HOMESHARE HOMEPATH
202
202
  # USERPROFILE
203
203
 
204
- paths << ENV['HOME']
205
- paths << ENV['HOMEDRIVE'] + ENV['HOMEPATH'] if ENV['HOMEDRIVE'] && ENV['HOMEPATH']
206
- paths << ENV['HOMESHARE'] + ENV['HOMEPATH'] if ENV['HOMESHARE'] && ENV['HOMEPATH']
207
- paths << ENV['USERPROFILE']
204
+ paths << ENV["HOME"]
205
+ paths << ENV["HOMEDRIVE"] + ENV["HOMEPATH"] if ENV["HOMEDRIVE"] && ENV["HOMEPATH"]
206
+ paths << ENV["HOMESHARE"] + ENV["HOMEPATH"] if ENV["HOMESHARE"] && ENV["HOMEPATH"]
207
+ paths << ENV["USERPROFILE"]
208
208
  end
209
- paths << Dir.home if ENV['HOME']
209
+ paths << Dir.home if ENV["HOME"]
210
210
 
211
211
  # Depending on what environment variables we're using, the slashes can go in any which way.
212
212
  # Just change them all to / to keep things consistent.
@@ -231,27 +231,28 @@ module ChefConfig
231
231
 
232
232
  # Determine if the given path is protected by OS X System Integrity Protection.
233
233
  def self.is_sip_path?(path, node)
234
- if node['platform'] == 'mac_os_x' and Gem::Version.new(node['platform_version']) >= Gem::Version.new('10.11')
234
+ if node["platform"] == "mac_os_x" and Gem::Version.new(node["platform_version"]) >= Gem::Version.new("10.11")
235
235
  # todo: parse rootless.conf for this?
236
- sip_paths= [
237
- '/System', '/bin', '/sbin', '/usr',
238
- ]
239
- sip_paths.each do |sip_path|
240
- ChefConfig.logger.info("This is a SIP path, checking if it in exceptions list.")
241
- return true if path.start_with?(sip_path)
242
- end
243
- false
236
+ sip_paths = [
237
+ "/System", "/bin", "/sbin", "/usr"
238
+ ]
239
+ sip_paths.each do |sip_path|
240
+ ChefConfig.logger.info("This is a SIP path, checking if it in exceptions list.")
241
+ return true if path.start_with?(sip_path)
242
+ end
243
+ false
244
244
  else
245
245
  false
246
246
  end
247
247
  end
248
+
248
249
  # Determine if the given path is on the exception list for OS X System Integrity Protection.
249
250
  def self.writable_sip_path?(path)
250
251
  # todo: parse rootless.conf for this?
251
252
  sip_exceptions = [
252
- '/System/Library/Caches', '/System/Library/Extensions',
253
- '/System/Library/Speech', '/System/Library/User Template',
254
- '/usr/libexec/cups', '/usr/local', '/usr/share/man'
253
+ "/System/Library/Caches", "/System/Library/Extensions",
254
+ "/System/Library/Speech", "/System/Library/User Template",
255
+ "/usr/libexec/cups", "/usr/local", "/usr/share/man"
255
256
  ]
256
257
  sip_exceptions.each do |exception_path|
257
258
  return true if path.start_with?(exception_path)
@@ -261,4 +262,3 @@ module ChefConfig
261
262
  end
262
263
  end
263
264
  end
264
-
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2010-2015 Chef Software, Inc.
1
+ # Copyright:: Copyright 2010-2016, Chef Software, Inc.
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +21,7 @@
21
21
 
22
22
  module ChefConfig
23
23
  CHEFCONFIG_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
24
- VERSION = '12.6.0'
24
+ VERSION = "12.7.2"
25
25
  end
26
26
 
27
27
  #
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
2
+ # Copyright:: Copyright 2015-2016, Chef Software, Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,4 +26,3 @@ module ChefConfig
26
26
  end
27
27
 
28
28
  end
29
-
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Daniel DeLeo (<dan@chef.io>)
3
- # Copyright:: Copyright (c) 2014 Chef Software, Inc.
3
+ # Copyright:: Copyright 2014-2016, Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,11 +16,11 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef-config/config'
20
- require 'chef-config/exceptions'
21
- require 'chef-config/logger'
22
- require 'chef-config/path_helper'
23
- require 'chef-config/windows'
19
+ require "chef-config/config"
20
+ require "chef-config/exceptions"
21
+ require "chef-config/logger"
22
+ require "chef-config/path_helper"
23
+ require "chef-config/windows"
24
24
 
25
25
  module ChefConfig
26
26
  class WorkstationConfigLoader
@@ -29,7 +29,7 @@ module ChefConfig
29
29
  attr_accessor :explicit_config_file
30
30
 
31
31
  # TODO: initialize this with a logger for Chef and Knife
32
- def initialize(explicit_config_file, logger=nil)
32
+ def initialize(explicit_config_file, logger = nil)
33
33
  @explicit_config_file = explicit_config_file
34
34
  @chef_config_dir = nil
35
35
  @config_location = nil
@@ -99,36 +99,36 @@ module ChefConfig
99
99
  candidate_configs = []
100
100
 
101
101
  # Look for $KNIFE_HOME/knife.rb (allow multiple knives config on same machine)
102
- if env['KNIFE_HOME']
103
- candidate_configs << File.join(env['KNIFE_HOME'], 'config.rb')
104
- candidate_configs << File.join(env['KNIFE_HOME'], 'knife.rb')
102
+ if env["KNIFE_HOME"]
103
+ candidate_configs << File.join(env["KNIFE_HOME"], "config.rb")
104
+ candidate_configs << File.join(env["KNIFE_HOME"], "knife.rb")
105
105
  end
106
106
  # Look for $PWD/knife.rb
107
107
  if Dir.pwd
108
- candidate_configs << File.join(Dir.pwd, 'config.rb')
109
- candidate_configs << File.join(Dir.pwd, 'knife.rb')
108
+ candidate_configs << File.join(Dir.pwd, "config.rb")
109
+ candidate_configs << File.join(Dir.pwd, "knife.rb")
110
110
  end
111
111
  # Look for $UPWARD/.chef/knife.rb
112
112
  if chef_config_dir
113
- candidate_configs << File.join(chef_config_dir, 'config.rb')
114
- candidate_configs << File.join(chef_config_dir, 'knife.rb')
113
+ candidate_configs << File.join(chef_config_dir, "config.rb")
114
+ candidate_configs << File.join(chef_config_dir, "knife.rb")
115
115
  end
116
116
  # Look for $HOME/.chef/knife.rb
117
- PathHelper.home('.chef') do |dot_chef_dir|
118
- candidate_configs << File.join(dot_chef_dir, 'config.rb')
119
- candidate_configs << File.join(dot_chef_dir, 'knife.rb')
117
+ PathHelper.home(".chef") do |dot_chef_dir|
118
+ candidate_configs << File.join(dot_chef_dir, "config.rb")
119
+ candidate_configs << File.join(dot_chef_dir, "knife.rb")
120
120
  end
121
121
 
122
- candidate_configs.find do | candidate_config |
122
+ candidate_configs.find do |candidate_config|
123
123
  have_config?(candidate_config)
124
124
  end
125
125
  end
126
126
 
127
127
  def working_directory
128
128
  a = if ChefConfig.windows?
129
- env['CD']
129
+ env["CD"]
130
130
  else
131
- env['PWD']
131
+ env["PWD"]
132
132
  end || Dir.pwd
133
133
 
134
134
  a
@@ -151,7 +151,7 @@ module ChefConfig
151
151
  message = "You have an error in your config file #{config_file_path}\n\n"
152
152
  message << "#{e.class.name}: #{e.message}\n"
153
153
  filtered_trace = e.backtrace.grep(/#{Regexp.escape(config_file_path)}/)
154
- filtered_trace.each {|bt_line| message << " " << bt_line << "\n" }
154
+ filtered_trace.each { |bt_line| message << " " << bt_line << "\n" }
155
155
  if !filtered_trace.empty?
156
156
  line_nr = filtered_trace.first[/#{Regexp.escape(config_file_path)}:([\d]+)/, 1]
157
157
  message << highlight_config_error(config_file_path, line_nr.to_i)
@@ -159,10 +159,9 @@ module ChefConfig
159
159
  raise ChefConfig::ConfigurationError, message
160
160
  end
161
161
 
162
-
163
162
  def highlight_config_error(file, line)
164
163
  config_file_lines = []
165
- IO.readlines(file).each_with_index {|l, i| config_file_lines << "#{(i + 1).to_s.rjust(3)}: #{l.chomp}"}
164
+ IO.readlines(file).each_with_index { |l, i| config_file_lines << "#{(i + 1).to_s.rjust(3)}: #{l.chomp}" }
166
165
  if line == 1
167
166
  lines = config_file_lines[0..3]
168
167
  else