From 89164bcef3fe2e5893f6d91e10a899c5fa11d421 Mon Sep 17 00:00:00 2001 From: Samuel <39674930+samgj18@users.noreply.github.com> Date: Thu, 9 May 2024 19:31:06 +0100 Subject: [PATCH] Adding logs on OAuth service for debugging (#25) --- api/src/endpoints/oauth.rs | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/api/src/endpoints/oauth.rs b/api/src/endpoints/oauth.rs index a06ba66f..0915a503 100644 --- a/api/src/endpoints/oauth.rs +++ b/api/src/endpoints/oauth.rs @@ -73,7 +73,12 @@ async fn oauth_handler( Json(payload): Json, ) -> Result, IntegrationOSError> { let conn_oauth_definition = get_conn_oauth_definition(&state, &platform).await?; - let setting = get_user_settings(&state, &user_event_access.ownership).await?; + let setting = get_user_settings(&state, &user_event_access.ownership) + .await + .map_err(|e| { + error!("Failed to get user settings: {:?}", e); + e + })?; let secret = get_secret::( &state, @@ -90,13 +95,19 @@ async fn oauth_handler( ) })?, buildable_id: if payload.is_engineering_account { + tracing::info!("Using engineering account id for secret"); state.config.engineering_account_id.clone() } else { + tracing::info!("Using user event access id for secret"); user_event_access.clone().ownership.id.to_string() }, }, ) - .await?; + .await + .map_err(|e| { + error!("Failed to get platform secret for connection: {:?}", e); + e + })?; let oauth_payload = OAuthPayload { metadata: payload.payload.clone().unwrap_or(Value::Null), @@ -107,12 +118,22 @@ async fn oauth_handler( let conn_oauth_definition = if conn_oauth_definition.is_full_template_enabled { state .template - .render_as(&conn_oauth_definition, oauth_payload.as_json().as_ref())? + .render_as(&conn_oauth_definition, oauth_payload.as_json().as_ref()) + .map_err(|e| { + error!("Failed to render oauth definition: {:?}", e); + e + })? } else { conn_oauth_definition }; - let request = request(&conn_oauth_definition, &oauth_payload, &state.template)?; + let request = + request(&conn_oauth_definition, &oauth_payload, &state.template).map_err(|e| { + error!("Failed to create oauth request: {}", e); + e + })?; + + debug!("Request: {:?}", request); let response = state .http_client .execute(request) @@ -124,11 +145,11 @@ async fn oauth_handler( })? .await .map_err(|e| { - error!("Failed to decode third party oauth response: {}", e); + error!("Failed to decode third party oauth response: {:?}", e); InternalError::deserialize_error(&e.to_string(), None) })?; - debug!("oauth response: {:?}", response); + debug!("Response: {:?}", response); let decoded: OAuthResponse = conn_oauth_definition .compute @@ -136,7 +157,7 @@ async fn oauth_handler( .response .compute(&response) .map_err(|e| { - error!("Failed to decode oauth response: {}", e); + error!("Failed to decode oauth response: {:?}", e); InternalError::script_error(e.message().as_ref(), None) })?;