chef-config 14.3.37 → 14.4.56

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8143b86ea4c5fd0ec8d4b8623aee402b2c0ade39738133a99c14f7338ff3327d
4
- data.tar.gz: 607162e7ef57736d7ecd7154a27c4ee132bd8c61452c758084b4dcb16768ce26
3
+ metadata.gz: 4df16d2c91bd0790bf8341d5f98ebc5ebee39c83091da38c5973822b971c1f0c
4
+ data.tar.gz: 0f2d9279a1a8358bbf4455d5c92c46b7ebd457143c8f4c4efcef5f39a223dd67
5
5
  SHA512:
6
- metadata.gz: 81d3a5a11e0281b00c0ae18da2298e3c0227df063597734431423febe7728c0f805a815e4f6d2fd74f465724ee2a1da45bb3fbbc5022a29758e322810e1d26c1
7
- data.tar.gz: b88d7a8a2d4fa5d5abf31839763cee4437e51bff8369ac17061f695f55b9fd3145399f98027801c9e8f0a2752e546184d764581c662f3146bdbb65caf8459624
6
+ metadata.gz: eefc7a831fb6ba7f2adfc4af8bd84f5dbfeaaefb2c407bda3806736774f3e9bb5d098182d23a8ebbe11b120d7f27013c2167ce883fa6b2c2fecf3dbfbbb7bd8a
7
+ data.tar.gz: d54a0eded2c548970fcd7f22a73df3e0d02b9bd4fc95cdb7eff6da3e2b6fe87a95f1b00cbf69f31726a5c724728aca9d5f78411582c9fa029fe081bd0838c7ec
data/Rakefile CHANGED
@@ -1,8 +1,4 @@
1
- require "chef-config/package_task"
2
-
3
- ChefConfig::PackageTask.new(File.expand_path("..", __FILE__), "ChefConfig", "chef-config") do |package|
4
- package.module_path = "chef-config"
5
- end
1
+ require "bundler/gem_tasks"
6
2
 
7
3
  task default: :spec
8
4
 
data/chef-config.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency "addressable"
22
22
  spec.add_dependency "tomlrb", "~> 1.2"
23
23
 
24
- spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rake"
25
25
 
26
26
  %w{rspec-core rspec-expectations rspec-mocks}.each do |rspec|
27
27
  spec.add_development_dependency(rspec, "~> 3.2")
@@ -20,37 +20,78 @@ require "chef-config/path_helper"
20
20
 
21
21
  module ChefConfig
22
22
  module Mixin
23
+ # Helper methods for working with credentials files.
24
+ #
25
+ # @since 13.7
26
+ # @api internal
23
27
  module Credentials
24
-
25
- def load_credentials(profile = nil)
26
- credentials_file = PathHelper.home(".chef", "credentials").freeze
28
+ # Compute the active credentials profile name.
29
+ #
30
+ # The lookup order is argument (from --profile), environment variable
31
+ # ($CHEF_PROFILE), context file (~/.chef/context), and then "default" as
32
+ # a fallback.
33
+ #
34
+ # @since 14.4
35
+ # @param profile [String, nil] Optional override for the active profile,
36
+ # normally set via a command-line option.
37
+ # @return [String]
38
+ def credentials_profile(profile = nil)
27
39
  context_file = PathHelper.home(".chef", "context").freeze
40
+ if !profile.nil?
41
+ profile
42
+ elsif ENV.include?("CHEF_PROFILE")
43
+ ENV["CHEF_PROFILE"]
44
+ elsif File.file?(context_file)
45
+ File.read(context_file).strip
46
+ else
47
+ "default"
48
+ end
49
+ end
28
50
 
29
- return unless File.file?(credentials_file)
30
-
31
- context = File.read(context_file).strip if File.file?(context_file)
32
-
33
- environment = ENV.fetch("CHEF_PROFILE", nil)
51
+ # Compute the path to the credentials file.
52
+ #
53
+ # @since 14.4
54
+ # @return [String]
55
+ def credentials_file_path
56
+ PathHelper.home(".chef", "credentials").freeze
57
+ end
34
58
 
