chef-utils 16.2.73 → 16.3.38
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/chef-utils.gemspec +1 -2
- data/lib/chef-utils.rb +2 -1
- data/lib/chef-utils/dsl/default_paths.rb +59 -0
- data/lib/chef-utils/dsl/path_sanity.rb +6 -27
- data/lib/chef-utils/dsl/service.rb +3 -2
- data/lib/chef-utils/internal.rb +39 -3
- data/lib/chef-utils/version.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/dsl/introspection_spec.rb +1 -0
- data/spec/unit/dsl/path_sanity_spec.rb +14 -14
- data/spec/unit/dsl/platform_spec.rb +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f5b96fe6160526b332bbb97dd82753a024e239478257753052287f5a91b2239
|
4
|
+
data.tar.gz: 5b8504937acdb70a72818d139c60eb760da04be5c8238b172a9c76a02b945bda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfd59cb093364785edc3ddb3261f792c9d13a6e63cfbf2ef3abaee879a020fcbcf913d47b4a93f6bcb59b77887638cad5342bd93db8bea625d087bfaf2e6afcf
|
7
|
+
data.tar.gz: 36faef376d1e3439bcfb743c48aea0b19e466461ee238706429058f11eabcfdf76ebdcf3d396867fe349c5beb78f0853e209e35f5c76a854cd9ff50075ca246a
|
data/chef-utils.gemspec
CHANGED
data/lib/chef-utils.rb
CHANGED
@@ -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 "
|
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
|
23
|
+
include ChefUtils::DSL::DefaultPaths
|
25
24
|
|
26
|
-
# @since 15.5
|
27
25
|
def sanitized_path(env = nil)
|
28
|
-
|
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
|
-
|
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
|
-
|
48
|
-
|
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
|
-
|
101
|
-
|
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
|
data/lib/chef-utils/internal.rb
CHANGED
@@ -40,11 +40,18 @@ module ChefUtils
|
|
40
40
|
|
41
41
|
private
|
42
42
|
|
43
|
-
#
|
44
|
-
#
|
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
|
data/lib/chef-utils/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -17,9 +17,9 @@
|
|
17
17
|
|
18
18
|
require "spec_helper"
|
19
19
|
|
20
|
-
RSpec.describe ChefUtils::DSL::
|
21
|
-
class
|
22
|
-
include ChefUtils::DSL::
|
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) {
|
35
|
+
let(:test_instance) { DefaultPathsTestClass.new }
|
36
36
|
|
37
37
|
it "works with no path" do
|
38
38
|
env = {}
|
39
|
-
expect(test_instance.
|
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.
|
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.
|
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
|
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.
|
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) {
|
63
|
+
let(:test_instance) { DefaultPathsTestClass.new }
|
64
64
|
|
65
65
|
it "works with no path" do
|
66
66
|
env = {}
|
67
|
-
expect(test_instance.
|
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.
|
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.
|
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.
|
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.
|
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-
|
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
|