diff --git a/services/identity/src/config.rs b/services/identity/src/config.rs new file mode 100644 --- /dev/null +++ b/services/identity/src/config.rs @@ -0,0 +1,23 @@ +use opaque_ke::keypair::Key; +use std::{env, fs, path::Path}; + +#[derive(Default, Debug)] +pub struct Config { + server_secret_key: Option, +} + +impl Config { + pub fn load(&mut self) -> Result<(), Box> { + let mut path = env::current_dir()?; + path.push("secrets"); + path.push("secret_key"); + let key = get_key_from_file(path)?; + self.server_secret_key = Some(key); + Ok(()) + } +} + +fn get_key_from_file>(path: P) -> Result> { + let bytes = fs::read(path)?; + Key::from_bytes(&bytes).map_err(|e| e.to_string().into()) +} diff --git a/services/identity/src/lib.rs b/services/identity/src/lib.rs --- a/services/identity/src/lib.rs +++ b/services/identity/src/lib.rs @@ -1 +1,2 @@ +pub mod config; pub mod opaque; diff --git a/services/identity/src/main.rs b/services/identity/src/main.rs --- a/services/identity/src/main.rs +++ b/services/identity/src/main.rs @@ -8,7 +8,11 @@ #[tokio::main] async fn main() -> Result<(), Box> { let addr = IDENTITY_SERVICE_SOCKET_ADDR.parse()?; - let identity_service = MyIdentityService::default(); + let mut identity_service = MyIdentityService::default(); + identity_service + .config + .load() + .expect("config successfully loaded"); Server::builder() .add_service(IdentityServiceServer::new(identity_service)) diff --git a/services/identity/src/service.rs b/services/identity/src/service.rs --- a/services/identity/src/service.rs +++ b/services/identity/src/service.rs @@ -2,6 +2,8 @@ use std::pin::Pin; use tonic::{Request, Response, Status}; +use common::config::Config; + pub use proto::identity_service_server::IdentityServiceServer; use proto::{ identity_service_server::IdentityService, LoginRequest, LoginResponse, RegistrationRequest, @@ -13,7 +15,9 @@ } #[derive(Debug, Default)] -pub struct MyIdentityService {} +pub struct MyIdentityService { + pub config: Config, +} #[tonic::async_trait] impl IdentityService for MyIdentityService {