chef 16.8.14-universal-mingw32 → 16.9.32-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -4
  3. data/README.md +1 -1
  4. data/chef.gemspec +20 -2
  5. data/lib/chef/compliance/default_attributes.rb +5 -1
  6. data/lib/chef/compliance/fetcher/automate.rb +2 -2
  7. data/lib/chef/compliance/fetcher/chef_server.rb +2 -2
  8. data/lib/chef/compliance/reporter/automate.rb +1 -2
  9. data/lib/chef/compliance/reporter/chef_server_automate.rb +2 -2
  10. data/lib/chef/compliance/runner.rb +11 -8
  11. data/lib/chef/http/ssl_policies.rb +27 -14
  12. data/lib/chef/knife/core/formatting_options.rb +49 -0
  13. data/lib/chef/knife/core/node_presenter.rb +0 -25
  14. data/lib/chef/knife/core/status_presenter.rb +1 -26
  15. data/lib/chef/knife/core/windows_bootstrap_context.rb +1 -1
  16. data/lib/chef/knife/node_show.rb +2 -1
  17. data/lib/chef/knife/search.rb +2 -1
  18. data/lib/chef/knife/status.rb +8 -11
  19. data/lib/chef/policy_builder/policyfile.rb +1 -1
  20. data/lib/chef/provider/package.rb +53 -19
  21. data/lib/chef/provider/package/dnf.rb +39 -12
  22. data/lib/chef/provider/package/dnf/dnf_helper.py +18 -5
  23. data/lib/chef/provider/package/dnf/python_helper.rb +6 -6
  24. data/lib/chef/provider/package/freebsd/pkgng.rb +3 -1
  25. data/lib/chef/provider/yum_repository.rb +2 -2
  26. data/lib/chef/resource/chef_gem.rb +2 -2
  27. data/lib/chef/resource/cron/cron_d.rb +1 -0
  28. data/lib/chef/resource/file.rb +1 -1
  29. data/lib/chef/resource/gem_package.rb +2 -2
  30. data/lib/chef/resource/homebrew_cask.rb +3 -3
  31. data/lib/chef/resource/http_request.rb +1 -1
  32. data/lib/chef/resource/locale.rb +1 -1
  33. data/lib/chef/resource/mdadm.rb +2 -2
  34. data/lib/chef/resource/osx_profile.rb +7 -7
  35. data/lib/chef/resource/remote_directory.rb +1 -1
  36. data/lib/chef/resource/ruby.rb +1 -5
  37. data/lib/chef/resource/ruby_block.rb +1 -1
  38. data/lib/chef/resource/user/windows_user.rb +5 -0
  39. data/lib/chef/resource/windows_certificate.rb +2 -12
  40. data/lib/chef/resource/yum_repository.rb +5 -0
  41. data/lib/chef/shell.rb +32 -1
  42. data/lib/chef/version.rb +1 -1
  43. data/lib/chef/version_string.rb +1 -1
  44. data/spec/data/rubygems.org/latest_specs.4.8.gz +0 -0
  45. data/spec/data/rubygems.org/nonexistent_gem +0 -0
  46. data/spec/data/rubygems.org/sexp_processor +0 -0
  47. data/spec/data/rubygems.org/sexp_processor-4.15.1.gemspec.rz +0 -0
  48. data/spec/data/ssl/binary/chef-rspec-der.cert +0 -0
  49. data/spec/data/ssl/binary/chef-rspec-der.key +0 -0
  50. data/spec/functional/resource/dnf_package_spec.rb +319 -16
  51. data/spec/functional/resource/ohai_spec.rb +2 -10
  52. data/spec/functional/resource/windows_certificate_spec.rb +204 -384
  53. data/spec/spec_helper.rb +1 -1
  54. data/spec/unit/compliance/runner_spec.rb +33 -7
  55. data/spec/unit/http/ssl_policies_spec.rb +106 -78
  56. data/spec/unit/knife/bootstrap_spec.rb +5 -17
  57. data/spec/unit/knife/core/status_presenter_spec.rb +54 -0
  58. data/spec/unit/mixin/openssl_helper_spec.rb +0 -7
  59. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +1 -1
  60. data/spec/unit/provider/package/rubygems_spec.rb +39 -7
  61. data/spec/unit/resource/user/windows_user_spec.rb +36 -0
  62. metadata +32 -14
  63. data/spec/data/trusted_certs_empty/.gitkeep +0 -0
  64. data/spec/data/trusted_certs_empty/README.md +0 -1
  65. data/spec/scripts/ssl-serve.rb +0 -47
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a402ad1804c5598430fc8d710c1c595fd9bbaf12c402d6cf292c7116b3fea2a5
4
- data.tar.gz: 53feecbd87fd2523bf12ed8c0b6665026edf1aba53bfa9fbd671f662a97e220c
3
+ metadata.gz: 2e32dc7fbd51e779de024bdb1eaf0c97ff02fbd2c564e4d1a0213be56d327411
4
+ data.tar.gz: b464130a1f9adaaaea74fd10c8cbefb9bf560aaf29c9cb284b8e77420bedbc3e
5
5
  SHA512:
