chef-utils 16.2.73 → 16.3.38

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 712ce0c1f706df8363d83df9037b09a162df620cdf2de3712184fb0d221fb725
4
- data.tar.gz: 65af39a0822945d9abf808c01823c80e405375d75111e6badded36283f3ea0e3
3
+ metadata.gz: 9f5b96fe6160526b332bbb97dd82753a024e239478257753052287f5a91b2239
4
+ data.tar.gz: 5b8504937acdb70a72818d139c60eb760da04be5c8238b172a9c76a02b945bda
5
5
  SHA512:
6
- metadata.gz: 1ed1b71c80a160ca0c1ca290d34988bd85b878f703d4f33359fafe01f8a4197099d5e7c636f7812dded42a76e0a58d3c7b907a634a5a0a6882ca0cd5d6fdf943
7
- data.tar.gz: b2a1e1baee866d6a68ba29e8cdb20aa08cb7c66af92a8afe8f75c0a33776a0457511a25c786d785a35d23c39933f56ad2ef20779b62a26f3ed83ae4728c3f8bb
6
+ metadata.gz: dfd59cb093364785edc3ddb3261f792c9d13a6e63cfbf2ef3abaee879a020fcbcf913d47b4a93f6bcb59b77887638cad5342bd93db8bea625d087bfaf2e6afcf
7
+ data.tar.gz: 36faef376d1e3439bcfb743c48aea0b19e466461ee238706429058f11eabcfdf76ebdcf3d396867fe349c5beb78f0853e209e35f5c76a854cd9ff50075ca246a
@@ -1,5 +1,4 @@
1
- # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require "chef-utils/version"
5
4
 
@@ -19,6 +19,7 @@ require_relative "chef-utils/dsl/architecture"
19
19
  require_relative "chef-utils/dsl/cloud"
20
20
  require_relative "chef-utils/dsl/introspection"
21
21
  require_relative "chef-utils/dsl/os"
22
+ require_relative "chef-utils/dsl/default_paths"
22
23
  require_relative "chef-utils/dsl/path_sanity"
23
24
  require_relative "chef-utils/dsl/platform"
24
25
  require_relative "chef-utils/dsl/platform_family"
@@ -34,9 +35,9 @@ require_relative "chef-utils/mash"
34
35
  module ChefUtils
35
36
  include ChefUtils::DSL::Architecture
36
37
  include ChefUtils::DSL::Cloud
38
+ include ChefUtils::DSL::DefaultPaths
37
39
  include ChefUtils::DSL::Introspection
38
40
  include ChefUtils::DSL::OS
39
- include ChefUtils::DSL::PathSanity
40
41
  include ChefUtils::DSL::Platform
41
42
  include ChefUtils::DSL::PlatformFamily
42
43
  include ChefUtils::DSL::PlatformVersion
@@ -0,0 +1,59 @@
1
+ #
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require_relative "../internal"
19
+ require_relative "platform_family"
20
+
21
+ module ChefUtils
22
+ module DSL
23
+ module DefaultPaths
24
+ include Internal
25
+
26
+ # @since 15.5
27
+ def default_paths(env = nil)
28
+ env_path = env ? env["PATH"] : __env_path
29
+ env_path = "" if env_path.nil?
30
+ path_separator = ChefUtils.windows? ? ";" : ":"
31
+ # ensure the Ruby and Gem bindirs are included for omnibus chef installs
32
+ new_paths = env_path.split(path_separator)
33
+ [ __ruby_bindir, __gem_bindir ].compact.each do |path|
34
+ new_paths = [ path ] + new_paths unless new_paths.include?(path)
35
+ end
36
+ __default_paths.each do |path|
37
+ new_paths << path unless new_paths.include?(path)
38
+ end
39
+ new_paths.join(path_separator).encode("utf-8", invalid: :replace, undef: :replace)
40
+ end
41
+
42
+ private
43
+
44
+ def __default_paths
45
+ ChefUtils.windows? ? %w{} : %w{/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin}
46
+ end
47
+
48
+ def __ruby_bindir
49
+ RbConfig::CONFIG["bindir"]
50
+ end
51
+
52
+ def __gem_bindir
53
+ Gem.bindir
54
+ end
55
+
56
+ extend self
57
+ end
58
+ end
59
+ end
@@ -15,42 +15,21 @@
15
15
  # limitations under the License.
16
16
  #
