Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lib/bamboozled/api/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ def request(method, path, options = {})
method: method
}

strio = StringIO.new
log = Logger.new strio

httparty_options = {
query: options[:query],
body: options[:body],
format: :plain,
ssl_version: :TLSv1_2,
debug_output: log,
basic_auth: auth,
headers: {
"Accept" => "application/json",
Expand All @@ -36,6 +40,33 @@ def request(method, path, options = {})
case response.code
when 200..201
begin
if ENV.fetch('BAMBOO_REQUEST_LOGGING_ENBALED', false) == "true"
encoded_auth_to_remove = Base64.encode64("#{auth[:username]}:#{auth[:password]}").chomp

employee_number_match = /(employeeNumber\D*)(\d*)/.match(httparty_options[:body])
employee_number = employee_number_match[2].presence if employee_number_match.present?

work_email_match = /([a-zA-Z\.]*@alphasights.com)/.match(httparty_options[:body])
work_email = work_email_match[1].presence if work_email_match.present?

bamboo_id_match = /(employees\/)(\d*)/.match(path)
bamboo_id = bamboo_id_match[2].presence if bamboo_id_match.present?

request_log = method.to_s == "get" ? nil : strio.string.gsub(encoded_auth_to_remove, "REDACTED-AUTH")

BambooRequestLog.create(
response_headers: response.headers.to_json,
response_timestamp: response["date"],
request_method: method.to_s,
request_path: "#{path_prefix}#{path}",
request_body: httparty_options[:body],
raw_httparty_request_log: request_log,
involving_employee_number: employee_number,
involving_work_email: work_email,
involving_bamboo_id: bamboo_id
)
end

if response.body.to_s.empty?
{"headers" => response.headers, "code" => "200", "message" => "ok"}.with_indifferent_access
else
Expand Down