You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by ms...@apache.org on 2020/03/24 18:00:18 UTC
[incubator-teaclave] branch develop updated: [utils] Introduce
macros to simplify fn impl
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
The following commit(s) were added to refs/heads/develop by this push:
new 3106a26 [utils] Introduce macros to simplify fn impl
3106a26 is described below
commit 3106a26de1b23af93d1c13c148a36fe09985cb6e
Author: Mingshen Sun <bo...@mssun.me>
AuthorDate: Mon Mar 23 21:06:18 2020 -0700
[utils] Introduce macros to simplify fn impl
---
.../enclave/src/access_control_service.rs | 48 +++-------------
tests/functional/enclave/src/utils.rs | 46 ++++++++--------
utils/service_enclave_utils/src/lib.rs | 64 +++++++++-------------
3 files changed, 60 insertions(+), 98 deletions(-)
diff --git a/tests/functional/enclave/src/access_control_service.rs b/tests/functional/enclave/src/access_control_service.rs
index 23888c4..706c232 100644
--- a/tests/functional/enclave/src/access_control_service.rs
+++ b/tests/functional/enclave/src/access_control_service.rs
@@ -15,14 +15,9 @@
// specific language governing permissions and limitations
// under the License.
+use crate::utils::*;
use std::prelude::v1::*;
-use teaclave_attestation::verifier;
-use teaclave_config::RuntimeConfig;
-use teaclave_config::BUILD_CONFIG;
use teaclave_proto::teaclave_access_control_service::*;
-use teaclave_rpc::config::SgxTrustedTlsClientConfig;
-use teaclave_rpc::endpoint::Endpoint;
-use teaclave_types::EnclaveInfo;
pub fn run_tests() -> bool {
use teaclave_test_utils::*;
@@ -40,33 +35,8 @@ pub fn run_tests() -> bool {
)
}
-fn get_client() -> TeaclaveAccessControlClient {
- let runtime_config = RuntimeConfig::from_toml("runtime.config.toml").expect("runtime");
- let enclave_info =
- EnclaveInfo::from_bytes(&runtime_config.audit.enclave_info_bytes.as_ref().unwrap());
- let enclave_attr = enclave_info
- .get_enclave_attr("teaclave_access_control_service")
- .expect("access_control");
- let config = SgxTrustedTlsClientConfig::new().attestation_report_verifier(
- vec![enclave_attr],
- BUILD_CONFIG.as_root_ca_cert,
- verifier::universal_quote_verifier,
- );
-
- let channel = Endpoint::new(
- &runtime_config
- .internal_endpoints
- .access_control
- .advertised_address,
- )
- .config(config)
- .connect()
- .unwrap();
- TeaclaveAccessControlClient::new(channel).unwrap()
-}
-
fn test_authorize_data_success() {
- let mut client = get_client();
+ let mut client = get_access_control_client();
let request = AuthorizeDataRequest::new("mock_user_a", "mock_data");
let response_result = client.authorize_data(request);
@@ -75,7 +45,7 @@ fn test_authorize_data_success() {
}
fn test_authorize_data_fail() {
- let mut client = get_client();
+ let mut client = get_access_control_client();
let request = AuthorizeDataRequest::new("mock_user_d", "mock_data");
let response_result = client.authorize_data(request);
@@ -89,7 +59,7 @@ fn test_authorize_data_fail() {
}
fn test_authorize_function_success() {
- let mut client = get_client();
+ let mut client = get_access_control_client();
let request =
AuthorizeFunctionRequest::new("mock_public_function_owner", "mock_public_function");
@@ -111,7 +81,7 @@ fn test_authorize_function_success() {
}
fn test_authorize_function_fail() {
- let mut client = get_client();
+ let mut client = get_access_control_client();
let request =
AuthorizeFunctionRequest::new("mock_public_function_owner", "mock_private_function");
let response_result = client.authorize_function(request);
@@ -120,7 +90,7 @@ fn test_authorize_function_fail() {
}
fn test_authorize_task_success() {
- let mut client = get_client();
+ let mut client = get_access_control_client();
let request = AuthorizeTaskRequest::new("mock_participant_a", "mock_task");
let response_result = client.authorize_task(request);
assert!(response_result.is_ok());
@@ -133,7 +103,7 @@ fn test_authorize_task_success() {
}
fn test_authorize_task_fail() {
- let mut client = get_client();
+ let mut client = get_access_control_client();
let request = AuthorizeTaskRequest::new("mock_participant_c", "mock_task");
let response_result = client.authorize_task(request);
assert!(response_result.is_ok());
@@ -141,7 +111,7 @@ fn test_authorize_task_fail() {
}
fn test_authorize_staged_task_success() {
- let mut client = get_client();
+ let mut client = get_access_control_client();
let request = AuthorizeStagedTaskRequest {
subject_task_id: "mock_staged_task".to_string(),
object_function_id: "mock_staged_allowed_private_function".to_string(),
@@ -162,7 +132,7 @@ fn test_authorize_staged_task_success() {
}
fn test_authorize_staged_task_fail() {
- let mut client = get_client();
+ let mut client = get_access_control_client();
let request = AuthorizeStagedTaskRequest {
subject_task_id: "mock_staged_task".to_string(),
object_function_id: "mock_staged_disallowed_private_function".to_string(),
diff --git a/tests/functional/enclave/src/utils.rs b/tests/functional/enclave/src/utils.rs
index cafc469..f703841 100644
--- a/tests/functional/enclave/src/utils.rs
+++ b/tests/functional/enclave/src/utils.rs
@@ -17,32 +17,34 @@
use std::prelude::v1::*;
use teaclave_config::RuntimeConfig;
+use teaclave_proto::teaclave_access_control_service::*;
use teaclave_proto::teaclave_scheduler_service::*;
use teaclave_proto::teaclave_storage_service::*;
use teaclave_rpc::endpoint::Endpoint;
use teaclave_types::*;
-pub(crate) fn get_scheduler_client() -> TeaclaveSchedulerClient {
- let runtime_config = RuntimeConfig::from_toml("runtime.config.toml").expect("runtime");
- let address = runtime_config
- .internal_endpoints
- .scheduler
- .advertised_address;
- let channel = Endpoint::new(&address).connect().unwrap();
- let metadata = hashmap!(
- "id" => "mock_user",
- "token" => "",
- );
- TeaclaveSchedulerClient::new_with_metadata(channel, metadata).unwrap()
+macro_rules! impl_get_service_client_fn {
+ ($service_name:ident, $fn_name:ident, $return:ident) => {
+ pub(crate) fn $fn_name() -> $return {
+ let runtime_config = RuntimeConfig::from_toml("runtime.config.toml").expect("runtime");
+ let address = runtime_config
+ .internal_endpoints
+ .$service_name
+ .advertised_address;
+ let channel = Endpoint::new(&address).connect().unwrap();
+ let metadata = hashmap!(
+ "id" => "mock_user",
+ "token" => "",
+ );
+ $return::new_with_metadata(channel, metadata).unwrap()
+ }
+ };
}
-pub(crate) fn get_storage_client() -> TeaclaveStorageClient {
- let runtime_config = RuntimeConfig::from_toml("runtime.config.toml").expect("runtime");
- let address = runtime_config.internal_endpoints.storage.advertised_address;
- let channel = Endpoint::new(&address).connect().unwrap();
- let metadata = hashmap!(
- "id" => "mock_user",
- "token" => "",
- );
- TeaclaveStorageClient::new_with_metadata(channel, metadata).unwrap()
-}
+impl_get_service_client_fn!(scheduler, get_scheduler_client, TeaclaveSchedulerClient);
+impl_get_service_client_fn!(storage, get_storage_client, TeaclaveStorageClient);
+impl_get_service_client_fn!(
+ access_control,
+ get_access_control_client,
+ TeaclaveAccessControlClient
+);
diff --git a/utils/service_enclave_utils/src/lib.rs b/utils/service_enclave_utils/src/lib.rs
index 6413474..a25d56c 100644
--- a/utils/service_enclave_utils/src/lib.rs
+++ b/utils/service_enclave_utils/src/lib.rs
@@ -68,42 +68,32 @@ impl ServiceEnclave {
pub use teaclave_service_enclave_utils_proc_macro::teaclave_service;
-pub fn create_trusted_storage_endpoint(
- advertised_address: &str,
- enclave_info: &EnclaveInfo,
- as_root_ca_cert: &[u8],
- verifier: AttestationReportVerificationFn,
-) -> Endpoint {
- let storage_service_enclave_attrs = enclave_info
- .get_enclave_attr("teaclave_storage_service")
- .expect("enclave_info");
- let storage_service_client_config = SgxTrustedTlsClientConfig::new()
- .attestation_report_verifier(
- vec![storage_service_enclave_attrs],
- as_root_ca_cert,
- verifier,
- );
- let storage_service_address = &advertised_address;
-
- Endpoint::new(storage_service_address).config(storage_service_client_config)
+macro_rules! impl_create_trusted_endpoint_fn {
+ ($fn_name:ident, $enclave_attr:literal) => {
+ pub fn $fn_name(
+ advertised_address: &str,
+ enclave_info: &EnclaveInfo,
+ as_root_ca_cert: &[u8],
+ verifier: AttestationReportVerificationFn,
+ ) -> Endpoint {
+ let service_enclave_attrs = enclave_info
+ .get_enclave_attr($enclave_attr)
+ .expect("enclave_info");
+ let service_client_config = SgxTrustedTlsClientConfig::new()
+ .attestation_report_verifier(
+ vec![service_enclave_attrs],
+ as_root_ca_cert,
+ verifier,
+ );
+ let service_address = &advertised_address;
+
+ Endpoint::new(service_address).config(service_client_config)
+ }
+ };
}
-pub fn create_trusted_scheduler_endpoint(
- advertised_address: &str,
- enclave_info: &EnclaveInfo,
- as_root_ca_cert: &[u8],
- verifier: AttestationReportVerificationFn,
-) -> Endpoint {
- let scheduler_service_enclave_attrs = enclave_info
- .get_enclave_attr("teaclave_scheduler_service")
- .expect("enclave_info");
- let scheduler_service_client_config = SgxTrustedTlsClientConfig::new()
- .attestation_report_verifier(
- vec![scheduler_service_enclave_attrs],
- as_root_ca_cert,
- verifier,
- );
- let scheduler_service_address = &advertised_address;
-
- Endpoint::new(scheduler_service_address).config(scheduler_service_client_config)
-}
+impl_create_trusted_endpoint_fn!(create_trusted_storage_endpoint, "teaclave_storage_service");
+impl_create_trusted_endpoint_fn!(
+ create_trusted_scheduler_endpoint,
+ "teaclave_scheduler_service"
+);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org