17
17
 
18
- require_relative "../internal"
19
- require_relative "platform_family"
18
+ require_relative "default_paths"
20
19
 
21
20
  module ChefUtils
22
21
  module DSL
23
22
  module PathSanity
24
- include Internal
23
+ include ChefUtils::DSL::DefaultPaths
25
24
 
26
- # @since 15.5
27
25
  def sanitized_path(env = nil)
28
- env_path = env ? env["PATH"] : __env_path
29
- env_path = "" if env_path.nil?
30
- path_separator = ChefUtils.windows? ? ";" : ":"
31
- # ensure the Ruby and Gem bindirs are included for omnibus chef installs
32
- new_paths = env_path.split(path_separator)
33
- [ ChefUtils::DSL::PathSanity.ruby_bindir, ChefUtils::DSL::PathSanity.gem_bindir ].compact.each do |path|
34
- new_paths = [ path ] + new_paths unless new_paths.include?(path)
35
- end
36
- ChefUtils::DSL::PathSanity.sane_paths.each do |path|
37
- new_paths << path unless new_paths.include?(path)
38
- end
39
- new_paths.join(path_separator).encode("utf-8", invalid: :replace, undef: :replace)
26
+ default_paths(env)
40
27
  end
41
28
 
42
- class << self
43
- def sane_paths
44
- ChefUtils.windows? ? %w{} : %w{/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin}
45
- end
29
+ private
46
30
 
47
- def ruby_bindir
48
- RbConfig::CONFIG["bindir"]
49
- end
50
-
51
- def gem_bindir
52
- Gem.bindir
53
- end
31
+ def __sane_paths
32
+ __default_paths
54
33
  end
55
34
 
56
35
  extend self
@@ -25,6 +25,7 @@ module ChefUtils
25
25
  module Service
26
26
  include Internal
27
27
  include TrainHelpers
28
+ include Introspection
28
29
 
29
30
  # Returns if debian's old rc.d manager is installed (not necessarily the primary init system).
30
31
  #
@@ -97,8 +98,8 @@ module ChefUtils
97
98
  file_exist?("/etc/rc.d/#{script}")
98
99
  when :systemd
99
100
  file_exist?("/etc/init.d/#{script}") ||
100
- ChefUtils::DSL::Introspection.has_systemd_service_unit?(script) ||
101
- ChefUtils::DSL::Introspection.has_systemd_unit?(script)
101
+ has_systemd_service_unit?(script) ||
102
+ has_systemd_unit?(script)
102
103
  else
103
104
  raise ArgumentError, "type of service must be one of :initd, :upstart, :xinetd, :etc_rcd, or :systemd"
104
105
  end
@@ -40,11 +40,18 @@ module ChefUtils
40
40
 
41
41
  private
42
42
 
43
- # FIXME: include a `__config` method so we can wire up Chef::Config automatically or allow other consumers to
44
- # inject a config hash without having to take a direct dep on the chef-config gem
45
-
43
+ # This should be set to a Chef::Node instance or to some Hash/Mash-like configuration object with the same keys. It needs to
44
+ # expose keys like `:os`, `:platform`, `:platform_version` and `:platform_family` at least to be useful. It will automatically
45
+ # pick up a `node` method when mixed into an object that has that as a method (which is the encouraged "public" API to use
46
+ # for dependency injection rather than overriding the method in this case.
47
+ #
48
+ # @return [Hash] hash-like config object
49
+ #
46
50
  # @api private
47
51
  def __getnode(skip_global = false)
52
+ # Software developers should feel free to rely on the default wiring here to the node method by implementing the node method in their
53
+ # own class. For anything more complicated they should completely override the method (overriding the whole method is never wrong and
54
+ # is safer).
48
55
  return node if respond_to?(:node) && node
49
56
 
50
57
  return run_context&.node if respond_to?(:run_context) && run_context&.node
@@ -56,7 +63,10 @@ module ChefUtils
56
63
  nil
57
64
  end
58
65
 
66
+ # Just a helper to pull the ENV["PATH"] in a train-independent way
67
+ #
59
68
  # @api private
69
+ #
60
70
  def __env_path
61
71
  if __transport_connection
62
72
  __transport_connection.run_command("echo $PATH").stdout || ""
@@ -65,13 +75,39 @@ module ChefUtils
65
75
  end
66
76
  end
67
77
 