6
- metadata.gz: ce2334263a8401db42070c380242d07340a34a93ae79a0c0d614bea8725f71541e73ccfd4254e711f71826f02dc7172ede575d9e353b8e31927631fbe4edd98d
7
- data.tar.gz: 5f6ec68ae4267b02140264890af0b777459e5e2536c4991c651726fe62db097017710dc0597017b9a3d5f27944a762d96171a69d9d5c1d3250c05fbf98c3ade5
6
+ metadata.gz: bd1d936dbf081c8116041fa016e1b48043b3c0e65e6299fcbfde79b43606472f7b10b76a0bfab85d02ccdc4175ea15a6a5a711f683619630d5133f3ad7525429
7
+ data.tar.gz: 248b1629d5d3b94130192c3d8e95e40ec0c183c865aeb80d2bc0d4a402b1788170f50768261bc0e45124443647739becff32f260a6953aa3deb63d21c77da83a
data/Gemfile CHANGED
@@ -1,5 +1,8 @@
1
1
  source "https://rubygems.org"
2
2
 
3
+ # pin until issues with Windows builds in 1.14.2 are resolved
4
+ gem "ffi", "=1.13.1"
5
+
3
6
  # Note we do not use the gemspec DSL which restricts to the
4
7
  # gemspec for the current platform and filters out other platforms
5
8
  # during a bundle lock operation. We actually want dependencies from
@@ -7,7 +10,7 @@ source "https://rubygems.org"
7
10
  # of bundler versions prior to 1.12.0 (https://github.com/bundler/bundler/commit/193a14fe5e0d56294c7b370a0e59f93b2c216eed)
8
11
  gem "chef", path: "."
9
12
 
10
- gem "ohai", git: "https://github.com/chef/ohai.git", branch: "master"
13
+ gem "ohai", git: "https://github.com/chef/ohai.git", branch: "16-stable"
11
14
 
12
15
  gem "chef-utils", path: File.expand_path("chef-utils", __dir__) if File.exist?(File.expand_path("chef-utils", __dir__))
13
16
  gem "chef-config", path: File.expand_path("chef-config", __dir__) if File.exist?(File.expand_path("chef-config", __dir__))
@@ -50,14 +53,13 @@ end
50
53
 
51
54
  group(:development, :test) do
52
55
  gem "rake"
53
- gem "rspec"
56
+ gem "rspec", "=3.9.0" # remove pin once https://github.com/chef/chef/issues/10817 is resolved
54
57
  gem "webmock"
55
58
  gem "fauxhai-ng" # for chef-utils gem
56
59
  end
57
60
 
58
61
  group(:chefstyle) do
59
- # for testing new chefstyle rules
60
- gem "chefstyle", git: "https://github.com/chef/chefstyle.git", branch: "master"
62
+ gem "chefstyle", "= 1.5.9"
61
63
  end
62
64
 
