diff options
author | Nathen Harvey <nathenharvey@google.com> | 2018-11-15 17:31:45 -0500 |
---|---|---|
committer | Nathen Harvey <nathenharvey@google.com> | 2018-11-15 17:40:37 -0500 |
commit | 1d7c86f15d027c4ba79e74dac5569e6ef2e00b2d (patch) | |
tree | 904382fae786808e900f7d98b07783ca8bce7d11 | |
parent | 5236aff74b8f2a2e9244cff4d325ccb4f73b3d69 (diff) | |
download | ohai-1d7c86f15d027c4ba79e74dac5569e6ef2e00b2d.tar.gz |
Set User-Agent in HTTP header for GCE plugin
Setting the User-Agent to `chef-ohai/VERSION` will correctly identify ohai as the application making a request to metadata.google.internal.
The previous User-Agent header was defaulting to
`User-Agent: Ruby`
It is now set to
`chef-ohai/14.6.2` where `14.6.2` is the value of `Ohai::VERSION`
Signed-off-by: Nathen Harvey <nathenharvey@google.com>
-rw-r--r-- | RELEASE_NOTES.md | 4 | ||||
-rw-r--r-- | lib/ohai/mixin/gce_metadata.rb | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index c6feab65..bfd31e51 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -2,6 +2,10 @@ This will be updated as the development of Ohai 15 progresses. +## Cloud Plugin Improvements + +The Google Compute Engine (GCE) plugin now identifies `chef-ohai` as the User-Agent making requests to the Google Cloud metadata server (metadata.google.internal). + # Ohai Release Notes 14.6 ## Filesystem Plugin on AIX and Solaris diff --git a/lib/ohai/mixin/gce_metadata.rb b/lib/ohai/mixin/gce_metadata.rb index f0f0ec22..929928c7 100644 --- a/lib/ohai/mixin/gce_metadata.rb +++ b/lib/ohai/mixin/gce_metadata.rb @@ -28,7 +28,11 @@ module Ohai def http_get(uri) conn = Net::HTTP.start(GCE_METADATA_ADDR) conn.read_timeout = 6 - conn.get(uri, { "Metadata-Flavor" => "Google" }) + conn.get(uri, { + "Metadata-Flavor" => "Google", + "User-Agent" => "chef-ohai/#{Ohai::VERSION}", + } + ) end def fetch_metadata(id = "") |