From 6bb8ac54cb8fbbc1b88ba0a4c9a2a9fa66bd1303 Mon Sep 17 00:00:00 2001 From: Natalie Tay Date: Thu, 5 Sep 2024 22:29:29 +0800 Subject: [PATCH] DEV: Include a basic oauth faraday formatter in core for usage in managed authenticators (#28758) We currently have some occurrences of ____FaradayFormatter for OAuth logs. This commit creates a generic formatter so that any new authenticators can use it. --- lib/auth/oauth_faraday_formatter.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lib/auth/oauth_faraday_formatter.rb diff --git a/lib/auth/oauth_faraday_formatter.rb b/lib/auth/oauth_faraday_formatter.rb new file mode 100644 index 00000000000..7c404988f5a --- /dev/null +++ b/lib/auth/oauth_faraday_formatter.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class Auth::OauthFaradayFormatter < Faraday::Logging::Formatter + def request(env) + warn <<~LOG + OAuth Debugging: request #{env.method.upcase} #{env.url} + + Headers: + #{env.request_headers} + + Body: + #{env[:body]} + LOG + end + + def response(env) + warn <<~LOG + OAuth Debugging: response status #{env.status} + + From #{env.method.upcase} #{env.url} + + Headers: + #{env.response_headers} + + Body: + #{env[:body]} + LOG + end +end