Module: Bolt::Analytics
- Defined in:
- lib/bolt/analytics.rb
Defined Under Namespace
Classes: Client, NoopClient
Constant Summary
collapse
- PROTOCOL_VERSION =
1
- APPLICATION_NAME =
'bolt'
- TRACKING_ID =
'UA-120367942-1'
- TRACKING_URL =
'https://google-analytics.com/collect'
- CUSTOM_DIMENSIONS =
{
operating_system: :cd1,
inventory_nodes: :cd2,
inventory_groups: :cd3,
target_nodes: :cd4,
output_format: :cd5,
statement_count: :cd6,
resource_mean: :cd7,
plan_steps: :cd8,
return_type: :cd9
}.freeze
Class Method Summary
collapse
Class Method Details
.build_client ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/bolt/analytics.rb', line 27
def self.build_client
logger = Logging.logger[self]
config_file = File.expand_path('~/.puppetlabs/bolt/analytics.yaml')
config = load_config(config_file)
if config['disabled'] || ENV['BOLT_DISABLE_ANALYTICS']
logger.debug "Analytics opt-out is set, analytics will be disabled"
NoopClient.new
else
unless config.key?('user-id')
config['user-id'] = SecureRandom.uuid
write_config(config_file, config)
end
Client.new(config['user-id'])
end
rescue StandardError => e
logger.debug "Failed to initialize analytics client, analytics will be disabled: #{e}"
NoopClient.new
end
|
.load_config(filename) ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/bolt/analytics.rb', line 48
def self.load_config(filename)
if File.exist?(filename)
YAML.load_file(filename)
else
{}
end
end
|
.write_config(filename, config) ⇒ Object
56
57
58
59
|
# File 'lib/bolt/analytics.rb', line 56
def self.write_config(filename, config)
FileUtils.mkdir_p(File.dirname(filename))
File.write(filename, config.to_yaml)
end
|