35
- profile = if !profile.nil?
36
- profile
37
- elsif !environment.nil?
38
- environment
39
- elsif !context.nil?
40
- context
41
- else
42
- "default"
43
- end
59
+ # Load and parse the credentials file.
60
+ #
61
+ # Returns `nil` if the credentials file is unavailable.
62
+ #
63
+ # @since 14.4
64
+ # @return [String, nil]
65
+ def parse_credentials_file
66
+ credentials_file = credentials_file_path
67
+ return nil unless File.file?(credentials_file)
68
+ begin
69
+ Tomlrb.load_file(credentials_file)
70
+ rescue => e
71
+ # TOML's error messages are mostly rubbish, so we'll just give a generic one
72
+ message = "Unable to parse Credentials file: #{credentials_file}\n"
73
+ message << e.message
74
+ raise ChefConfig::ConfigurationError, message
75
+ end
76
+ end
44
77
 
45
- config = Tomlrb.load_file(credentials_file)
78
+ # Load and process the active credentials.
79
+ #
80
+ # @see WorkstationConfigLoader#apply_credentials
81
+ # @param profile [String, nil] Optional override for the active profile,
82
+ # normally set via a command-line option.
83
+ # @return [void]
84
+ def load_credentials(profile = nil)
85
+ profile = credentials_profile(profile)
86
+ config = parse_credentials_file
87
+ return if config.nil? # No credentials, nothing to do here.
88
+ if config[profile].nil?
89
+ # Unknown profile name. For "default" just silently ignore, otherwise
90
+ # raise an error.
91
+ return if profile == "default"
92
+ raise ChefConfig::ConfigurationError, "Profile #{profile} doesn't exist. Please add it to #{credentials_file}."
93
+ end
46
94
  apply_credentials(config[profile], profile)
47
- rescue ChefConfig::ConfigurationError
48
- raise
49
- rescue => e
50
- # TOML's error messages are mostly rubbish, so we'll just give a generic one
51
- message = "Unable to parse Credentials file: #{credentials_file}\n"
52
- message << e.message
53
- raise ChefConfig::ConfigurationError, message
54
95
  end
55
96
  end
56
97
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Bryan McLellan <btm@loftninjas.org>
3
- # Copyright:: Copyright 2014-2016, Chef Software, Inc.
3
+ # Copyright:: Copyright 2014-2018, 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");
@@ -152,7 +152,7 @@ module ChefConfig
152
152
  canonical_path(path1) == canonical_path(path2)
153
153
  end
154
154
 
155
- # Note: this method is deprecated. Please use escape_glob_dirs
155
+ # @deprecated this method is deprecated. Please use escape_glob_dirs
156
156
  # Paths which may contain glob-reserved characters need
157
157
  # to be escaped before globbing can be done.
158
158
  # http://stackoverflow.com/questions/14127343
@@ -295,5 +295,28 @@ module ChefConfig
295
295
  ChefConfig.logger.error("Cannot write to a SIP Path on OS X 10.11+")
296
296
  false
297
297
  end
