Module: Inspec::InstallContextHelpers
- Included in:
- Inspec
- Defined in:
- lib/inspec/utils/install_context.rb
Overview
Heuristics to determine how InSpec was installed.
Instance Method Summary collapse
- #chef_workstation_install? ⇒ Boolean
- #chefdk_install? ⇒ Boolean
- #docker_install? ⇒ Boolean
- #guess_install_context ⇒ Object
- #habitat_install? ⇒ Boolean
- #omnibus_install? ⇒ Boolean
- #path_exist?(path) ⇒ Boolean
- #rubygem_install? ⇒ Boolean
- #source_install? ⇒ Boolean
Instance Method Details
#chef_workstation_install? ⇒ Boolean
22 23 24 |
# File 'lib/inspec/utils/install_context.rb', line 22 def chef_workstation_install? !!(src_root.start_with?("/opt/chef-workstation") || src_root.start_with?("C:/opscode/chef-workstation")) end |
#chefdk_install? ⇒ Boolean
26 27 28 |
# File 'lib/inspec/utils/install_context.rb', line 26 def chefdk_install? !!(src_root.start_with?("/opt/chef-dk") || src_root.start_with?("C:/opscode/chef-dk")) end |
#docker_install? ⇒ Boolean
30 31 32 33 |
# File 'lib/inspec/utils/install_context.rb', line 30 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 |
#guess_install_context ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# 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 |
#habitat_install? ⇒ Boolean
35 36 37 |
# File 'lib/inspec/utils/install_context.rb', line 35 def habitat_install? !!src_root.match(%r{hab/pkgs/chef/inspec/\d+\.\d+\.\d+/\d{14}}) end |
#omnibus_install? ⇒ Boolean
39 40 41 |
# File 'lib/inspec/utils/install_context.rb', line 39 def omnibus_install? !!(src_root.start_with?("/opt/inspec") || src_root.start_with?("C:/opscode/inspec")) end |
#path_exist?(path) ⇒ Boolean
54 55 56 |
# File 'lib/inspec/utils/install_context.rb', line 54 def path_exist?(path) File.exist? path end |
#rubygem_install? ⇒ Boolean
43 44 45 |
# File 'lib/inspec/utils/install_context.rb', line 43 def rubygem_install? !!src_root.match(%r{gems/inspec-\d+\.\d+\.\d+}) end |
#source_install? ⇒ Boolean
47 48 49 50 51 52 |
# File 'lib/inspec/utils/install_context.rb', line 47 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 |