Skip to content

Commit

Permalink
Adds useragent
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruairi Fennell committed Aug 20, 2018
1 parent 713289d commit 591f329
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 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
response = rest_client.get(*args).body # rest.get

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_client.get( #rest.get
"/#{tenant_id}/#{next_link}",
params: { 'api-version' => '1.6' },
).body
Expand Down
15 changes: 15 additions & 0 deletions libraries/support/azure/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

module Azure
class Rest

INSPEC_USER_AGENT = 'Chef-Inspec-pid-18d63047-6cdf-4f34-beed-62f01fc73fc2'
private_constant :INSPEC_USER_AGENT

attr_reader :host, :resource, :credentials

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

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

add_user_agent!(headers)
connection.get do |req|
req.url path

Expand Down Expand Up @@ -45,5 +51,14 @@ def authorization_header
)
@authentication.authentication_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)
else
headers[:user_agent] = current_user_agent + "; #{INSPEC_USER_AGENT}"
end
end
end
end
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
body = rest_client.get(url, params: { 'api-version' => api_version }).body # rest.get
body.fetch('value', body)
end
end
Expand Down

0 comments on commit 591f329

Please sign in to comment.