Skip to content

Commit

Permalink
Adds User-Agent
Browse files Browse the repository at this point in the history
Signed-off-by: Ruairi Fennell <rfennell@chef.io>
  • Loading branch information
Ruairi Fennell committed Aug 20, 2018
1 parent 591f329 commit e11b70e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions libraries/support/azure/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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
Expand Down
13 changes: 6 additions & 7 deletions libraries/support/azure/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -19,7 +19,6 @@ def initialize(client)
end

def get(path, params: {}, headers: {})

add_user_agent!(headers)
connection.get do |req|
req.url path
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libraries/support/azure/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e11b70e

Please sign in to comment.