Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3113720
D3812.id11804.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D3812.id11804.diff
View Options
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<Key>,
+}
+
+impl Config {
+ pub fn load(&mut self) -> Result<(), Box<dyn std::error::Error>> {
+ 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<P: AsRef<Path>>(path: P) -> Result<Key, Box<dyn std::error::Error>> {
+ 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<dyn std::error::Error>> {
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 {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 1, 6:27 PM (21 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2400508
Default Alt Text
D3812.id11804.diff (2 KB)
Attached To
Mode
D3812: [Identity] Add config for Identity service
Attached
Detach File
Event Timeline
Log In to Comment