298
+
299
+ # Splits a string into an array of tokens as commands and arguments
300
+ #
301
+ # str = 'command with "some arguments"'
302
+ # split_args(str) => ["command", "with", "\"some arguments\""]
303
+ #
304
+ def self.split_args(line)
305
+ cmd_args = []
306
+ field = ""
307
+ line.scan(/\s*(?>([^\s\\"]+|"([^"]*)"|'([^']*)')|(\S))(\s|\z)?/m) do |word, within_dq, within_sq, esc, sep|
308
+
309
+ # Append the string with Word & Escape Character
310
+ field << (word || esc.gsub(/\\(.)/, '\\1'))
311
+
312
+ # Re-build the field when any whitespace character or
313
+ # End of string is encountered
314
+ if sep
315
+ cmd_args << field
316
+ field = ""
317
+ end
318
+ end
319
+ cmd_args
320
+ end
298
321
  end
299
322
  end
@@ -21,7 +21,7 @@
21
21
 
22
22
  module ChefConfig
23
23
  CHEFCONFIG_ROOT = File.expand_path("../..", __FILE__)
24
- VERSION = "14.3.37".freeze
24
+ VERSION = "14.4.56".freeze
25
25
  end
26
26
 
27
27
  #
@@ -225,12 +225,14 @@ module ChefConfig
225
225
  Config[:node_name] ||= Etc.getlogin
226
226
  # If we don't have a key (path or inline) check user.pem and $node_name.pem.
227
227
  unless Config.key?(:client_key) || Config.key?(:client_key_contents)
228
- Config[:client_key] = find_default_key(["#{Config[:node_name]}.pem", "user.pem"])
228
+ key_path = find_default_key(["#{Config[:node_name]}.pem", "user.pem"])
229
+ Config[:client_key] = key_path if key_path
229
230
  end
230
231
  # Similarly look for a validation key file, though this should be less
231
232
  # common these days.
232
233
  unless Config.key?(:validation_key) || Config.key?(:validation_key_contents)
233
- Config[:validation_key] = find_default_key(["#{Config[:validation_client_name]}.pem", "validator.pem", "validation.pem"])
234
+ key_path = find_default_key(["#{Config[:validation_client_name]}.pem", "validator.pem", "validation.pem"])
235
+ Config[:validation_key] = key_path if key_path
234
236
  end
235
237
  end
236
238
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 14.3.37
4
+ version: 14.4.56
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-10 00:00:00.000000000 Z
11
+ date: 2018-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout
@@ -90,16 +90,16 @@ dependencies:
90
90
  name: rake
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - "~>"
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
- version: '10.0'
95
+ version: '0'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - "~>"
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
- version: '10.0'
102
+ version: '0'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: rspec-core
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -160,7 +160,6 @@ files:
160
160
  - lib/chef-config/mixin/credentials.rb
161
161
  - lib/chef-config/mixin/dot_d.rb
162
162
  - lib/chef-config/mixin/fuzzy_hostname_matcher.rb
163
- - lib/chef-config/package_task.rb
164
163
  - lib/chef-config/path_helper.rb
165
164
  - lib/chef-config/version.rb
166
165
  - lib/chef-config/windows.rb
@@ -1,289 +0,0 @@
1
- #
2
- # Author:: Kartik Null Cating-Subramanian (<ksubramanian@chef.io>)
3
- # Copyright:: Copyright 2015-2016, Chef, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require "rake"
20
- require "rubygems"
21
- require "rubygems/package_task"
22
-
23
- module ChefConfig
24
- class PackageTask < Rake::TaskLib
25
-
26
- # Full path to root of top-level repository. All other files (like VERSION or
27
- # lib/<module_path>/version.rb are rooted at this path).
28
- attr_accessor :root_path
29
-
30
- # Name of the top-level module/library build built. This is used to define
31
- # the top level module which contains VERSION and MODULE_ROOT.
32
- attr_accessor :module_name
33
-
34
- # Name of the gem being built. This is used to find the lines to fix in
35
- # Gemfile.lock.
36
- attr_accessor :gem_name
37
-
38
- # Should the generated version.rb be in a class or module? Default is false (module).
39
- attr_accessor :generate_version_class
40
-
41
- # Paths to the roots of any components that also support ChefPackageTask.
42
- # If relative paths are provided, they are rooted against root_path.
43
- attr_accessor :component_paths
44
-
45
- # This is the module name as it appears on the path "lib/module/".
46
- # e.g. for module_name "ChefDK", you'd want module_path to be "chef-dk".
47
- # The default is module_name but lower-cased.
48
- attr_writer :module_path
49
-
50
- def module_path
51
- @module_path || module_name.downcase
52
- end
53
-
54
- # Directory used to store package files and output that is generated.
55
- # This has the same meaning (or lack thereof) as package_dir in
56
- # rake/packagetask.
57
- attr_accessor :package_dir
58
-
59
- # Name of git remote used to push tags during a release. Default is origin.
60
- attr_accessor :git_remote
61
-
62
- # True if should use Chef::VersionString.
63
- attr_accessor :use_versionstring
64
-
65
- def initialize(root_path = nil, module_name = nil, gem_name = nil)
66
- init(root_path, module_name, gem_name)
67
- yield self if block_given?
68
- define unless root_path.nil? || module_name.nil?
69
- end
70
-
71
- def init(root_path, module_name, gem_name)
72
- @root_path = root_path
73
- @module_name = module_name
74
- @gem_name = gem_name
75
- @component_paths = []
76
- @module_path = nil
77
- @package_dir = "pkg"
78
- @git_remote = "origin"
79
- @generate_version_class = false
80
- end
81
-
82
- def component_full_paths
83
- component_paths.map { |path| File.expand_path(path, root_path) }
84
- end
85
-
86
- def version_rb_path
87
- File.expand_path("lib/#{module_path}/version.rb", root_path)
88
- end
89
-
90
- def chef_root_path
91
- module_name == "Chef" ? root_path : File.dirname(root_path)
92
- end
93
-
94
- def version_file_path
95
- File.join(chef_root_path, "VERSION")
96
- end
97
-
98
- def gemfile_lock_path
99
- File.join(root_path, "Gemfile.lock")
100
- end
101
-
102
- def version
103
- IO.read(version_file_path).strip
104
- end
105
-
106
- def full_package_dir
107
- File.expand_path(package_dir, root_path)
108
- end
109
-
110
- def class_or_module
111
- generate_version_class ? "class" : "module"
112
- end
113
-
114
- def with_clean_env(&block)
115
- if defined?(Bundler)
116
- Bundler.with_clean_env(&block)
117
- else
118
- yield
119
- end
120
- end
121
-
122
- def define
123
- raise "Need to provide package root and module name" if root_path.nil? || module_name.nil?
124
-
125
- desc "Build Gems of component dependencies"
126
- task :package_components do
127
- component_full_paths.each do |component_path|
128
- Dir.chdir(component_path) do
129
- sh "rake package"
130
- end
131
- end
132
- end
133
-
134
- task package: :package_components
135
-
136
- desc "Build and install component dependencies"
137
- task install_components: :package_components do
138
- component_full_paths.each do |component_path|
139
- Dir.chdir(component_path) do
140
- sh "rake install"
141
- end
142
- end
143
- end
144
-
145
- task install: :install_components
146
-
147
- desc "Clean up builds of component dependencies"
148
- task :clobber_component_packages do
149
- component_full_paths.each do |component_path|
150
- Dir.chdir(component_path) do
151
- sh "rake clobber_package"
152
- end
153
- end
154
- end
155
-
156
- task clobber_package: :clobber_component_packages
157
-
158
- desc "Update the version number for component dependencies"
159
- task :update_components_versions do
160
- component_full_paths.each do |component_path|
161
- Dir.chdir(component_path) do
162
- sh "rake version"
163
- end
164
- end
165
- end
166
-
167
- namespace :version do
168
- desc "Regenerate lib/#{module_path}/version.rb from VERSION file"
169
- task update: :update_components_versions do
170
- update_version_rb
171
- update_gemfile_lock
172
- end
173
-
174
- task bump: %w{version:bump_patch version:update}
175
-
176
- task :show do
177
- puts version
178
- end
179
-
180
- # Add 1 to the current patch version in the VERSION file, and write it back out.
181
- task :bump_patch do
182
- current_version = version
183
- new_version = current_version.sub(/^(\d+\.\d+\.)(\d+)/) { "#{$1}#{$2.to_i + 1}" }
184
- puts "Updating version in #{version_rb_path} from #{current_version.chomp} to #{new_version.chomp}"
185
- IO.write(version_file_path, new_version)
186
- end
187
-
188
- task :bump_minor do
189
- current_version = version
190
- new_version = current_version.sub(/^(\d+)\.(\d+)\.(\d+)/) { "#{$1}.#{$2.to_i + 1}.0" }
191
- puts "Updating version in #{version_rb_path} from #{current_version.chomp} to #{new_version.chomp}"
192
- IO.write(version_file_path, new_version)
193
- end
194
-
195
- task :bump_major do
196
- current_version = version
197
- new_version = current_version.sub(/^(\d+)\.(\d+\.\d+)/) { "#{$1.to_i + 1}.0.0" }
198
- puts "Updating version in #{version_rb_path} from #{current_version.chomp} to #{new_version.chomp}"
199
- IO.write(version_file_path, new_version)
200
- end
201
-
202
- def update_version_rb # rubocop:disable Lint/NestedMethodDefinition
203
- puts "Updating #{version_rb_path} to include version #{version} ..."
204
- contents = <<~VERSION_RB
205
- # Copyright:: Copyright 2010-2016, Chef Software, Inc.
206
- # License:: Apache License, Version 2.0
207
- #
208
- # Licensed under the Apache License, Version 2.0 (the "License");
209
- # you may not use this file except in compliance with the License.
210
- # You may obtain a copy of the License at
211
- #
212
- # http://www.apache.org/licenses/LICENSE-2.0
213
- #
214
- # Unless required by applicable law or agreed to in writing, software
215
- # distributed under the License is distributed on an "AS IS" BASIS,
216
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
217
- # See the License for the specific language governing permissions and
218
- # limitations under the License.
219
-
220
- #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
221
- # NOTE: This file is generated by running `rake version` in the top level of
222
- # this repo. Do not edit this manually. Edit the VERSION file and run the rake
223
- # task instead.
224
- #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
225
- #{"\nrequire \"chef/version_string\"\n" if use_versionstring}
226
- #{class_or_module} #{module_name}
227
- #{module_name.upcase}_ROOT = File.expand_path("../..", __FILE__)
228
- VERSION = #{use_versionstring ? "Chef::VersionString.new(\"#{version}\")" : "\"#{version}\""}
229
- end
230
-
231
- #
232
- # NOTE: the Chef::Version class is defined in version_class.rb
233
- #
234
- # NOTE: DO NOT Use the Chef::Version class on #{module_name}::VERSIONs. The
235
- # Chef::Version class is for _cookbooks_ only, and cannot handle
236
- # pre-release versions like "10.14.0.rc.2". Please use Rubygem's
237
- # Gem::Version class instead.
238
- #
239
- VERSION_RB
240
- IO.write(version_rb_path, contents)
241
- end
242
-
243
- def update_gemfile_lock # rubocop:disable Lint/NestedMethodDefinition
244
- if File.exist?(gemfile_lock_path)
245
- puts "Updating #{gemfile_lock_path} to include version #{version} ..."
246
- contents = IO.read(gemfile_lock_path)
247
- contents.gsub!(/^\s*(chef|chef-config)\s*\((= )?\S+\)\s*$/) do |line|
248
- line.gsub(/\((= )?\d+(\.\d+)+/) { "(#{$1}#{version}" }
249
- end
250
- IO.write(gemfile_lock_path, contents)
251
- end
252
- end
253
- end
254
-
255
- task version: "version:update"
256
-
257
- gemspec_platform_to_install = ""
258
- Dir[File.expand_path("*.gemspec", root_path)].reverse_each do |gemspec_path|
259
- gemspec = eval(IO.read(gemspec_path))
260
- Gem::PackageTask.new(gemspec) do |task|
261
- task.package_dir = full_package_dir
262
- end
263
- gemspec_platform_to_install = "-#{gemspec.platform}" if gemspec.platform != Gem::Platform::RUBY && Gem::Platform.match(gemspec.platform)
264
- end
265
-
266
- desc "Build and install a #{module_path} gem"
267
- task install: [:package] do
268
- with_clean_env do
269
- full_module_path = File.join(full_package_dir, module_path)
270
- sh %{gem install #{full_module_path}-#{version}#{gemspec_platform_to_install}.gem --no-rdoc --no-ri}
271
- end
272
- end
273
-
274
- task :uninstall do
275
- sh %{gem uninstall #{module_path} -x -v #{version} }
276
- end
277
-
278
- desc "Build it, tag it and ship it"
279
- task ship: [:clobber_package, :gem] do
280
- sh("git tag #{version}")
281
- sh("git push #{git_remote} --tags")
282
- Dir[File.expand_path("*.gem", full_package_dir)].reverse_each do |built_gem|
283
- sh("gem push #{built_gem}")
284
- end
285
- end
286
- end
287
- end
288
-
289
- end