78
+ # This should be set to a Train::Plugins::Transport instance. You should wire this up to nil for not using a train transport connection.
79
+ #
80
+ # @return [Train::Plugins::Transport]
81
+ #
68
82
  # @api private
83
+ #
69
84
  def __transport_connection
85
+ # Software consumers MUST override this method with their own implementation. The default behavior here is subject to change.
70
86
  return Chef.run_context.transport_connection if defined?(Chef) && Chef.respond_to?(:run_context) && Chef&.run_context&.transport_connection
71
87
 
72
88
  nil
73
89
  end
74
90
 
91
+ # This should be set to Chef::Config or to some Hash/Mash-like configuration object with the same keys. It must not be nil.
92
+ #
93
+ # @return [Hash] hash-like config object
94
+ #
95
+ # @api private
96
+ #
97
+ def __config
98
+ raise NotImplementedError
99
+ end
100
+
101
+ # This should be set to Chef::Log or something that duck-types like it. It must not be nil.
102
+ #
103
+ # @return [Chef::Log] logger-like logging object
104
+ #
105
+ # @api private
106
+ #
107
+ def __log
108
+ raise NotImplementedError
109
+ end
110
+
75
111
  extend self
76
112
  end
77
113
  end
@@ -14,6 +14,6 @@
14
14
  # limitations under the License.
15
15
 
16
16
  module ChefUtils
17
- CHEFUTILS_ROOT = File.expand_path("../..", __FILE__)
18
- VERSION = "16.2.73".freeze
17
+ CHEFUTILS_ROOT = File.expand_path("..", __dir__)
18
+ VERSION = "16.3.38".freeze
19
19
  end
