summaryrefslogtreecommitdiffstats
path: root/crates/auth/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/auth/src/main.rs')
-rw-r--r--crates/auth/src/main.rs41
1 files changed, 39 insertions, 2 deletions
diff --git a/crates/auth/src/main.rs b/crates/auth/src/main.rs
index a1883ad..72f991f 100644
--- a/crates/auth/src/main.rs
+++ b/crates/auth/src/main.rs
@@ -1,3 +1,4 @@
+mod auth;
mod client;
mod cnfg;
mod error;
@@ -7,11 +8,19 @@ mod state;
use std::net::{Ipv6Addr, SocketAddr};
use clap::Parser;
+use reqwest::header::CONTENT_TYPE;
+use sellershut_core::auth::{AUTH_FILE_DESCRIPTOR_SET, auth_server::AuthServer};
use stack_up::{Configuration, Services, tracing::Tracing};
use tokio::{signal, task::AbortHandle};
+use tonic::service::Routes;
+use tower::{make::Shared, steer::Steer};
use tracing::{info, trace};
-use crate::{error::AppError, state::AppState};
+use crate::{
+ error::AppError,
+ server::{grpc::interceptor::MyInterceptor, routes::authorised::AuthRequest},
+ state::AppState,
+};
/// auth-service
#[derive(Parser, Debug)]
@@ -63,7 +72,35 @@ async fn main() -> Result<(), AppError> {
let listener = tokio::net::TcpListener::bind(addr).await?;
info!(port = addr.port(), "serving api");
- axum::serve(listener, server::router(state))
+ let service = AuthServer::with_interceptor(state.clone(), MyInterceptor);
+ let auth_reflector = tonic_reflection::server::Builder::configure()
+ .register_encoded_file_descriptor_set(AUTH_FILE_DESCRIPTOR_SET)
+ .build_v1()?;
+
+ let grpc_server = Routes::new(service)
+ .add_service(auth_reflector)
+ .into_axum_router();
+
+ let service = Steer::new(
+ vec![server::router(state), grpc_server],
+ |req: &axum::extract::Request, _services: &[_]| {
+ if req
+ .headers()
+ .get(CONTENT_TYPE)
+ .map(|content_type| content_type.as_bytes())
+ .filter(|content_type| content_type.starts_with(b"application/grpc"))
+ .is_some()
+ {
+ // grpc service
+ 1
+ } else {
+ // http service
+ 0
+ }
+ },
+ );
+
+ axum::serve(listener, Shared::new(service))
.with_graceful_shutdown(shutdown_signal(deletion_task.abort_handle()))
.await?;