summaryrefslogtreecommitdiff
path: root/chef-utils/lib
diff options
context:
space:
mode:
Diffstat (limited to 'chef-utils/lib')
-rw-r--r--chef-utils/lib/chef-utils.rb3
-rw-r--r--chef-utils/lib/chef-utils/dsl/default_paths.rb59
-rw-r--r--chef-utils/lib/chef-utils/dsl/path_sanity.rb29
3 files changed, 65 insertions, 26 deletions
diff --git a/chef-utils/lib/chef-utils.rb b/chef-utils/lib/chef-utils.rb
index 43058f6fe3..c1b06ed3fb 100644
--- a/chef-utils/lib/chef-utils.rb
+++ b/chef-utils/lib/chef-utils.rb
@@ -19,6 +19,7 @@ require_relative "chef-utils/dsl/architecture"
require_relative "chef-utils/dsl/cloud"
require_relative "chef-utils/dsl/introspection"
require_relative "chef-utils/dsl/os"
+require_relative "chef-utils/dsl/default_paths"
require_relative "chef-utils/dsl/path_sanity"
require_relative "chef-utils/dsl/platform"
require_relative "chef-utils/dsl/platform_family"
@@ -34,9 +35,9 @@ require_relative "chef-utils/mash"
module ChefUtils
include ChefUtils::DSL::Architecture
include ChefUtils::DSL::Cloud
+ include ChefUtils::DSL::DefaultPaths
include ChefUtils::DSL::Introspection
include ChefUtils::DSL::OS
- include ChefUtils::DSL::PathSanity
include ChefUtils::DSL::Platform
include ChefUtils::DSL::PlatformFamily
include ChefUtils::DSL::PlatformVersion
diff --git a/chef-utils/lib/chef-utils/dsl/default_paths.rb b/chef-utils/lib/chef-utils/dsl/default_paths.rb
new file mode 100644
index 0000000000..f18bd93157
--- /dev/null
+++ b/chef-utils/lib/chef-utils/dsl/default_paths.rb
@@ -0,0 +1,59 @@
+#
+# Copyright:: Copyright (c) Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require_relative "../internal"
+require_relative "platform_family"
+
+module ChefUtils
+ module DSL
+ module DefaultPaths
+ include Internal
+
+ # @since 15.5
+ def default_paths(env = nil)
+ env_path = env ? env["PATH"] : __env_path
+ env_path = "" if env_path.nil?
+ path_separator = ChefUtils.windows? ? ";" : ":"
+ # ensure the Ruby and Gem bindirs are included for omnibus chef installs
+ new_paths = env_path.split(path_separator)
+ [ __ruby_bindir, __gem_bindir ].compact.each do |path|
+ new_paths = [ path ] + new_paths unless new_paths.include?(path)
+ end
+ __default_paths.each do |path|
+ new_paths << path unless new_paths.include?(path)
+ end
+ new_paths.join(path_separator).encode("utf-8", invalid: :replace, undef: :replace)
+ end
+
+ private
+
+ def __default_paths
+ ChefUtils.windows? ? %w{} : %w{/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin}
+ end
+
+ def __ruby_bindir
+ RbConfig::CONFIG["bindir"]
+ end
+
+ def __gem_bindir
+ Gem.bindir
+ end
+
+ extend self
+ end
+ end
+end
diff --git a/chef-utils/lib/chef-utils/dsl/path_sanity.rb b/chef-utils/lib/chef-utils/dsl/path_sanity.rb
index 921c666124..1fbfbdccf3 100644
--- a/chef-utils/lib/chef-utils/dsl/path_sanity.rb
+++ b/chef-utils/lib/chef-utils/dsl/path_sanity.rb
@@ -15,42 +15,21 @@
# limitations under the License.
#
-require_relative "../internal"
-require_relative "platform_family"
+require_relative "default_paths"
module ChefUtils
module DSL
module PathSanity
- include Internal
+ include ChefUtils::DSL::DefaultPaths
- # @since 15.5
def sanitized_path(env = nil)
- env_path = env ? env["PATH"] : __env_path
- env_path = "" if env_path.nil?
- path_separator = ChefUtils.windows? ? ";" : ":"
- # ensure the Ruby and Gem bindirs are included for omnibus chef installs
- new_paths = env_path.split(path_separator)
- [ __ruby_bindir, __gem_bindir ].compact.each do |path|
- new_paths = [ path ] + new_paths unless new_paths.include?(path)
- end
- __sane_paths.each do |path|
- new_paths << path unless new_paths.include?(path)
- end
- new_paths.join(path_separator).encode("utf-8", invalid: :replace, undef: :replace)
+ default_paths(env)
end
private
def __sane_paths
- ChefUtils.windows? ? %w{} : %w{/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin}
- end
-
- def __ruby_bindir
- RbConfig::CONFIG["bindir"]
- end
-
- def __gem_bindir
- Gem.bindir
+ __default_paths
end
extend self