@@ -6,7 +6,7 @@ HELPER_MODULES = [
6
6
  ChefUtils::DSL::Cloud,
7
7
  ChefUtils::DSL::Introspection,
8
8
  ChefUtils::DSL::OS,
9
- ChefUtils::DSL::PathSanity,
9
+ ChefUtils::DSL::DefaultPaths,
10
10
  ChefUtils::DSL::Platform,
11
11
  ChefUtils::DSL::PlatformFamily,
12
12
  ChefUtils::DSL::Service,
@@ -21,6 +21,7 @@ RSpec.describe ChefUtils::DSL::Introspection do
21
21
  class IntrospectionTestClass
22
22
  include ChefUtils::DSL::Introspection
23
23
  attr_accessor :node
24
+
24
25
  def initialize(node)
25
26
  @node = node
26
27
  end
@@ -17,9 +17,9 @@
17
17
 
18
18
  require "spec_helper"
19
19
 
20
- RSpec.describe ChefUtils::DSL::PathSanity do
21
- class PathSanityTestClass
22
- include ChefUtils::DSL::PathSanity
20
+ RSpec.describe ChefUtils::DSL::DefaultPaths do
21
+ class DefaultPathsTestClass
22
+ include ChefUtils::DSL::DefaultPaths
23
23
  end
24
24
 
25
25
  before do
@@ -32,26 +32,26 @@ RSpec.describe ChefUtils::DSL::PathSanity do
32
32
  allow(ChefUtils).to receive(:windows?).and_return(false)
33
33
  end
34
34
 
35
- let(:test_instance) { PathSanityTestClass.new }
35
+ let(:test_instance) { DefaultPathsTestClass.new }
36
36
 
37
37
  it "works with no path" do
38
38
  env = {}
39
- expect(test_instance.sanitized_path(env)).to eql("#{Gem.bindir}:#{RbConfig::CONFIG["bindir"]}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin")
39
+ expect(test_instance.default_paths(env)).to eql("#{Gem.bindir}:#{RbConfig::CONFIG["bindir"]}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin")
40
40
  end
41
41
 
42
42
  it "works with nil path" do
43
43
  env = { "PATH" => nil }
44
- expect(test_instance.sanitized_path(env)).to eql("#{Gem.bindir}:#{RbConfig::CONFIG["bindir"]}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin")
44
+ expect(test_instance.default_paths(env)).to eql("#{Gem.bindir}:#{RbConfig::CONFIG["bindir"]}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin")
45
45
  end
46
46
 
47
47
  it "works with empty path" do
48
48
  env = { "PATH" => "" }
49
- expect(test_instance.sanitized_path(env)).to eql("#{Gem.bindir}:#{RbConfig::CONFIG["bindir"]}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin")
49
+ expect(test_instance.default_paths(env)).to eql("#{Gem.bindir}:#{RbConfig::CONFIG["bindir"]}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin")
50
50
  end
51
51
 
52
- it "appends the sane_paths to the end of the path, preserving any that already exist, in the same order" do
52
+ it "appends the default_paths to the end of the path, preserving any that already exist, in the same order" do
53
53
  env = { "PATH" => "/bin:/opt/app/bin:/sbin" }
54
- expect(test_instance.sanitized_path(env)).to eql("#{Gem.bindir}:#{RbConfig::CONFIG["bindir"]}:/bin:/opt/app/bin:/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin")
54
+ expect(test_instance.default_paths(env)).to eql("#{Gem.bindir}:#{RbConfig::CONFIG["bindir"]}:/bin:/opt/app/bin:/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin")
55
55
  end
56
56
  end
57
57
 
@@ -60,26 +60,26 @@ RSpec.describe ChefUtils::DSL::PathSanity do
60
60
  allow(ChefUtils).to receive(:windows?).and_return(true)
61
61
  end
62
62
 
63
- let(:test_instance) { PathSanityTestClass.new }
63
+ let(:test_instance) { DefaultPathsTestClass.new }
64
64
 
65
65
  it "works with no path" do
66
66
  env = {}
67
- expect(test_instance.sanitized_path(env)).to eql("#{Gem.bindir};#{RbConfig::CONFIG["bindir"]}")
67
+ expect(test_instance.default_paths(env)).to eql("#{Gem.bindir};#{RbConfig::CONFIG["bindir"]}")
68
68
  end
69
69
 
70
70
  it "works with nil path" do
71
71
  env = { "PATH" => nil }
72
- expect(test_instance.sanitized_path(env)).to eql("#{Gem.bindir};#{RbConfig::CONFIG["bindir"]}")
72
+ expect(test_instance.default_paths(env)).to eql("#{Gem.bindir};#{RbConfig::CONFIG["bindir"]}")
73
73
  end
74
74
 
75
75
  it "works with empty path" do
76
76
  env = { "PATH" => "" }
77
- expect(test_instance.sanitized_path(env)).to eql("#{Gem.bindir};#{RbConfig::CONFIG["bindir"]}")
77
+ expect(test_instance.default_paths(env)).to eql("#{Gem.bindir};#{RbConfig::CONFIG["bindir"]}")
78
78
  end
79
79
 
80
80
  it "prepends to an existing path" do
81
81
  env = { "PATH" => '%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\\' }
82
- expect(test_instance.sanitized_path(env)).to eql("#{Gem.bindir};#{RbConfig::CONFIG["bindir"]};%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\")
82
+ expect(test_instance.default_paths(env)).to eql("#{Gem.bindir};#{RbConfig::CONFIG["bindir"]};%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\")
83
83
  end
84
84
  end
85
85
  end
@@ -58,6 +58,7 @@ RSpec.describe ChefUtils::DSL::Platform do
58
58
  class ThingWithANode
59
59
  include ChefUtils::DSL::Platform
60
60
  attr_accessor :node
61
+
61
62
  def initialize(node)
62
63
  @node = node
63
64
  end
@@ -69,6 +70,7 @@ RSpec.describe ChefUtils::DSL::Platform do
69
70
  attr_accessor :node
70
71
  end
71
72
  attr_accessor :run_context
73
+
72
74
  def initialize(node)
73
75
  @run_context = RunContext.new
74
76
  run_context.node = node
@@ -78,6 +80,7 @@ RSpec.describe ChefUtils::DSL::Platform do
78
80
  class ThingWithTheDSL
79
81
  include ChefUtils
80
82
  attr_accessor :node
83
+
81
84
  def initialize(node)
82
85
  @node = node
83
86
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.2.73
4
+ version: 16.3.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Software, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-01 00:00:00.000000000 Z
11
+ date: 2020-07-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -23,6 +23,7 @@ files:
23
23
  - lib/chef-utils.rb
24
24
  - lib/chef-utils/dsl/architecture.rb
25
25
  - lib/chef-utils/dsl/cloud.rb
26
+ - lib/chef-utils/dsl/default_paths.rb
26
27
  - lib/chef-utils/dsl/introspection.rb
27
28
  - lib/chef-utils/dsl/os.rb
28
29
  - lib/chef-utils/dsl/path_sanity.rb