Module: Chef::Telemetry::Decision

Defined in:
lib/chef/telemetry/decision.rb

Constant Summary collapse

OPT_OUT_FILE =
"telemetry_opt_out".freeze
OPT_IN_FILE =
"telemetry_opt_in".freeze

Class Method Summary collapse

Class Method Details

.env_opt_out?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/chef/telemetry/decision.rb', line 30

def env_opt_out?
  ENV.key?("CHEF_TELEMETRY_OPT_OUT")
end

.local_opt_out?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/chef/telemetry/decision.rb', line 34

def local_opt_out?
  found = false
  full_path = working_directory.split(File::SEPARATOR)
  (full_path.length - 1).downto(0) do |i|
    candidate = File.join(full_path[0..i], ".chef", OPT_OUT_FILE)
    if File.exist?(candidate)
      # TODO: push up logging
      # Log.info "Found opt out at: #{candidate}"
      found = true
      break
    end
  end
  found
end

.made?Boolean

Check whether the user has made an explicit decision on their participation.

Returns:

  • (Boolean)


18
19
20
# File 'lib/chef/telemetry/decision.rb', line 18

def made?
  user_opted_in? || user_opted_out?
end

.opt_out?Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/chef/telemetry/decision.rb', line 12

def opt_out?
  # We check that the user has made a decision so that we can have a default setting for robots
  user_opted_out? || env_opt_out? || local_opt_out? || !made?
end

.user_opted_in?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/chef/telemetry/decision.rb', line 26

def user_opted_in?
  File.exist?(File.join(home, OPT_IN_FILE))
end

.user_opted_out?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/chef/telemetry/decision.rb', line 22

def user_opted_out?
  File.exist?(File.join(home, OPT_OUT_FILE))
end