Skip to content

Commit

Permalink
P 491 - url checking (#2511)
Browse files Browse the repository at this point in the history
* this should be a warn message.

* keep consistency with tee-worker

* fix the typo error, which causes crash

* remove `build_client`; all use `build_client_with_cert`.

* remove DataProviderConfig::default()

* add url sanity check at initialization

* add missing return value

---------

Co-authored-by: Yang <[email protected]>
  • Loading branch information
BillyWooo and Yang authored Feb 23, 2024
1 parent 717e39f commit 655fc19
Show file tree
Hide file tree
Showing 25 changed files with 109 additions and 87 deletions.
2 changes: 1 addition & 1 deletion bitacross-worker/core-primitives/settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub mod files {

// used by enclave
/// Path to the light-client db for the Integritee parentchain.
pub const LITENTRY_PARENTCHAIN_LIGHT_CLIENT_DB_PATH: &str = "integritee_lcdb";
pub const LITENTRY_PARENTCHAIN_LIGHT_CLIENT_DB_PATH: &str = "litentry_lcdb";

/// Path to the light-client db for the Target A parentchain.
pub const TARGET_A_PARENTCHAIN_LIGHT_CLIENT_DB_PATH: &str = "target_a_lcdb";
Expand Down
7 changes: 5 additions & 2 deletions tee-worker/enclave-runtime/src/initialization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,11 @@ pub(crate) fn init_enclave(
Arc::new(IntelAttestationHandler::new(ocall_api, signing_key_repository));
GLOBAL_ATTESTATION_HANDLER_COMPONENT.initialize(attestation_handler);

let data_provider_config = DataProviderConfig::new();
GLOBAL_DATA_PROVIDER_CONFIG.initialize(data_provider_config.into());
if let Ok(data_provider_config) = DataProviderConfig::new() {
GLOBAL_DATA_PROVIDER_CONFIG.initialize(data_provider_config.into());
} else {
return Err(Error::Other("data provider initialize error".into()))
}

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ mod tests {
let _ = env_logger::builder().is_test(true).try_init();
let url = run(0).unwrap();

let mut data_provider_config = DataProviderConfig::default();
let mut data_provider_config = DataProviderConfig::new().unwrap();

data_provider_config.set_nodereal_api_key("d416f55179dbd0e45b1a8ed030e3".into());
data_provider_config.set_nodereal_api_chain_network_url(url.clone() + "/nodereal_jsonrpc/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ mod tests {
let _ = env_logger::builder().is_test(true).try_init();
let url = run(0).unwrap() + "/karat_dao/";

let mut config = DataProviderConfig::new();
let mut config = DataProviderConfig::new().unwrap();
config.set_karat_dao_api_url(url);
config
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ mod tests {
let _ = env_logger::builder().is_test(true).try_init();
let url = run(0).unwrap();

let mut data_provider_config = DataProviderConfig::default();
let mut data_provider_config = DataProviderConfig::new().unwrap();

data_provider_config.set_nodereal_api_key("d416f55179dbd0e45b1a8ed030e3".into());
data_provider_config.set_nodereal_api_chain_network_url(url.clone() + "/nodereal_jsonrpc/");
Expand Down
8 changes: 4 additions & 4 deletions tee-worker/litentry/core/assertion-build/src/a14.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ use http::header::{AUTHORIZATION, CONNECTION};
use http_req::response::Headers;
use itc_rest_client::{
error::Error as RestClientError,
http_client::{DefaultSend, HttpClient},
http_client::{HttpClient, SendWithCertificateVerification},
rest_client::RestClient,
RestPath, RestPost,
};
use lc_data_providers::{build_client, DataProviderConfig};
use lc_data_providers::{build_client_with_cert, DataProviderConfig};
use serde::{Deserialize, Serialize};

const VC_A14_SUBJECT_DESCRIPTION: &str =
Expand Down Expand Up @@ -67,7 +67,7 @@ pub struct A14Response {

// TODO: merge it to new achainable API client once the migration is done
pub struct A14Client {
client: RestClient<HttpClient<DefaultSend>>,
client: RestClient<HttpClient<SendWithCertificateVerification>>,
}

impl A14Client {
Expand All @@ -79,7 +79,7 @@ impl A14Client {
data_provider_config.achainable_auth_key.clone().as_str(),
);
let client =
build_client("https://label-production.graph.tdf-labs.io/v1/run/labels/a719e99c-1f9b-432e-8f1d-cb3de0f14dde", headers);
build_client_with_cert("https://label-production.graph.tdf-labs.io/v1/run/labels/a719e99c-1f9b-432e-8f1d-cb3de0f14dde", headers);
A14Client { client }
}

Expand Down
2 changes: 1 addition & 1 deletion tee-worker/litentry/core/assertion-build/src/a2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mod tests {

#[test]
fn build_a2_works() {
let mut data_provider_config = DataProviderConfig::new();
let mut data_provider_config = DataProviderConfig::new().unwrap();
data_provider_config
.set_litentry_discord_microservice_url("http://localhost:19527".to_string());
let guild_id_u: u64 = 919848390156767232;
Expand Down
4 changes: 2 additions & 2 deletions tee-worker/litentry/core/assertion-build/src/a20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern crate sgx_tstd as std;
use http::header::CONNECTION;
use http_req::response::Headers;
use itc_rest_client::{error::Error as RestClientError, RestGet, RestPath};
use lc_data_providers::{build_client, DataProviderConfig};
use lc_data_providers::{build_client_with_cert, DataProviderConfig};
use serde::{Deserialize, Serialize};

#[cfg(all(not(feature = "std"), feature = "sgx"))]
Expand Down Expand Up @@ -65,7 +65,7 @@ pub fn build(

let mut headers = Headers::new();
headers.insert(CONNECTION.as_str(), "close");
let mut client = build_client(&data_provider_config.litentry_archive_url, headers);
let mut client = build_client_with_cert(&data_provider_config.litentry_archive_url, headers);
let query = vec![("account", who.as_str())];
let value = client
.get_with::<String, EarlyBirdResponse>("".to_string(), query.as_slice())
Expand Down
2 changes: 1 addition & 1 deletion tee-worker/litentry/core/assertion-build/src/a3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ mod tests {

#[test]
fn build_a3_works() {
let mut data_provider_config = DataProviderConfig::new();
let mut data_provider_config = DataProviderConfig::new().unwrap();
data_provider_config
.set_litentry_discord_microservice_url("http://localhost:19527".to_string());
let guild_id_u: u64 = 919848390156767232;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ mod tests {
fn init() -> DataProviderConfig {
let _ = env_logger::builder().is_test(true).try_init();
let url = run(0).unwrap();
let mut data_provider_conifg = DataProviderConfig::new();
let mut data_provider_conifg = DataProviderConfig::new().unwrap();

data_provider_conifg.set_litentry_discord_microservice_url(url);
data_provider_conifg.set_contest_legend_discord_role_id("1034083718425493544".to_string());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ mod tests {
fn init() -> DataProviderConfig {
let _ = env_logger::builder().is_test(true).try_init();
let url = run(0).unwrap();
let mut data_provider_config = DataProviderConfig::new();
let mut data_provider_config = DataProviderConfig::new().unwrap();
data_provider_config.set_achainable_url(url);
data_provider_config
}
Expand Down
8 changes: 4 additions & 4 deletions tee-worker/litentry/core/assertion-build/src/lit_staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ use frame_support::{StorageHasher, Twox64Concat};
use http::header::CONNECTION;
use itc_rest_client::{
error::Error as RestClientError,
http_client::{DefaultSend, HttpClient},
http_client::{HttpClient, SendWithCertificateVerification},
rest_client::{Headers, RestClient},
RestPath, RestPost,
};
use itp_stf_primitives::types::AccountId;
use itp_utils::hex_display::AsBytesRef;
use lc_credentials::litentry_profile::lit_staking::UpdateLITStakingAmountCredential;
use lc_data_providers::build_client;
use lc_data_providers::build_client_with_cert;
use litentry_primitives::ParentchainBalance;
use pallet_parachain_staking::types::Delegator;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -70,7 +70,7 @@ pub struct JsonRPCResponse {
}

pub struct LitentryStakingClient {
client: RestClient<HttpClient<DefaultSend>>,
client: RestClient<HttpClient<SendWithCertificateVerification>>,
}

impl Default for LitentryStakingClient {
Expand All @@ -83,7 +83,7 @@ impl LitentryStakingClient {
pub fn new() -> Self {
let mut headers = Headers::new();
headers.insert(CONNECTION.as_str(), "close");
let client = build_client("https://litentry-rpc.dwellir.com:443", headers);
let client = build_client_with_cert("https://litentry-rpc.dwellir.com:443", headers);
LitentryStakingClient { client }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ mod tests {
fn init() -> DataProviderConfig {
let _ = env_logger::builder().is_test(true).try_init();
let url = run(0).unwrap() + "/nodereal_jsonrpc/";
let mut data_provider_config = DataProviderConfig::default();
let mut data_provider_config = DataProviderConfig::new().unwrap();

data_provider_config.set_nodereal_api_key("d416f55179dbd0e45b1a8ed030e3".into());
data_provider_config.set_nodereal_api_chain_network_url(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ mod tests {
fn init() -> DataProviderConfig {
let _ = env_logger::builder().is_test(true).try_init();
let url = run(0).unwrap() + "/nodereal_jsonrpc/";
let mut config = DataProviderConfig::new();
let mut config = DataProviderConfig::new().unwrap();

config.set_nodereal_api_key("d416f55179dbd0e45b1a8ed030e3".to_string());
config.set_nodereal_api_chain_network_url(url);
Expand Down
4 changes: 2 additions & 2 deletions tee-worker/litentry/core/assertion-build/src/oneblock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::*;
use http::header::{AUTHORIZATION, CONNECTION};
use http_req::response::Headers;
use itc_rest_client::{error::Error as RestClientError, RestGet, RestPath};
use lc_data_providers::{build_client, DataProviderConfig};
use lc_data_providers::{build_client_with_cert, DataProviderConfig};
use serde::{Deserialize, Serialize};
use std::string::ToString;

Expand Down Expand Up @@ -55,7 +55,7 @@ fn fetch_data_from_notion(
headers.insert("Notion-Version", "2022-06-28");
headers.insert(AUTHORIZATION.as_str(), oneblock_notion_key.as_str());

let mut client = build_client(oneblock_notion_url.as_str(), headers);
let mut client = build_client_with_cert(oneblock_notion_url.as_str(), headers);

client.get::<String, OneBlockResponse>(String::default()).map_err(|e| {
Error::RequestVCFailed(
Expand Down
2 changes: 1 addition & 1 deletion tee-worker/litentry/core/data-providers/src/achainable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ mod tests {
let _ = env_logger::builder().is_test(true).try_init();
let url = run(0).unwrap();

let mut data_provider_config = DataProviderConfig::new();
let mut data_provider_config = DataProviderConfig::new().unwrap();
data_provider_config.set_achainable_url(url);
AchainableClient::new(&data_provider_config)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ mod tests {
fn init() -> DataProviderConfig {
let _ = env_logger::builder().is_test(true).try_init();
let url = run(0).unwrap();
let mut data_provider_config = DataProviderConfig::new();
let mut data_provider_config = DataProviderConfig::new().unwrap();
data_provider_config.set_litentry_discord_microservice_url(url);
data_provider_config
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ mod tests {
fn init() -> DataProviderConfig {
let _ = env_logger::builder().is_test(true).try_init();
let url = run(0).unwrap();
let mut data_provider_config = DataProviderConfig::new();
let mut data_provider_config = DataProviderConfig::new().unwrap();
data_provider_config.set_discord_official_url(url);
data_provider_config
}
Expand Down
11 changes: 6 additions & 5 deletions tee-worker/litentry/core/data-providers/src/karat_dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ use crate::sgx_reexport_prelude::*;
extern crate sgx_tstd as std;

use crate::{
build_client, DataProviderConfig, Error, HttpError, ReqPath, RetryOption, RetryableRestGet,
build_client_with_cert, DataProviderConfig, Error, HttpError, ReqPath, RetryOption,
RetryableRestGet,
};
use http::header::CONNECTION;
use http_req::response::Headers;
use itc_rest_client::{
http_client::{DefaultSend, HttpClient},
http_client::{HttpClient, SendWithCertificateVerification},
rest_client::RestClient,
RestPath,
};
Expand All @@ -41,7 +42,7 @@ use std::{

pub struct KaratDaoClient {
retry_option: RetryOption,
client: RestClient<HttpClient<DefaultSend>>,
client: RestClient<HttpClient<SendWithCertificateVerification>>,
}

#[derive(Debug)]
Expand All @@ -60,7 +61,7 @@ impl KaratDaoClient {

let mut headers = Headers::new();
headers.insert(CONNECTION.as_str(), "close");
let client = build_client(api_url.as_str(), headers);
let client = build_client_with_cert(api_url.as_str(), headers);

KaratDaoClient { retry_option, client }
}
Expand Down Expand Up @@ -146,7 +147,7 @@ mod tests {
let _ = env_logger::builder().is_test(true).try_init();
let url = run(0).unwrap() + "/karat_dao/";

let mut config = DataProviderConfig::new();
let mut config = DataProviderConfig::new().unwrap();
config.set_karat_dao_api_url(url);
config
}
Expand Down
Loading

0 comments on commit 655fc19

Please sign in to comment.