summaryrefslogtreecommitdiff
path: root/lib/chef/node.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-03-11 11:49:31 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2019-03-11 11:49:31 -0700
commit66015ba654469f4dacfd78d40b02aafee52bbf1b (patch)
treeb00d0de111d18980f446b006ac63ef599eea8108 /lib/chef/node.rb
parent4037976199b728d4bdc18fd428e8d40a84c97e2b (diff)
downloadchef-66015ba654469f4dacfd78d40b02aafee52bbf1b.tar.gz
Extract Action Collection from Data Collector
See the PR for details on this change. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/node.rb')
-rw-r--r--lib/chef/node.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index 87418b5732..9b67f27f14 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -2,7 +2,7 @@
# Author:: Christopher Brown (<cb@chef.io>)
# Author:: Christopher Walters (<cw@chef.io>)
# Author:: Tim Hinderliter (<tim@chef.io>)
-# Copyright:: Copyright 2008-2018, Chef Software Inc.
+# Copyright:: Copyright 2008-2019, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,6 +19,7 @@
#
require "forwardable"
+require "securerandom"
require "chef/config"
require "chef/nil_argument"
require "chef/mixin/params_validate"
@@ -338,7 +339,7 @@ class Chef
logger.debug("Platform is #{platform} version #{version}")
automatic[:platform] = platform
automatic[:platform_version] = version
- automatic[:chef_guid] = Chef::Config[:chef_guid]
+ automatic[:chef_guid] = Chef::Config[:chef_guid] || ( Chef::Config[:chef_guid] = node_uuid )
automatic[:name] = name
automatic[:chef_environment] = chef_environment
end
@@ -687,5 +688,24 @@ class Chef
data
end
+ # Returns a UUID that uniquely identifies this node for reporting reasons.
+ #
+ # The node is read in from disk if it exists, or it's generated if it does
+ # does not exist.
+ #
+ # @return [String] UUID for the node
+ #
+ def node_uuid
+ path = File.expand_path(Chef::Config[:chef_guid_path])
+ dir = File.dirname(path)
+
+ unless File.exists?(path)
+ FileUtils.mkdir_p(dir)
+ File.write(path, SecureRandom.uuid)
+ end
+
+ File.open(path).first.chomp
+ end
+
end
end