This is an automated email from the ASF dual-hosted git repository.

mssun pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git

commit feaa60453e4c33d08a4c09a12bde60d30f7b25ef
Author: Mingshen Sun <[email protected]>
AuthorDate: Sun Feb 2 20:15:35 2020 -0800

    [services] Add constructor to services
---
 services/authentication/enclave/src/api_service.rs      | 13 +++++++++++--
 services/authentication/enclave/src/internal_service.rs | 13 +++++++++++--
 services/authentication/enclave/src/lib.rs              | 11 +++--------
 services/database/enclave/src/lib.rs                    |  8 +++-----
 services/database/enclave/src/proxy.rs                  |  8 +++++++-
 services/database/enclave/src/service.rs                | 10 ++++++++--
 services/frontend/enclave/src/lib.rs                    |  8 +++++++-
 services/frontend/enclave/src/service.rs                |  5 ++---
 8 files changed, 52 insertions(+), 24 deletions(-)

diff --git a/services/authentication/enclave/src/api_service.rs 
b/services/authentication/enclave/src/api_service.rs
index ae425df..b90d3e3 100644
--- a/services/authentication/enclave/src/api_service.rs
+++ b/services/authentication/enclave/src/api_service.rs
@@ -37,8 +37,17 @@ impl From<TeaclaveAuthenticationApiError> for 
TeaclaveServiceResponseError {
 )]
 #[derive(Clone)]
 pub(crate) struct TeaclaveAuthenticationApiService {
-    pub(crate) db_client: DbClient,
-    pub(crate) jwt_secret: Vec<u8>,
+    db_client: DbClient,
+    jwt_secret: Vec<u8>,
+}
+
+impl TeaclaveAuthenticationApiService {
+    pub(crate) fn new(db_client: DbClient, jwt_secret: Vec<u8>) -> Self {
+        Self {
+            db_client,
+            jwt_secret,
+        }
+    }
 }
 
 impl TeaclaveAuthenticationApi for TeaclaveAuthenticationApiService {
diff --git a/services/authentication/enclave/src/internal_service.rs 
b/services/authentication/enclave/src/internal_service.rs
index 72360a3..a758bf1 100644
--- a/services/authentication/enclave/src/internal_service.rs
+++ b/services/authentication/enclave/src/internal_service.rs
@@ -11,8 +11,17 @@ use teaclave_types::TeaclaveServiceResponseResult;
 #[teaclave_service(teaclave_authentication_service, 
TeaclaveAuthenticationInternal)]
 #[derive(Clone)]
 pub(crate) struct TeaclaveAuthenticationInternalService {
-    pub(crate) db_client: DbClient,
-    pub(crate) jwt_secret: Vec<u8>,
+    db_client: DbClient,
+    jwt_secret: Vec<u8>,
+}
+
+impl TeaclaveAuthenticationInternalService {
+    pub(crate) fn new(db_client: DbClient, jwt_secret: Vec<u8>) -> Self {
+        Self {
+            db_client,
+            jwt_secret,
+        }
+    }
 }
 
 impl TeaclaveAuthenticationInternal for TeaclaveAuthenticationInternalService {
diff --git a/services/authentication/enclave/src/lib.rs 
b/services/authentication/enclave/src/lib.rs
index 789fe9c..3ff710c 100644
--- a/services/authentication/enclave/src/lib.rs
+++ b/services/authentication/enclave/src/lib.rs
@@ -64,10 +64,8 @@ fn start_internal_endpoint(
         TeaclaveAuthenticationInternalRequest,
     >::new(addr, &config);
 
-    let service = internal_service::TeaclaveAuthenticationInternalService {
-        db_client,
-        jwt_secret,
-    };
+    let service =
+        
internal_service::TeaclaveAuthenticationInternalService::new(db_client, 
jwt_secret);
 
     match server.start(service) {
         Ok(_) => (),
@@ -94,10 +92,7 @@ fn start_api_endpoint(
         TeaclaveAuthenticationApiRequest,
     >::new(addr, &config);
 
-    let service = api_service::TeaclaveAuthenticationApiService {
-        db_client,
-        jwt_secret,
-    };
+    let service = 
api_service::TeaclaveAuthenticationApiService::new(db_client, jwt_secret);
 
     match server.start(service) {
         Ok(_) => (),
diff --git a/services/database/enclave/src/lib.rs 
b/services/database/enclave/src/lib.rs
index 5d63d8e..1c83c71 100644
--- a/services/database/enclave/src/lib.rs
+++ b/services/database/enclave/src/lib.rs
@@ -67,10 +67,8 @@ fn handle_start_service(args: &StartServiceInput) -> 
Result<StartServiceOutput>
     thread::spawn(move || {
         let opt = rusty_leveldb::in_memory();
         let database = DB::open("teaclave_db", opt).unwrap();
-        let mut database_service = service::TeaclaveDatabaseService {
-            database: RefCell::new(database),
-            receiver,
-        };
+        let mut database_service =
+            service::TeaclaveDatabaseService::new(RefCell::new(database), 
receiver);
         database_service.start();
     });
 
@@ -79,7 +77,7 @@ fn handle_start_service(args: &StartServiceInput) -> 
Result<StartServiceOutput>
         &config,
     );
 
-    let service = proxy::ProxyService { sender };
+    let service = proxy::ProxyService::new(sender);
 
     match server.start(service) {
         Ok(_) => (),
diff --git a/services/database/enclave/src/proxy.rs 
b/services/database/enclave/src/proxy.rs
index 6a60878..27db81a 100644
--- a/services/database/enclave/src/proxy.rs
+++ b/services/database/enclave/src/proxy.rs
@@ -9,7 +9,13 @@ use teaclave_types::TeaclaveServiceResponseResult;
 
 #[derive(Clone)]
 pub(crate) struct ProxyService {
-    pub sender: Sender<ProxyRequest>,
+    sender: Sender<ProxyRequest>,
+}
+
+impl ProxyService {
+    pub(crate) fn new(sender: Sender<ProxyRequest>) -> Self {
+        Self { sender }
+    }
 }
 
 impl teaclave_rpc::TeaclaveService<TeaclaveDatabaseRequest, 
TeaclaveDatabaseResponse>
diff --git a/services/database/enclave/src/service.rs 
b/services/database/enclave/src/service.rs
index 36f422c..15bf9ba 100644
--- a/services/database/enclave/src/service.rs
+++ b/services/database/enclave/src/service.rs
@@ -35,8 +35,14 @@ pub(crate) struct TeaclaveDatabaseService {
     // Current LevelDB implementation is not concurrent, so we need to wrap the
     // DB with RefCell. This service is running in a single thread, it's safe 
to
     // use RefCell.
-    pub database: RefCell<DB>,
-    pub receiver: Receiver<ProxyRequest>,
+    database: RefCell<DB>,
+    receiver: Receiver<ProxyRequest>,
+}
+
+impl TeaclaveDatabaseService {
+    pub(crate) fn new(database: RefCell<DB>, receiver: Receiver<ProxyRequest>) 
-> Self {
+        Self { database, receiver }
+    }
 }
 
 // queue-key-head: u32; include element
diff --git a/services/frontend/enclave/src/lib.rs 
b/services/frontend/enclave/src/lib.rs
index f401326..3932527 100644
--- a/services/frontend/enclave/src/lib.rs
+++ b/services/frontend/enclave/src/lib.rs
@@ -58,7 +58,13 @@ fn handle_start_service(args: &StartServiceInput) -> 
Result<StartServiceOutput>
         &config,
     );
 
-    let service = service::TeaclaveFrontendService::new(&args.config);
+    let service = service::TeaclaveFrontendService::new(
+        &args
+            .config
+            .internal_endpoints
+            .authentication
+            .advertised_address,
+    );
     match server.start(service) {
         Ok(_) => (),
         Err(e) => {
diff --git a/services/frontend/enclave/src/service.rs 
b/services/frontend/enclave/src/service.rs
index 7ffd390..a2bca0a 100644
--- a/services/frontend/enclave/src/service.rs
+++ b/services/frontend/enclave/src/service.rs
@@ -1,6 +1,5 @@
 use std::prelude::v1::*;
 use std::sync::{Arc, SgxMutex as Mutex};
-use teaclave_config::RuntimeConfig;
 use 
teaclave_proto::teaclave_authentication_service::TeaclaveAuthenticationInternalClient;
 use teaclave_proto::teaclave_authentication_service::UserAuthenticateRequest;
 use teaclave_proto::teaclave_common::UserCredential;
@@ -33,8 +32,8 @@ pub(crate) struct TeaclaveFrontendService {
 }
 
 impl TeaclaveFrontendService {
-    pub(crate) fn new(config: &RuntimeConfig) -> Self {
-        let channel = 
Endpoint::new(&config.internal_endpoints.authentication.advertised_address)
+    pub(crate) fn new(authentication_service_address: &str) -> Self {
+        let channel = Endpoint::new(authentication_service_address)
             .connect()
             .unwrap();
         let client = 
TeaclaveAuthenticationInternalClient::new(channel).unwrap();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to