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 d7f26d5bec46c8e3e630eaf927792e7cd035553a Author: Mingshen Sun <[email protected]> AuthorDate: Tue Feb 4 19:51:49 2020 -0800 [proto] Add new/constructor for small request/response structure --- .../proto/src/teaclave_access_control_service.rs | 68 +++++++++++++++++++--- services/proto/src/teaclave_storage_service.rs | 38 +++++------- .../enclave/src/teaclave_access_control_service.rs | 54 +++++------------ 3 files changed, 89 insertions(+), 71 deletions(-) diff --git a/services/proto/src/teaclave_access_control_service.rs b/services/proto/src/teaclave_access_control_service.rs index 2a51071..4b71116 100644 --- a/services/proto/src/teaclave_access_control_service.rs +++ b/services/proto/src/teaclave_access_control_service.rs @@ -1,6 +1,5 @@ use crate::teaclave_access_control_service_proto as proto; use anyhow::{Error, Result}; -use serde::{Deserialize, Serialize}; use std::prelude::v1::*; pub use proto::TeaclaveAccessControl; @@ -8,40 +7,85 @@ pub use proto::TeaclaveAccessControlClient; pub use proto::TeaclaveAccessControlRequest; pub use proto::TeaclaveAccessControlResponse; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct AuthorizeDataRequest { pub subject_user_id: String, pub object_data_id: String, } -#[derive(Serialize, Deserialize, Debug)] +impl AuthorizeDataRequest { + pub fn new(subject_user_id: impl Into<String>, object_data_id: impl Into<String>) -> Self { + Self { + subject_user_id: subject_user_id.into(), + object_data_id: object_data_id.into(), + } + } +} + +#[derive(Debug)] pub struct AuthorizeDataResponse { pub accept: bool, } -#[derive(Serialize, Deserialize, Debug)] +impl AuthorizeDataResponse { + pub fn new(accept: bool) -> Self { + Self { accept } + } +} + +#[derive(Debug)] pub struct AuthorizeFunctionRequest { pub subject_user_id: String, pub object_function_id: String, } -#[derive(Serialize, Deserialize, Debug)] +impl AuthorizeFunctionRequest { + pub fn new(subject_user_id: impl Into<String>, object_function_id: impl Into<String>) -> Self { + Self { + subject_user_id: subject_user_id.into(), + object_function_id: object_function_id.into(), + } + } +} + +#[derive(Debug)] pub struct AuthorizeFunctionResponse { pub accept: bool, } -#[derive(Serialize, Deserialize, Debug)] +impl AuthorizeFunctionResponse { + pub fn new(accept: bool) -> Self { + Self { accept } + } +} + +#[derive(Debug)] pub struct AuthorizeTaskRequest { pub subject_user_id: String, pub object_task_id: String, } -#[derive(Serialize, Deserialize, Debug)] +impl AuthorizeTaskRequest { + pub fn new(subject_user_id: impl Into<String>, object_task_id: impl Into<String>) -> Self { + Self { + subject_user_id: subject_user_id.into(), + object_task_id: object_task_id.into(), + } + } +} + +#[derive(Debug)] pub struct AuthorizeTaskResponse { pub accept: bool, } -#[derive(Serialize, Deserialize, Debug)] +impl AuthorizeTaskResponse { + pub fn new(accept: bool) -> Self { + Self { accept } + } +} + +#[derive(Debug)] pub struct AuthorizeStagedTaskRequest { pub subject_task_id: String, pub object_function_id: String, @@ -49,11 +93,17 @@ pub struct AuthorizeStagedTaskRequest { pub object_output_data_id_list: Vec<String>, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct AuthorizeStagedTaskResponse { pub accept: bool, } +impl AuthorizeStagedTaskResponse { + pub fn new(accept: bool) -> Self { + Self { accept } + } +} + impl std::convert::TryFrom<proto::AuthorizeDataRequest> for AuthorizeDataRequest { type Error = Error; diff --git a/services/proto/src/teaclave_storage_service.rs b/services/proto/src/teaclave_storage_service.rs index 71956f6..6e1b200 100644 --- a/services/proto/src/teaclave_storage_service.rs +++ b/services/proto/src/teaclave_storage_service.rs @@ -13,10 +13,8 @@ pub struct GetRequest { } impl GetRequest { - pub fn new(key: impl AsRef<[u8]>) -> Self { - Self { - key: key.as_ref().into(), - } + pub fn new(key: impl Into<Vec<u8>>) -> Self { + Self { key: key.into() } } } @@ -26,9 +24,9 @@ pub struct GetResponse { } impl GetResponse { - pub fn new(value: impl AsRef<[u8]>) -> Self { + pub fn new(value: impl Into<Vec<u8>>) -> Self { Self { - value: value.as_ref().into(), + value: value.into(), } } } @@ -40,10 +38,10 @@ pub struct PutRequest { } impl PutRequest { - pub fn new(key: impl AsRef<[u8]>, value: impl AsRef<[u8]>) -> Self { + pub fn new(key: impl Into<Vec<u8>>, value: impl Into<Vec<u8>>) -> Self { Self { - key: key.as_ref().into(), - value: value.as_ref().into(), + key: key.into(), + value: value.into(), } } } @@ -57,10 +55,8 @@ pub struct DeleteRequest { } impl DeleteRequest { - pub fn new(key: impl AsRef<[u8]>) -> Self { - Self { - key: key.as_ref().into(), - } + pub fn new(key: impl Into<Vec<u8>>) -> Self { + Self { key: key.into() } } } @@ -74,10 +70,10 @@ pub struct EnqueueRequest { } impl EnqueueRequest { - pub fn new(key: impl AsRef<[u8]>, value: impl AsRef<[u8]>) -> Self { + pub fn new(key: impl Into<Vec<u8>>, value: impl Into<Vec<u8>>) -> Self { Self { - key: key.as_ref().into(), - value: value.as_ref().into(), + key: key.into(), + value: value.into(), } } } @@ -91,10 +87,8 @@ pub struct DequeueRequest { } impl DequeueRequest { - pub fn new(key: impl AsRef<[u8]>) -> Self { - Self { - key: key.as_ref().into(), - } + pub fn new(key: impl Into<Vec<u8>>) -> Self { + Self { key: key.into() } } } @@ -104,9 +98,9 @@ pub struct DequeueResponse { } impl DequeueResponse { - pub fn new(value: impl AsRef<[u8]>) -> Self { + pub fn new(value: impl Into<Vec<u8>>) -> Self { Self { - value: value.as_ref().into(), + value: value.into(), } } } diff --git a/tests/functional_tests/enclave/src/teaclave_access_control_service.rs b/tests/functional_tests/enclave/src/teaclave_access_control_service.rs index 32ebb43..c8ddfcd 100644 --- a/tests/functional_tests/enclave/src/teaclave_access_control_service.rs +++ b/tests/functional_tests/enclave/src/teaclave_access_control_service.rs @@ -51,10 +51,7 @@ fn get_client() -> TeaclaveAccessControlClient { fn test_authorize_data_success() { let mut client = get_client(); - let request = AuthorizeDataRequest { - subject_user_id: "mock_user_a".to_string(), - object_data_id: "mock_data".to_string(), - }; + let request = AuthorizeDataRequest::new("mock_user_a", "mock_data"); let response_result = client.authorize_data(request); assert!(response_result.is_ok()); assert!(response_result.unwrap().accept); @@ -63,18 +60,12 @@ fn test_authorize_data_success() { fn test_authorize_data_fail() { let mut client = get_client(); - let request = AuthorizeDataRequest { - subject_user_id: "mock_user_d".to_string(), - object_data_id: "mock_data".to_string(), - }; + let request = AuthorizeDataRequest::new("mock_user_d", "mock_data"); let response_result = client.authorize_data(request); assert!(response_result.is_ok()); assert!(!response_result.unwrap().accept); - let request = AuthorizeDataRequest { - subject_user_id: "mock_user_a".to_string(), - object_data_id: "mock_data_b".to_string(), - }; + let request = AuthorizeDataRequest::new("mock_user_a", "mock_data_b"); let response_result = client.authorize_data(request); assert!(response_result.is_ok()); assert!(!response_result.unwrap().accept); @@ -83,26 +74,20 @@ fn test_authorize_data_fail() { fn test_authorize_function_success() { let mut client = get_client(); - let request = AuthorizeFunctionRequest { - subject_user_id: "mock_public_function_owner".to_string(), - object_function_id: "mock_public_function".to_string(), - }; + let request = + AuthorizeFunctionRequest::new("mock_public_function_owner", "mock_public_function"); let response_result = client.authorize_function(request); assert!(response_result.is_ok()); assert!(response_result.unwrap().accept); - let request = AuthorizeFunctionRequest { - subject_user_id: "mock_private_function_owner".to_string(), - object_function_id: "mock_private_function".to_string(), - }; + let request = + AuthorizeFunctionRequest::new("mock_private_function_owner", "mock_private_function"); let response_result = client.authorize_function(request); assert!(response_result.is_ok()); assert!(response_result.unwrap().accept); - let request = AuthorizeFunctionRequest { - subject_user_id: "mock_private_function_owner".to_string(), - object_function_id: "mock_public_function".to_string(), - }; + let request = + AuthorizeFunctionRequest::new("mock_private_function_owner", "mock_public_function"); let response_result = client.authorize_function(request); assert!(response_result.is_ok()); assert!(response_result.unwrap().accept); @@ -110,10 +95,8 @@ fn test_authorize_function_success() { fn test_authorize_function_fail() { let mut client = get_client(); - let request = AuthorizeFunctionRequest { - subject_user_id: "mock_public_function_owner".to_string(), - object_function_id: "mock_private_function".to_string(), - }; + let request = + AuthorizeFunctionRequest::new("mock_public_function_owner", "mock_private_function"); let response_result = client.authorize_function(request); assert!(response_result.is_ok()); assert!(!response_result.unwrap().accept); @@ -121,18 +104,12 @@ fn test_authorize_function_fail() { fn test_authorize_task_success() { let mut client = get_client(); - let request = AuthorizeTaskRequest { - subject_user_id: "mock_participant_a".to_string(), - object_task_id: "mock_task".to_string(), - }; + let request = AuthorizeTaskRequest::new("mock_participant_a", "mock_task"); let response_result = client.authorize_task(request); assert!(response_result.is_ok()); assert!(response_result.unwrap().accept); - let request = AuthorizeTaskRequest { - subject_user_id: "mock_participant_b".to_string(), - object_task_id: "mock_task".to_string(), - }; + let request = AuthorizeTaskRequest::new("mock_participant_b", "mock_task"); let response_result = client.authorize_task(request); assert!(response_result.is_ok()); assert!(response_result.unwrap().accept); @@ -140,10 +117,7 @@ fn test_authorize_task_success() { fn test_authorize_task_fail() { let mut client = get_client(); - let request = AuthorizeTaskRequest { - subject_user_id: "mock_participant_c".to_string(), - object_task_id: "mock_task".to_string(), - }; + let request = AuthorizeTaskRequest::new("mock_participant_c", "mock_task"); let response_result = client.authorize_task(request); assert!(response_result.is_ok()); assert!(!response_result.unwrap().accept); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
