Skip to content

Commit

Permalink
checking whether correct from servicinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
aaravm committed Jun 20, 2024
1 parent 02685c0 commit cbba4ae
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 63 deletions.
33 changes: 27 additions & 6 deletions lib/src/serviceinfo/mod.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
mod serviceinfo;
mod models;

use crate::transport::Transport;
use crate::configuration::Configuration;

#[derive(Clone)]
pub struct ServiceInfo {
transport: Transport,
}

impl ServiceInfo {
pub fn new(config: &Configuration) -> Self {
// todo: read service info from the server
ServiceInfo {
transport: Transport::new(&config.clone()),
}
pub fn new(transport: Transport)-> Self{
Self { transport }
}
pub async fn get_service_info(&self) -> Result<models::Service, Box<dyn std::error::Error>> {

let configuration = &self.transport.config;

let url = format!("{}/service-info", configuration.base_path);
let response = self.transport.get(&url,None).await;
match response {
Ok(response_body) => {
match serde_json::from_str::<models::Service>(&response_body) {
Ok(tes_create_task_response) => Ok(tes_create_task_response),
Err(e) => {
log::error!("Failed to deserialize response: {}", e);
Err("Failed to deserialize response".into())
},
}
},
Err(e) => {
log::error!("Error: {}", e);
Err(e)
},
}
}

}


// CHECK WHAT ALL ARE REQUIRED

use std::error;
Expand Down
48 changes: 0 additions & 48 deletions lib/src/serviceinfo/serviceinfo.rs

This file was deleted.

27 changes: 19 additions & 8 deletions lib/src/tes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod models;
use crate::transport::Transport;
use reqwest::Response;
use serde::ser;
use serde_json::json;
use crate::serviceinfo::ServiceInfo;
use crate::configuration::Configuration;
Expand Down Expand Up @@ -34,14 +36,17 @@ pub struct TES {
// *** see question above

impl TES {
pub fn new(config: &Configuration) -> Self {
// todo double check that it's really a TES using serviceinfo
TES {
config: config.clone(),
transport: Transport::new(config),
service_info: ServiceInfo::new(config)
}
pub async fn new(config: &Configuration) -> Self {
let transport = &Transport::new(config);
let service_info = &ServiceInfo::new(transport.clone());
let _resp = service_info.get_service_info().await;
// assert_eq!(_resp.name, "TES");
TES {
config: config.clone(),
transport: transport.clone(),
service_info: service_info.clone(),
}
}

pub async fn create(&self, task: TesTask/*, params: models::TesTask*/) -> Result<TesCreateTaskResponse, Box<dyn std::error::Error>> {
// todo: version in url based on serviceinfo or user config
Expand Down Expand Up @@ -102,7 +107,7 @@ mod tests {
async fn create_task() -> Result<String, Box<dyn std::error::Error>> {
let mut config = Configuration::default();
config.set_base_path("http://localhost:8080"); // expecting TES/Funnel, TODO autorun
let tes = TES::new(&config);
let tes = TES::new(&config).await;

let task_json = std::fs::read_to_string("./lib/sample/grape.tes").expect("Unable to read file");
let task: TesTask = serde_json::from_str(&task_json).expect("JSON was not well-formatted");
Expand Down Expand Up @@ -130,6 +135,12 @@ mod tests {
}

// not sure if we need the code bellow, it was autogenerated by openapi-generator as i understand
// struct for typed errors of method [`get_service_info`]
// #[derive(Debug, Clone, Serialize, Deserialize)]
// #[serde(untagged)]
// pub enum GetServiceInfoError {
// UnknownValue(serde_json::Value),
// }
// #[derive(Debug, Clone)]
// pub struct ResponseContent<T> {
// pub status: reqwest::StatusCode,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fmt;
use crate::configuration::Configuration;

// note: could implement custom certs handling, such as in-TEE generated ephemerial certs

#[derive(Clone)]
pub struct Transport {
pub config: Configuration,
pub client: reqwest::Client,
Expand Down

0 comments on commit cbba4ae

Please sign in to comment.