-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
load generator config for confidential markets
- Loading branch information
1 parent
8609fc6
commit 17026b3
Showing
8 changed files
with
274 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ pub mod client; | |
mod handler; | ||
mod handler_funcs; | ||
mod kalypso; | ||
mod model; | ||
pub mod model; | ||
mod supervisord; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use std::{collections::HashMap, error::Error}; | ||
|
||
use async_trait::async_trait; | ||
|
||
use crate::common_deps::CommonDeps; | ||
|
||
use super::Operation; | ||
|
||
pub struct GeneratorConfig; | ||
|
||
#[async_trait] | ||
impl Operation for GeneratorConfig { | ||
async fn execute(&self, config: HashMap<String, String>) -> Result<(), String> { | ||
let load_generator_config_info = CommonDeps::load_operator_config_info(&config)?; | ||
load_config( | ||
load_generator_config_info.generator_client_url, | ||
load_generator_config_info.config, | ||
) | ||
.await | ||
.map_err(|_| "Failed loading generator config into the enclave.".to_string())?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
async fn load_config( | ||
generator_client_url: String, | ||
config: generator_client::model::GeneratorConfigSetupRequestBody, | ||
) -> Result<(), Box<dyn Error>> { | ||
// Initialize the HTTP client with a timeout (optional but recommended) | ||
let client = reqwest::Client::builder() | ||
.timeout(std::time::Duration::from_secs(10)) | ||
.build()?; | ||
let full_url = format!("{}/api/generatorConfigSetup", generator_client_url); | ||
|
||
// Prepare the headers | ||
let mut headers = reqwest::header::HeaderMap::new(); | ||
headers.insert(reqwest::header::CONTENT_TYPE, "application/json".parse()?); | ||
|
||
// Send the POST request | ||
let response = client | ||
.post(&full_url) | ||
.headers(headers) | ||
.json(&config) | ||
.send() | ||
.await?; | ||
|
||
// Capture the HTTP status before moving the response | ||
let status = response.status(); | ||
|
||
// Read the response body as text | ||
let response_text = response.text().await?; | ||
|
||
let json_response: kalypso_helper::response::JsonResponse = | ||
match serde_json::from_str(&response_text) { | ||
Ok(resp) => resp, | ||
Err(e) => { | ||
return Err(format!( | ||
"Failed to parse JSON response. HTTP Status: {}, Body: {}, Error: {}", | ||
status, response_text, e | ||
) | ||
.into()) | ||
} | ||
}; | ||
|
||
// Check the HTTP status and the JSON message | ||
if status.is_success() { | ||
println!("{:?}", json_response); | ||
Ok(()) | ||
} else { | ||
// Return error with message | ||
Err(format!( | ||
"Failed to load config. HTTP Status: {}, Message: {}", | ||
status, json_response.message | ||
) | ||
.into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters