Changeset View
Changeset View
Standalone View
Standalone View
services/identity/src/main.rs
use std::time::Duration; | |||||
use clap::{Parser, Subcommand}; | use clap::{Parser, Subcommand}; | ||||
use database::DatabaseClient; | use database::DatabaseClient; | ||||
use moka::future::Cache; | |||||
use tonic::transport::Server; | use tonic::transport::Server; | ||||
use tracing_subscriber::FmtSubscriber; | use tracing_subscriber::FmtSubscriber; | ||||
mod client_service; | mod client_service; | ||||
mod config; | mod config; | ||||
pub mod constants; | pub mod constants; | ||||
mod database; | mod database; | ||||
mod id; | |||||
mod interceptor; | mod interceptor; | ||||
mod keygen; | mod keygen; | ||||
mod nonce; | mod nonce; | ||||
mod token; | mod token; | ||||
use config::load_config; | use config::load_config; | ||||
use constants::{IDENTITY_SERVICE_SOCKET_ADDR, SECRETS_DIRECTORY}; | use constants::{IDENTITY_SERVICE_SOCKET_ADDR, SECRETS_DIRECTORY}; | ||||
use keygen::generate_and_persist_keypair; | use keygen::generate_and_persist_keypair; | ||||
Show All 32 Lines | match &cli.command { | ||||
Commands::Keygen { dir } => { | Commands::Keygen { dir } => { | ||||
generate_and_persist_keypair(dir)?; | generate_and_persist_keypair(dir)?; | ||||
} | } | ||||
Commands::Server => { | Commands::Server => { | ||||
load_config(); | load_config(); | ||||
let addr = IDENTITY_SERVICE_SOCKET_ADDR.parse()?; | let addr = IDENTITY_SERVICE_SOCKET_ADDR.parse()?; | ||||
let aws_config = aws_config::from_env().region("us-east-2").load().await; | let aws_config = aws_config::from_env().region("us-east-2").load().await; | ||||
let database_client = DatabaseClient::new(&aws_config); | let database_client = DatabaseClient::new(&aws_config); | ||||
let client_service = | let workflow_cache = Cache::builder() | ||||
IdentityClientServiceServer::new(ClientService::new(database_client)); | .time_to_live(Duration::from_secs(10)) | ||||
.build(); | |||||
let client_service = IdentityClientServiceServer::new( | |||||
ClientService::new(database_client, workflow_cache), | |||||
); | |||||
info!("Listening to gRPC traffic on {}", addr); | info!("Listening to gRPC traffic on {}", addr); | ||||
Server::builder() | Server::builder() | ||||
.accept_http1(true) | .accept_http1(true) | ||||
.add_service(tonic_web::enable(client_service)) | .add_service(tonic_web::enable(client_service)) | ||||
.serve(addr) | .serve(addr) | ||||
.await?; | .await?; | ||||
} | } | ||||
Commands::PopulateDB => unimplemented!(), | Commands::PopulateDB => unimplemented!(), | ||||
} | } | ||||
Ok(()) | Ok(()) | ||||
} | } |