Skip to content

Commit

Permalink
fixes issue with user-agent being overwritten by sensor version (Crow…
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmmatos authored May 15, 2023
1 parent 0b2e017 commit 1576a4c
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions libraries/falconapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FalconApi
attr_accessor :bearer_token
attr_accessor :update_policy
attr_accessor :platform_name
attr_accessor :version
attr_accessor :cookbook_version

# Initialize a new FalconApi instance.
# - falcon_cloud - the name of the falcon cloud to use.
Expand All @@ -40,7 +40,7 @@ def initialize(falcon_cloud: nil, bearer_token: nil, client_id: nil, client_secr
end
@client_id = client_id
@client_secret = client_secret
@version = '0.1.1'
@cookbook_version = '0.1.2'
end

# Returns the version of the sensor installer for the given policy and platform name.
Expand All @@ -53,7 +53,7 @@ def version_from_update_policy(update_policy = @update_policy, platform_name = @
request = Net::HTTP::Get.new(url_path)
request['Content-Type'] = 'application/json'
request['Authorization'] = "Bearer #{@bearer_token}"
request['User-Agent'] = "crowdstrike-chef/#{@version}"
request['User-Agent'] = "crowdstrike-chef/#{@cookbook_version}"

resp = @http_client.request(request)

Expand All @@ -72,8 +72,7 @@ def version_from_update_policy(update_policy = @update_policy, platform_name = @
raise
end

@version = body['resources'][0]['settings']['sensor_version']
version
body['resources'][0]['settings']['sensor_version']
else
Chef::Log.error(sanitize_error_message("Falcon API error when calling #{url_path} - #{resp.code} #{resp.message} #{resp.body}"))
raise
Expand All @@ -91,7 +90,7 @@ def falcon_installers(query)
request = Net::HTTP::Get.new(url_path)
request['Content-Type'] = 'application/json'
request['Authorization'] = "Bearer #{@bearer_token}"
request['User-Agent'] = "crowdstrike-chef/#{@version}"
request['User-Agent'] = "crowdstrike-chef/#{@cookbook_version}"

resp = @http_client.request(request)

Expand Down Expand Up @@ -120,7 +119,7 @@ def download_installer(sha256, out_path)
request = Net::HTTP::Get.new(url_path)
request['Content-Type'] = 'application/json'
request['Authorization'] = "Bearer #{@bearer_token}"
request['User-Agent'] = "crowdstrike-chef/#{@version}"
request['User-Agent'] = "crowdstrike-chef/#{@cookbook_version}"

resp = @http_client.request(request)

Expand Down Expand Up @@ -166,7 +165,7 @@ def access_token(client_id, client_secret)

request = Net::HTTP::Post.new(url_path)
request['Content-Type'] = 'application/x-www-form-urlencoded'
request['User-Agent'] = "crowdstrike-chef/#{@version}"
request['User-Agent'] = "crowdstrike-chef/#{@cookbook_version}"
request.body = URI.encode_www_form(req_body)

resp = @http_client.request(request)
Expand Down

0 comments on commit 1576a4c

Please sign in to comment.