Skip to content

Commit

Permalink
Adding logs on OAuth service for debugging (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagojez authored May 9, 2024
1 parent aa3c13e commit 89164bc
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions api/src/endpoints/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ async fn oauth_handler(
Json(payload): Json<OAuthRequest>,
) -> Result<Json<Connection>, 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::<PlatformSecret>(
&state,
Expand All @@ -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),
Expand All @@ -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)
Expand All @@ -124,19 +145,19 @@ 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
.init
.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)
})?;

Expand Down

0 comments on commit 89164bc

Please sign in to comment.