Add PKCE support for Tetrate Agent Router Service (#4165)
Signed-off-by: John Landa <jonathanlanda@gmail.com> Co-authored-by: Michael Neale <michael.neale@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use crate::state::AppState;
|
||||
use axum::{extract::State, http::StatusCode, routing::post, Json, Router};
|
||||
use goose::config::signup_openrouter::OpenRouterAuth;
|
||||
use goose::config::signup_tetrate::{configure_tetrate, TetrateAuth};
|
||||
use goose::config::{configure_openrouter, Config};
|
||||
use serde::Serialize;
|
||||
use std::sync::Arc;
|
||||
@@ -14,6 +15,7 @@ pub struct SetupResponse {
|
||||
pub fn routes(state: Arc<AppState>) -> Router {
|
||||
Router::new()
|
||||
.route("/handle_openrouter", post(start_openrouter_setup))
|
||||
.route("/handle_tetrate", post(start_tetrate_setup))
|
||||
.with_state(state)
|
||||
}
|
||||
|
||||
@@ -58,3 +60,45 @@ async fn start_openrouter_setup(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn start_tetrate_setup(
|
||||
State(_state): State<Arc<AppState>>,
|
||||
) -> Result<Json<SetupResponse>, StatusCode> {
|
||||
tracing::info!("Starting Tetrate Agent Router Service setup flow");
|
||||
|
||||
let mut auth_flow = TetrateAuth::new().map_err(|e| {
|
||||
tracing::error!("Failed to initialize auth flow: {}", e);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
|
||||
tracing::info!("Auth flow initialized, starting complete_flow");
|
||||
|
||||
match auth_flow.complete_flow().await {
|
||||
Ok(api_key) => {
|
||||
tracing::info!("Got API key, configuring Tetrate Agent Router Service...");
|
||||
|
||||
let config = Config::global();
|
||||
|
||||
if let Err(e) = configure_tetrate(config, api_key) {
|
||||
tracing::error!("Failed to configure Tetrate Agent Router Service: {}", e);
|
||||
return Ok(Json(SetupResponse {
|
||||
success: false,
|
||||
message: format!("Failed to configure Tetrate Agent Router Service: {}", e),
|
||||
}));
|
||||
}
|
||||
|
||||
tracing::info!("Tetrate Agent Router Service setup completed successfully");
|
||||
Ok(Json(SetupResponse {
|
||||
success: true,
|
||||
message: "Tetrate Agent Router Service setup completed successfully".to_string(),
|
||||
}))
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Tetrate Agent Router Service setup failed: {}", e);
|
||||
Ok(Json(SetupResponse {
|
||||
success: false,
|
||||
message: format!("Setup failed: {}", e),
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user