9362a10
ZhenYi
refactor: remove OAuth-related modules and update references for identity service integration
9362a10
pub mod access_key;
pub mod agreement;
pub mod audit;
pub mod authority;
pub mod authorization;
pub mod cache_maintenance;
pub mod context;
pub mod convert;
pub mod email;
pub mod error;
pub mod identity;
pub mod key_rotation;
pub mod mfa;
pub mod organization;
pub mod service_token;
pub mod session;
pub mod ssh_key;
pub mod store;
pub mod token;
use std::net::SocketAddr;
use thiserror::Error;
use tonic::transport::Server;
use tonic::transport::server::Router;
use tonic_health::{ServingStatus, server};
use tonic_reflection::server::Builder as ReflectionBuilder;
use tower::layer::util::{Identity, Stack};
use crate::server::AuthSvc;
use crate::server::grpc::access_key::AccessKeyApi;
use crate::server::grpc::agreement::AgreementApi;
use crate::server::grpc::audit::AuditApi;
use crate::server::grpc::authority::AuthorityApi;
use crate::server::grpc::authorization::AuthorizationApi;
use crate::server::grpc::cache_maintenance::CacheMaintenanceApi;
use crate::server::grpc::email::EmailApi;
use crate::server::grpc::identity::IdentityApi;
use crate::server::grpc::key_rotation::KeyRotationApi;
use crate::server::grpc::mfa::MfaApi;
use crate::server::grpc::organization::{OrganizationAdminApi, OrganizationApi};
use crate::server::grpc::session::SessionApi;
use crate::server::grpc::ssh_key::SshKeyApi;
use crate::server::grpc::token::TokenApi;
pub const DEFAULT_MAX_MESSAGE_SIZE: usize = 4 * 1024 * 1024;
pub const HEALTH_SERVICE: &str = "";
pub const IMPLEMENTED_SERVICES: &[&str] = &[
"auth.v1.AccessKeyService",
"auth.v1.AgreementService",
"auth.v1.AuthorizationService",
"auth.v1.IdentityService",
"auth.v1.MfaService",
"auth.v1.OrganizationService",
"auth.v1.SessionService",
"auth.v1.SshKeyService",
"auth.v1.TokenService",
"auth.internal.v1.AuditService",
"auth.internal.v1.AuthorityService",
"auth.internal.v1.CacheMaintenanceService",
"auth.internal.v1.EmailService",
"auth.internal.v1.KeyRotationService",
"auth.internal.v1.OrganizationAdminService",
];
#[derive(Debug, Error)]
pub enum GrpcError {
#[error("grpc transport error: {0}")]
Transport(#[from] tonic::transport::Error),
#[error("grpc reflection error: {0}")]
Reflection(String),
}
pub type GrpcResult<T> = Result<T, GrpcError>;
pub type GrpcRouter = Router<Stack<crate::oltp::GrpcRequestLog, Identity>>;
pub async fn router(svc: AuthSvc) -> GrpcResult<GrpcRouter> {
let (reporter, health) = server::health_reporter();
reporter
.set_service_status(HEALTH_SERVICE, ServingStatus::Serving)
.await;
for service in IMPLEMENTED_SERVICES {
reporter
.set_service_status(*service, ServingStatus::Serving)
.await;
}
let reflection = ReflectionBuilder::configure()
.register_encoded_file_descriptor_set(crate::protos::FILE_DESCRIPTOR_SET)
.build_v1()
.map_err(|error| GrpcError::Reflection(error.to_string()))?;
Ok(Server::builder()
.layer(crate::oltp::GrpcRequestLog)
.add_service(health)
.add_service(reflection)
.add_service(AgreementApi::new(svc.clone()).server())
.add_service(IdentityApi::new(svc.clone()).server())
.add_service(SessionApi::new(svc.clone()).server())
.add_service(TokenApi::new(svc.clone()).server())
.add_service(AccessKeyApi::new(svc.clone()).server())
.add_service(SshKeyApi::new(svc.clone()).server())
.add_service(MfaApi::new(svc.clone()).server())
.add_service(OrganizationApi::new(svc.clone()).server())
.add_service(OrganizationAdminApi::new(svc.clone()).server())
.add_service(AuthorizationApi::new(svc.clone()).server())
.add_service(KeyRotationApi::new(svc.clone()).server())
.add_service(AuthorityApi::new(svc.clone()).server())
.add_service(CacheMaintenanceApi::new(svc.clone()).server())
.add_service(EmailApi::new(svc.clone()).server())
.add_service(AuditApi::new(svc).server()))
}
pub async fn serve(addr: SocketAddr, svc: AuthSvc) -> GrpcResult<()> {
let router = router(svc).await?;
router.serve(addr).await?;
Ok(())
}