From e11b70eeb1546462f93afc126c27ed32a17b52d1 Mon Sep 17 00:00:00 2001 From: Ruairi Fennell Date: Mon, 20 Aug 2018 17:36:50 +0100 Subject: [PATCH] Adds User-Agent Signed-off-by: Ruairi Fennell --- libraries/support/azure/graph.rb | 4 ++-- libraries/support/azure/rest.rb | 13 ++++++------- libraries/support/azure/service.rb | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/libraries/support/azure/graph.rb b/libraries/support/azure/graph.rb index ed5f88cf8..83c0309c3 100644 --- a/libraries/support/azure/graph.rb +++ b/libraries/support/azure/graph.rb @@ -38,7 +38,7 @@ def get(*args) confirm_configured! values = [] - response = rest_client.get(*args).body # rest.get + response = rest_client.get(*args).body if response.key?('odata.error') raise Inspec::Exceptions::ResourceFailed, format_error(response['odata.error']) @@ -65,7 +65,7 @@ def get(*args) end def next_results(next_link) - rest_client.get( #rest.get + rest_client.get( "/#{tenant_id}/#{next_link}", params: { 'api-version' => '1.6' }, ).body diff --git a/libraries/support/azure/rest.rb b/libraries/support/azure/rest.rb index 382f3fc1c..86109b961 100644 --- a/libraries/support/azure/rest.rb +++ b/libraries/support/azure/rest.rb @@ -5,9 +5,9 @@ module Azure class Rest - + USER_AGENT = 'User-Agent' INSPEC_USER_AGENT = 'Chef-Inspec-pid-18d63047-6cdf-4f34-beed-62f01fc73fc2' - private_constant :INSPEC_USER_AGENT + private_constant :USER_AGENT, :INSPEC_USER_AGENT attr_reader :host, :resource, :credentials @@ -19,7 +19,6 @@ def initialize(client) end def get(path, params: {}, headers: {}) - add_user_agent!(headers) connection.get do |req| req.url path @@ -53,11 +52,11 @@ def authorization_header end def add_user_agent!(headers) - current_user_agent = headers.fetch(:user_agent, nil) - if current_user_agent == nil - headers.store(:user_agent => INSPEC_USER_AGENT) + current_user_agent = headers.fetch(USER_AGENT, nil) + if current_user_agent.nil? + headers[USER_AGENT] = INSPEC_USER_AGENT else - headers[:user_agent] = current_user_agent + "; #{INSPEC_USER_AGENT}" + headers[USER_AGENT] = current_user_agent + "; #{INSPEC_USER_AGENT}" end end end diff --git a/libraries/support/azure/service.rb b/libraries/support/azure/service.rb index 0054040c7..33f1955bd 100644 --- a/libraries/support/azure/service.rb +++ b/libraries/support/azure/service.rb @@ -56,7 +56,7 @@ def get(url:, api_version:) confirm_configured! cache.fetch(url) do - body = rest_client.get(url, params: { 'api-version' => api_version }).body # rest.get + body = rest_client.get(url, params: { 'api-version' => api_version }).body body.fetch('value', body) end end