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

Instance Method Details

#chef_workstation_install?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/inspec/utils/install_context.rb', line 21

def chef_workstation_install?
  !!(src_root.start_with?("/opt/chef-workstation") || src_root.start_with?("C:/opscode/chef-workstation"))
end

#chefdk_install?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/inspec/utils/install_context.rb', line 25

def chefdk_install?
  !!(src_root.start_with?("/opt/chef-dk") || src_root.start_with?("C:/opscode/chef-dk"))
end

#docker_install?Boolean

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/inspec/utils/install_context.rb', line 29

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_contextObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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 "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

Returns:

  • (Boolean)


34
35
36
# File 'lib/inspec/utils/install_context.rb', line 34

def habitat_install?
  !!src_root.match(%r{hab/pkgs/chef/inspec/\d+\.\d+\.\d+/\d{14}})
end

#path_exist?(path) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/inspec/utils/install_context.rb', line 49

def path_exist?(path)
  File.exist? path
end

#rubygem_install?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/inspec/utils/install_context.rb', line 38

def rubygem_install?
  !!src_root.match(%r{gems/inspec-\d+\.\d+\.\d+})
end

#source_install?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
# File 'lib/inspec/utils/install_context.rb', line 42

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