From ea0643cc144c17764907bae4e16c9507c1de7361 Mon Sep 17 00:00:00 2001 From: Miah Johnson Date: Tue, 7 May 2019 19:04:51 -0700 Subject: [PATCH] Handle load_config better private method to minimize external interface default enabled to false if unable to find setting in configuration add reader for config Signed-off-by: Miah Johnson --- lib/inspec/utils/telemetry/collector.rb | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/inspec/utils/telemetry/collector.rb b/lib/inspec/utils/telemetry/collector.rb index 198f4b234..85b081f10 100644 --- a/lib/inspec/utils/telemetry/collector.rb +++ b/lib/inspec/utils/telemetry/collector.rb @@ -7,6 +7,8 @@ module Inspec::Telemetry class Collector include Singleton + attr_reader :config + def initialize @data_series = [] load_config @@ -23,15 +25,11 @@ module Inspec::Telemetry @data_series << data_series end - # Is the Telemetry system enabled or disabled? - # Always true until we add configuration parsing. + # The loaded configuration should have a option to configure + # telemetry, if not default to false. # @return [True, False] def telemetry_enabled? - if @config.telemetry_enabled?.nil? - @enabled = true - else - @enabled = @config.telemetry_enabled? - end + config_telemetry_options.fetch("enable_telemetry", false) end # A way to disable the telemetry system. @@ -66,5 +64,12 @@ module Inspec::Telemetry def reset @data_series = [] end + + private + + # Minimize exposure of Inspec::Config interface + def config_telemetry_options + config.telemetry_options + end end end