chore: fix liveness and change if auth.role is empty
This commit is contained in:
		
							parent
							
								
									882ea24dea
								
							
						
					
					
						commit
						ab70fabbe3
					
				| @ -14,11 +14,11 @@ use app_auth::{UserCtx}; | ||||
| // 	},
 | ||||
| // };
 | ||||
| use clds::defs::{KloudCheckHome}; | ||||
| use clds::clouds::defs::{Cloud}; | ||||
| use clds::clouds::defs::{Cloud,SrvcsHostInfo,App,AppsrvcInfo,TskSrvc,TsksrvcInfo}; | ||||
| use crate::defs::{DataDBs}; // ,CollsData};
 | ||||
| use clds::clouds::on_clouds::{get_cloud_check,get_apps_check}; | ||||
| 
 | ||||
| pub async fn get_tsks_apps_check(reqenv: &ReqEnv, cld_indx: usize, _auth: UserCtx,_role: &str) -> String { | ||||
| pub async fn get_tsks_apps_check(reqenv: &ReqEnv, cld_indx: usize, _auth: UserCtx, role: &str) -> String { | ||||
| 	let result_apps = get_apps_check(&reqenv).await; | ||||
| 	// println!("Result apps: {}",&result_apps);
 | ||||
|   let res_apps: Vec<KloudCheckHome> = serde_json::from_str(&result_apps).unwrap_or_else(|e| { | ||||
| @ -26,7 +26,7 @@ pub async fn get_tsks_apps_check(reqenv: &ReqEnv, cld_indx: usize, _auth: UserCt | ||||
| 	 	Vec::new() | ||||
| 	}); | ||||
| 	// let mut list_groups = String::from("");
 | ||||
|   let mut grp_apps_hash: HashMap<String, BTreeMap<String,String>> = HashMap::new(); | ||||
|   let mut grp_apps_hash: HashMap<String, BTreeMap<String,Vec<SrvcsHostInfo>>> = HashMap::new(); | ||||
| 	if let Some(kld) = res_apps.get(cld_indx) { | ||||
| 		for grp in &kld.groups { | ||||
| 			// if !list_groups.is_empty() {
 | ||||
| @ -35,9 +35,32 @@ pub async fn get_tsks_apps_check(reqenv: &ReqEnv, cld_indx: usize, _auth: UserCt | ||||
|       // list_groups.push_str(&grp.name);
 | ||||
| 			let mut m_items = BTreeMap::new(); | ||||
|       for itm in &grp.items { | ||||
| 	      if let Some(data_liveness) = &itm.liveness { | ||||
|           m_items.insert(format!("{}",&itm.name),data_liveness.to_string()); | ||||
| 				let liveness: Vec<SrvcsHostInfo>; | ||||
| 				if role.is_empty() { | ||||
| 					liveness = itm.liveness.to_owned().into_iter().map(|it| { 
 | ||||
| 					  SrvcsHostInfo { | ||||
| 							hostname: format!("{}",&it.hostname), | ||||
| 							tsksrvcs: it.tsksrvcs.to_owned(), | ||||
| 							appsrvcs: it.appsrvcs.into_iter().map(|ap| { | ||||
| 								AppsrvcInfo { | ||||
| 									name: ap.name.to_owned(), | ||||
| 									info: ap.info.to_owned(), | ||||
| 									srvc: App { | ||||
| 									  name: ap.srvc.name.to_owned(), | ||||
| 										path: String::from(""), | ||||
| 										req: String::from(""), | ||||
| 										target: ap.srvc.target.to_owned(), | ||||
| 										liveness: String::from(""), | ||||
| 										critical: ap.srvc.critical.to_owned(), | ||||
| 									} | ||||
| 								} | ||||
| 							}).collect() | ||||
| 						} | ||||
| 					}).collect(); | ||||
| 				} else { | ||||
| 					liveness = itm.liveness.to_owned(); | ||||
| 				} | ||||
|         m_items.insert(format!("{}",&itm.name),liveness); | ||||
| 			} | ||||
|       grp_apps_hash.insert(format!("{}",grp.name),m_items); | ||||
| 		} | ||||
| @ -48,14 +71,37 @@ pub async fn get_tsks_apps_check(reqenv: &ReqEnv, cld_indx: usize, _auth: UserCt | ||||
| 		println!("Error serde apps json: {}",e); | ||||
| 	 	Vec::new() | ||||
| 	}); | ||||
| 	let mut grp_cloud_hash: HashMap<String, BTreeMap<String,String>> = HashMap::new(); | ||||
| 	let mut grp_cloud_hash: HashMap<String, BTreeMap<String,Vec<SrvcsHostInfo>>> = HashMap::new(); | ||||
| 	if let Some(kld) = res_cloud.get(cld_indx) { | ||||
| 		for grp in &kld.groups { | ||||
| 			let mut m_items = BTreeMap::new(); | ||||
|       for itm in &grp.items { | ||||
| 	      if let Some(data_liveness) = &itm.liveness { | ||||
|           m_items.insert(format!("{}",&itm.name),data_liveness.to_string()); | ||||
| 				let liveness: Vec<SrvcsHostInfo>; | ||||
| 				if role.is_empty() { | ||||
| 					liveness = itm.liveness.to_owned().into_iter().map(|it| { 
 | ||||
| 					  SrvcsHostInfo { | ||||
| 							hostname: format!("{}",&it.hostname), | ||||
| 							appsrvcs: it.appsrvcs.to_owned(), | ||||
| 							tsksrvcs: it.tsksrvcs.into_iter().map(|tsk| { | ||||
| 								TsksrvcInfo { | ||||
| 									name: tsk.name.to_owned(), | ||||
| 									info: tsk.info.to_owned(), | ||||
| 									srvc: TskSrvc { | ||||
| 									  name: tsk.srvc.name.to_owned(), | ||||
| 										path: String::from(""), | ||||
| 										req: String::from(""), | ||||
| 										target: tsk.srvc.target.to_owned(), | ||||
| 										liveness: String::from(""), | ||||
| 										critical: tsk.srvc.critical.to_owned(), | ||||
| 									} | ||||
| 								} | ||||
| 							}).collect() | ||||
| 						} | ||||
| 					}).collect(); | ||||
| 				} else { | ||||
| 					liveness = itm.liveness.to_owned(); | ||||
| 				} | ||||
|         m_items.insert(format!("{}",&itm.name),liveness.to_owned()); | ||||
| 			} | ||||
|       grp_cloud_hash.insert(format!("{}",grp.name),m_items); | ||||
| 		} | ||||
| @ -131,7 +177,7 @@ pub async fn home( | ||||
| 			//    &allow_origin))
 | ||||
| 			// Ok(warp::reply::json(&result))
 | ||||
| 		}, | ||||
| 		Err(e) => { | ||||
| 		Err(_e) => { | ||||
| 			// let result = format!("Error: no credentials found");
 | ||||
| 			// println!("{}",e);
 | ||||
| 			let result = get_tsks_apps_check(&reqenv,1,UserCtx::default(),"").await; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user