63
65
  instance_eval(ENV["GEMFILE_MOD"]) if ENV["GEMFILE_MOD"]
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Chef Infra
2
2
  [![Code Climate](https://codeclimate.com/github/chef/chef.svg)](https://codeclimate.com/github/chef/chef)
3
- [![Build Status](https://badge.buildkite.com/c82093430ceec7d27af05febb9dcafe3aa331fff9d74c0ab9d.svg?branch=master)](https://buildkite.com/chef-oss/chef-chef-master-verify)
3
+ [![Build Status](https://badge.buildkite.com/c82093430ceec7d27af05febb9dcafe3aa331fff9d74c0ab9d.svg?branch=chef-16)](https://buildkite.com/chef-oss/chef-chef-chef-16-verify)
4
4
  [![Gem Version](https://badge.fury.io/rb/chef.svg)](https://badge.fury.io/rb/chef)
5
5
  [![](https://img.shields.io/badge/Release%20Policy-Cadence%20Release-brightgreen.svg)](https://github.com/chef/chef/blob/master/docs/dev/design_documents/client_release_cadence.md)
6
6
 
@@ -1,4 +1,13 @@
1
1
  $:.unshift(File.dirname(__FILE__) + "/lib")
2
+ vs_path = File.expand_path("chef-utils/lib/chef-utils/version_string.rb", __dir__)
3
+
4
+ if File.exist?(vs_path)
5
+ # this is the moral equivalent of a require_relative since bundler makes require_relative here fail hard
6
+ eval(IO.read(vs_path))
7
+ else
8
+ # if the path doesn't exist then we're just in the wild gem and not in the git repo
9
+ require "chef-utils/version_string"
10
+ end
2
11
  require "chef/version"
3
12
 
4
13
  Gem::Specification.new do |s|
@@ -35,7 +44,7 @@ Gem::Specification.new do |s|
35
44
  s.add_dependency "net-ssh-multi", "~> 1.2", ">= 1.2.1"
36
45
  s.add_dependency "net-sftp", ">= 2.1.2", "< 4.0"
37
46
  s.add_dependency "ed25519", "~> 1.2" # ed25519 ssh key support
38
- s.add_dependency "bcrypt_pbkdf", "= 1.1.0.rc1" # ed25519 ssh key support
47
+ s.add_dependency "bcrypt_pbkdf", "= 1.1.0.rc2" # ed25519 ssh key support
39
48
  s.add_dependency "highline", ">= 1.6.9", "< 3"
40
49
  s.add_dependency "tty-prompt", "~> 0.21" # knife ui.ask prompt
41
50
  s.add_dependency "tty-screen", "~> 0.6" # knife list
@@ -51,7 +60,7 @@ Gem::Specification.new do |s|
51
60
  s.add_dependency "iniparse", "~> 1.4"
52
61
  s.add_dependency "addressable"
53
62
  s.add_dependency "syslog-logger", "~> 1.6"
54
- s.add_dependency "uuidtools", "~> 2.1.5"
63
+ s.add_dependency "uuidtools", ">= 2.1.5", "< 3.0"
55
64
 
56
65
  s.add_dependency "proxifier", "~> 1.0"
57
66
 
@@ -67,4 +76,13 @@ Gem::Specification.new do |s|
67
76
  Dir.glob("{lib,spec}/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) } +
68
77
  Dir.glob("*.gemspec") +
69
78
  Dir.glob("tasks/rspec.rb")
79
+
80
+ s.metadata = {
81
+ "bug_tracker_uri" => "https://github.com/chef/chef/issues",
82
+ "changelog_uri" => "https://github.com/chef/chef/blob/master/CHANGELOG.md",
83
+ "documentation_uri" => "https://docs.chef.io/",
84
+ "homepage_uri" => "https://www.chef.io",
85
+ "mailing_list_uri" => "https://discourse.chef.io/",
86
+ "source_code_uri" => "https://github.com/chef/chef/",
87
+ }
70
88
  end
@@ -83,7 +83,11 @@ class Chef
83
83
 
84
84
  # The array of results per control will be truncated at this limit to avoid large reports that cannot be
85
85
  # processed by Chef Automate. A summary of removed results will be sent with each impacted control.
86
- "control_results_limit" => 50
86
+ "control_results_limit" => 50,
87
+
88
+ # If enabled, a hash representation of the Chef Infra node object will be sent to Chef InSpec in an input
89
+ # named `chef_node`.
90
+ "chef_node_attribute_enabled" => false
87
91
  )
88
92
  end
89
93
  end
@@ -7,8 +7,8 @@ class Chef
7
7
  class Automate < ::InspecPlugins::Compliance::Fetcher
8
8
  name "chef-automate"
9
9
 
10
- # it positions itself before `compliance` fetcher
11
- # only load it, if you want to use audit cookbook in Chef Solo with Chef Automate
10
+ # Positions this fetcher before Chef InSpec's `compliance` fetcher.
11
+ # Only load this file if you want to use Compliance Phase in Chef Solo with Chef Automate.
12
12
  priority 502
13
13
 
14
14
  CONFIG = {
@@ -95,11 +95,11 @@ class Chef
95
95
  def handle_http_error_code(code)
96
96
  case code
97
97
  when /401|403/
98
- Chef::Log.error "Auth issue: see audit cookbook TROUBLESHOOTING.md"
98
+ Chef::Log.error "Auth issue: see the Compliance Phase troubleshooting documentation (http://docs.chef.io/chef_compliance_phase/#troubleshooting)."
99
99
  when /404/
100
100
  Chef::Log.error "Object does not exist on remote server."
101
101
  when /413/
102
- Chef::Log.error "You most likely hit the erchef request size in #{ChefUtils::Dist::Server::PRODUCT} that defaults to ~2MB. To increase this limit see audit cookbook TROUBLESHOOTING.md OR https://docs.chef.io/config_rb_server.html"
102
+ Chef::Log.error "You most likely hit the erchef request size in #{ChefUtils::Dist::Server::PRODUCT} that defaults to ~2MB. To increase this limit see the Compliance Phase troubleshooting documentation (http://docs.chef.io/chef_compliance_phase/#troubleshooting) or the Chef Infra Server configuration documentation (https://docs.chef.io/server/config_rb_server/)"
103
103
  when /429/
104
104
  Chef::Log.error "This error typically means the data sent was larger than #{ChefUtils::Dist::Automate::PRODUCT}'s limit (4 MB). Run InSpec locally to identify any controls producing large diffs."
105
105
  end
@@ -36,8 +36,7 @@ class Chef
36
36
  end
37
37
 
38
38
  unless @url && @token
39
- Chef::Log.warn "data_collector.token and data_collector.server_url must be defined in client.rb!"
40
- Chef::Log.warn "Further information: https://github.com/chef-cookbooks/audit#direct-reporting-to-chef-automate"
39
+ Chef::Log.warn "data_collector.token and data_collector.server_url must be defined in client.rb! Further information: https://docs.chef.io/chef_compliance_phase/#direct-reporting-to-chef-automate"
41
40
  return false
42
41
  end
43
42
 
@@ -76,11 +76,11 @@ class Chef
76
76
  def handle_http_error_code(code)
77
77
  case code
78
78
  when /401|403/
79
- Chef::Log.error "Auth issue: see audit cookbook TROUBLESHOOTING.md"
79
+ Chef::Log.error "Auth issue: see the Compliance Phase troubleshooting documentation (http://docs.chef.io/chef_compliance_phase/#troubleshooting)."
80
80
  when /404/
81
81
  Chef::Log.error "Object does not exist on remote server."
82
82
  when /413/
83
- Chef::Log.error "You most likely hit the erchef request size in #{ChefUtils::Dist::Server::PRODUCT} that defaults to ~2MB. To increase this limit see audit cookbook TROUBLESHOOTING.md OR https://docs.chef.io/config_rb_server.html"
83
+ Chef::Log.error "You most likely hit the erchef request size in #{ChefUtils::Dist::Server::PRODUCT} that defaults to ~2MB. To increase this limit see the Compliance Phase troubleshooting documentation (http://docs.chef.io/chef_compliance_phase/#troubleshooting) or the Chef Infra Server configuration documentation (https://docs.chef.io/server/config_rb_server/)"
84
84
  when /429/
85
85
  Chef::Log.error "This error typically means the data sent was larger than #{ChefUtils::Dist::Automate::PRODUCT}'s limit (4 MB). Run InSpec locally to identify any controls producing large diffs."
86
86
  end
@@ -11,12 +11,14 @@ class Chef
11
11
  class Runner < EventDispatch::Base
12
12
  extend Forwardable
13
13
 
14
- attr_accessor :run_id, :recipes
14
+ attr_accessor :run_id
15
15
  attr_reader :node
16
16
  def_delegators :node, :logger
17
17
 
18
18
  def enabled?
19
- audit_cookbook_present = recipes.include?("audit::default")
19
+ # Did we parse the libraries file from the audit cookbook? This class dates back to when Chef Automate was
20
+ # renamed from Chef Visibility in 2017, so should capture all modern versions of the audit cookbook.
21
+ audit_cookbook_present = defined?(::Reporter::ChefAutomate)
20
22
 
21
23
  logger.info("#{self.class}##{__method__}: #{Inspec::Dist::PRODUCT_NAME} profiles? #{inspec_profiles.any?}")
22
24
  logger.info("#{self.class}##{__method__}: audit cookbook? #{audit_cookbook_present}")
@@ -37,10 +39,6 @@ class Chef
37
39
  self.run_id = run_status.run_id
38
40
  end
39
41
 
40
- def run_list_expanded(run_list_expansion)
41
- self.recipes = run_list_expansion.recipes
42
- end
43
-
44
42
  def run_completed(_node, _run_status)
45
43
  return unless enabled?
46
44
 
@@ -61,7 +59,6 @@ class Chef
61
59
 
62
60
  DEPRECATED_CONFIG_VALUES = %w{
63
61
  attributes_save
64
- chef_node_attribute_enabled
65
62
  fail_if_not_present
66
63
  inspec_gem_source
67
64
  inspec_version
@@ -93,9 +90,15 @@ class Chef
93
90
  end
94
91
 
95
92
  def inspec_opts
93
+ inputs = node["audit"]["attributes"].to_h
94
+ if node["audit"]["chef_node_attribute_enabled"]
95
+ inputs["chef_node"] = node.to_h
96
+ inputs["chef_node"]["chef_environment"] = node.chef_environment
97
+ end
98
+
96
99
  {
97
100
  backend_cache: node["audit"]["inspec_backend_cache"],
98
- inputs: node["audit"]["attributes"],
101
+ inputs: inputs,
99
102
  logger: logger,
100
103
  output: node["audit"]["quiet"] ? ::File::NULL : STDOUT,
101
104
  report: true,
@@ -85,28 +85,41 @@ class Chef
85
85
  http_client.cert_store.set_default_paths
86
86
  end
87
87
  if config.trusted_certs_dir
88
- certs = Dir.glob(File.join(Chef::Util::PathHelper.escape_glob_dir(config.trusted_certs_dir), "*.{crt,pem}"))
88
+ certs = Dir.glob(::File.join(Chef::Util::PathHelper.escape_glob_dir(config.trusted_certs_dir), "*.{crt,pem}"))
89
89
  certs.each do |cert_file|
90
- cert = OpenSSL::X509::Certificate.new(File.read(cert_file))
90
+ cert = begin
91
+ OpenSSL::X509::Certificate.new(::File.binread(cert_file))
92
+ rescue OpenSSL::X509::CertificateError => e
93
+ raise Chef::Exceptions::ConfigurationError, "Error reading cert file '#{cert_file}', original error '#{e.class}: #{e.message}'"
94
+ end
91
95
  add_trusted_cert(cert)
92
96
  end
93
97
  end
94
98
  end
95
99
 
96
100
  def set_client_credentials
97
- if config[:ssl_client_cert] || config[:ssl_client_key]
98
- unless config[:ssl_client_cert] && config[:ssl_client_key]
99
- raise Chef::Exceptions::ConfigurationError, "You must configure ssl_client_cert and ssl_client_key together"
100
- end
101
- unless ::File.exists?(config[:ssl_client_cert])
102
- raise Chef::Exceptions::ConfigurationError, "The configured ssl_client_cert #{config[:ssl_client_cert]} does not exist"
103
- end
104
- unless ::File.exists?(config[:ssl_client_key])
105
- raise Chef::Exceptions::ConfigurationError, "The configured ssl_client_key #{config[:ssl_client_key]} does not exist"
106
- end
101
+ return unless config[:ssl_client_cert] || config[:ssl_client_key]
102
+
103
+ unless config[:ssl_client_cert] && config[:ssl_client_key]
104
+ raise Chef::Exceptions::ConfigurationError, "You must configure ssl_client_cert and ssl_client_key together"
105
+ end
106
+ unless ::File.exists?(config[:ssl_client_cert])
107
+ raise Chef::Exceptions::ConfigurationError, "The configured ssl_client_cert #{config[:ssl_client_cert]} does not exist"
108
+ end
109
+ unless ::File.exists?(config[:ssl_client_key])
110
+ raise Chef::Exceptions::ConfigurationError, "The configured ssl_client_key #{config[:ssl_client_key]} does not exist"
111
+ end
112
+
113
+ begin
114
+ http_client.cert = OpenSSL::X509::Certificate.new(::File.binread(config[:ssl_client_cert]))
115
+ rescue OpenSSL::X509::CertificateError => e
116
+ raise Chef::Exceptions::ConfigurationError, "Error reading cert file '#{config[:ssl_client_cert]}', original error '#{e.class}: #{e.message}'"
117
+ end
107
118
 
108
- http_client.cert = OpenSSL::X509::Certificate.new(::File.read(config[:ssl_client_cert]))
109
- http_client.key = OpenSSL::PKey::RSA.new(::File.read(config[:ssl_client_key]))
119
+ begin
120
+ http_client.key = OpenSSL::PKey::RSA.new(::File.binread(config[:ssl_client_key]))
121
+ rescue OpenSSL::PKey::RSAError => e
122
+ raise Chef::Exceptions::ConfigurationError, "Error reading key file '#{config[:ssl_client_key]}', original error '#{e.class}: #{e.message}'"
110
123
  end
111
124
  end
112
125
 
@@ -0,0 +1,49 @@
1
+ #
2
+ # Author:: Nicolas DUPEUX (<nicolas.dupeux@arkea.com>)
3
+ # Copyright:: Copyright (c) Chef Software 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
+ class Chef
20
+ class Knife
21
+ module Core
22
+
23
+ # This module may be included into a knife subcommand class to automatically
24
+ # add configuration options used by the StatusPresenter and NodePresenter.
25
+ module FormattingOptions
26
+ # @private
27
+ # Would prefer to do this in a rational way, but can't be done b/c of
28
+ # Mixlib::CLI's design :(
29
+ def self.included(includer)
30
+ includer.class_eval do
31
+ option :medium_output,
32
+ short: "-m",
33
+ long: "--medium",
34
+ boolean: true,
35
+ default: false,
36
+ description: "Include normal attributes in the output"
37
+
38
+ option :long_output,
39
+ short: "-l",
40
+ long: "--long",
41
+ boolean: true,
42
+ default: false,
43
+ description: "Include all attributes in the output"
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -23,31 +23,6 @@ class Chef
23
23
  class Knife
24
24
  module Core
25
25
 
26
- # This module may be included into a knife subcommand class to automatically
27
- # add configuration options used by the NodePresenter
28
- module NodeFormattingOptions
29
- # @private
30
- # Would prefer to do this in a rational way, but can't be done b/c of
31
- # Mixlib::CLI's design :(
32
- def self.included(includer)
33
- includer.class_eval do
34
- option :medium_output,
35
- short: "-m",
36
- long: "--medium",
37
- boolean: true,
38
- default: false,
39
- description: "Include normal attributes in the output"
40
-
41
- option :long_output,
42
- short: "-l",
43
- long: "--long",
44
- boolean: true,
45
- default: false,
46
- description: "Include all attributes in the output"
47
- end
48
- end
49
- end
50
-
51
26
  # A customized presenter for Chef::Node objects. Supports variable-length
52
27
  # output formats for displaying node data
53
28
  class NodePresenter < GenericPresenter
@@ -23,31 +23,6 @@ class Chef
23
23
  class Knife
24
24
  module Core
25
25
 
26
- # This module may be included into a knife subcommand class to automatically
27
- # add configuration options used by the StatusPresenter
28
- module StatusFormattingOptions
29
- # @private
30
- # Would prefer to do this in a rational way, but can't be done b/c of
31
- # Mixlib::CLI's design :(
32
- def self.included(includer)
33
- includer.class_eval do
34
- option :medium_output,
35
- short: "-m",
36
- long: "--medium",
37
- boolean: true,
38
- default: false,
39
- description: "Include normal attributes in the output"
40
-
41
- option :long_output,
42
- short: "-l",
43
- long: "--long",
44
- boolean: true,
45
- default: false,
46
- description: "Include all attributes in the output"
47
- end
48
- end
49
- end
50
-
51
26
  # A customized presenter for Chef::Node objects. Supports variable-length
52
27
  # output formats for displaying node data
53
28
  class StatusPresenter < GenericPresenter
@@ -67,7 +42,7 @@ class Chef
67
42
 
68
43
  result["name"] = node["name"] || node.name
69
44
  result["chef_environment"] = node["chef_environment"]
70
- ip = (node["cloud"] && node["cloud"]["public_ipv4_addrs"].first) || node["ipaddress"]
45
+ ip = (node["cloud"] && node["cloud"]["public_ipv4_addrs"]&.first) || node["ipaddress"]
71
46
  fqdn = (node["cloud"] && node["cloud"]["public_hostname"]) || node["fqdn"]
72
47
  result["ip"] = ip if ip
73
48
  result["fqdn"] = fqdn if fqdn
@@ -140,7 +140,7 @@ class Chef
140
140
  end
141
141
 
142
142
  unless trusted_certs_script.empty?
143
- client_rb << %Q{trusted_certs_dir "#{ChefConfig::Config.etc_chef_dir(windows: true)}/trusted_certs"\n}
143
+ client_rb << %Q{trusted_certs_dir "#{ChefConfig::PathHelper.escapepath(ChefConfig::Config.etc_chef_dir(windows: true))}\\\\trusted_certs"\n}
144
144
  end
145
145
 
146
146
  if chef_config[:fips]
@@ -18,13 +18,14 @@
18
18
 
19
19
  require_relative "../knife"
20
20
  require_relative "core/node_presenter"
21
+ require_relative "core/formatting_options"
21
22
  require "chef-utils/dist" unless defined?(ChefUtils::Dist)
22
23
 
23
24
  class Chef
24
25
  class Knife
25
26
  class NodeShow < Knife
26
27
 
27
- include Knife::Core::NodeFormattingOptions
28
+ include Knife::Core::FormattingOptions
28
29
  include Knife::Core::MultiAttributeReturnOption
29
30
 
30
31
  deps do
@@ -18,6 +18,7 @@
18
18
 
19
19
  require_relative "../knife"
20
20
  require_relative "core/node_presenter"
21
+ require_relative "core/formatting_options"
21
22
 
22
23
  class Chef
23
24
  class Knife
@@ -32,7 +33,7 @@ class Chef
32
33
  require_relative "../search/query"
33
34
  end
34
35
 
35
- include Knife::Core::NodeFormattingOptions
36
+ include Knife::Core::FormattingOptions
36
37
 
37
38
  banner "knife search INDEX QUERY (options)"
38
39
 
@@ -18,13 +18,13 @@
18
18
 
19
19
  require_relative "../knife"
20
20
  require_relative "core/status_presenter"
21
- require_relative "core/node_presenter"
21
+ require_relative "core/formatting_options"
22
22
  require "chef-utils/dist" unless defined?(ChefUtils::Dist)
23
23
 
24
24
  class Chef
25
25
  class Knife
26
26
  class Status < Knife
27
- include Knife::Core::NodeFormattingOptions
27
+ include Knife::Core::FormattingOptions
28
28
 
29
29
  deps do
30
30
  require_relative "../search/query"
@@ -68,11 +68,11 @@ class Chef
68
68
  append_to_query("chef_environment:#{config[:environment]}") if config[:environment]
69
69
 
70
70
  if config[:hide_by_mins]
71
- hidemins = config[:hide_by_mins].to_i
71
+ hide_by_mins = config[:hide_by_mins].to_i
72
72
  time = Time.now.to_i
73
73
  # AND NOT is not valid lucene syntax, so don't use append_to_query
74
74
  @query << " " unless @query.empty?
75
- @query << "NOT ohai_time:[#{(time - hidemins * 60)} TO #{time}]"
75
+ @query << "NOT ohai_time:[#{(time - hide_by_mins * 60)} TO #{time}]"
76
76
  end
77
77
 
78
78
  @query = @query.empty? ? "*:*" : @query
@@ -84,13 +84,10 @@ class Chef
84
84
  all_nodes << node
85
85
  end
86
86
 
87
- output(all_nodes.sort do |n1, n2|
88
- if config[:sort_reverse] || config[:sort_status_reverse]
89
- (n2["ohai_time"] || 0) <=> (n1["ohai_time"] || 0)
90
- else
91
- (n1["ohai_time"] || 0) <=> (n2["ohai_time"] || 0)
92
- end
93
- end)
87
+ all_nodes.sort_by! { |n| n["ohai_time"] || 0 }
88
+ all_nodes.reverse! if config[:sort_reverse] || config[:sort_status_reverse]
89
+
90
+ output(all_nodes)
94
91
  end
95
92
 
96
93
  end