module Inspec::InstallContextHelpers
Heuristics to determine how InSpec was installed.
Public Instance Methods
guess_install_context()
click to toggle source
# File lib/inspec/utils/install_context.rb, line 6 def guess_install_context # These all work by simple path recognition return "chef-workstation" if chef_workstation_install? return "omnibus" if omnibus_install? return "chefdk" if chefdk_install? return "habitat" if habitat_install? # Order matters here - gem mode is easily mistaken for one of the above return "docker" if docker_install? return "rubygem" if rubygem_install? return "source" if source_install? "unknown" end
Private Instance Methods
chef_workstation_install?()
click to toggle source
# File lib/inspec/utils/install_context.rb, line 24 def chef_workstation_install? !!(src_root.start_with?("/opt/chef-workstation") || src_root.start_with?("C:/opscode/chef-workstation")) end
chefdk_install?()
click to toggle source
# File lib/inspec/utils/install_context.rb, line 28 def chefdk_install? !!(src_root.start_with?("/opt/chef-dk") || src_root.start_with?("C:/opscode/chef-dk")) end
docker_install?()
click to toggle source
# File lib/inspec/utils/install_context.rb, line 32 def docker_install? # Our docker image is based on alpine. This could be easily fooled. !!(rubygem_install? && path_exist?("/etc/alpine-release")) && path_exist?("/.dockerenv") end
habitat_install?()
click to toggle source
# File lib/inspec/utils/install_context.rb, line 37 def habitat_install? !!src_root.match(%r{hab/pkgs/chef/inspec/\d+\.\d+\.\d+/\d{14}}) end
omnibus_install?()
click to toggle source
# File lib/inspec/utils/install_context.rb, line 41 def omnibus_install? !!(src_root.start_with?("/opt/inspec") || src_root.start_with?("C:/opscode/inspec")) end
path_exist?(path)
click to toggle source
# File lib/inspec/utils/install_context.rb, line 56 def path_exist?(path) File.exist? path end
rubygem_install?()
click to toggle source
# File lib/inspec/utils/install_context.rb, line 45 def rubygem_install? !!src_root.match(%r{gems/inspec-\d+\.\d+\.\d+}) end
source_install?()
click to toggle source
# File lib/inspec/utils/install_context.rb, line 49 def source_install? # These are a couple of examples of dirs removed during packaging %w{habitat test}.all? do |devdir| path_exist?("#{src_root}/#{devdir}") end end