chore: apps_services & cleanup

This commit is contained in:
Jesús Pérez Lorenzo 2021-10-09 00:59:57 +01:00
parent 8a9fa96599
commit 97a2bfa891

View File

@ -15,10 +15,12 @@ use kloud::{
};
use clds::clouds::defs::{Cloud};
use crate::defs::{DataDBs}; // ,CollsData};
use clds::clouds::on_clouds::{on_cloud_req,on_cloud_name_req,get_cloud_check};
use clds::clouds::on_clouds::{on_cloud_req,on_cloud_name_req,get_cloud_check,get_apps_check};
pub async fn cloud_req(reqname: &str,cloud: &Cloud,reqenv: &ReqEnv,opts: &KloudQueryConfigFilters) -> String {
let mut result: String;
let mut liveness_result = String::from("");
let mut apps_result = String::from("");
if opts.grp.is_empty() {
result = on_cloud_req(&reqname,&cloud,&reqenv,&opts.tsksrvcs,&opts.srvrs,&opts.cld).await;
} else if opts.name.is_empty() {
@ -29,8 +31,12 @@ pub async fn cloud_req(reqname: &str,cloud: &Cloud,reqenv: &ReqEnv,opts: &KloudQ
result = on_cloud_name_req(&reqname,&cloud,&reqenv,&opts.tsksrvcs,&opts.srvrs,&source).await;
}
if opts.tsksrvcs.contains("liveness") {
result = format!("{}:{}{}:{}{}",r#"{"req""#,&result,r#","liveness""#,get_cloud_check(&reqenv).await,r#"}"#);
liveness_result = get_cloud_check(&reqenv).await;
}
if opts.tsksrvcs.contains("apps") {
apps_result = get_apps_check(&reqenv).await;
}
result = format!("{}:{}{}:{}{}:{}{}",r#"{"req""#,&result,r#","apps""#,&apps_result,r#","liveness""#,&liveness_result,r#"}"#);
match reqname {
"config" => {
result.to_owned()
@ -72,7 +78,7 @@ pub async fn config (
// println!("User: {} | {}",&user.user_id,&user.token);
// println!("LANG: {}",language);
// if prfx.as_str() == "ta" {
// if prfx.as_str() == "prfl" {
// let cur = db.colls.ta.entries.read();
// }
// let allow_origin = reqenv.websrvr().allow_origin;
@ -93,9 +99,9 @@ pub async fn config (
.body(result.to_string())
.into_response())
},
"ta" => {
/* let data = CollsData::get_ta_entries(db.colls.clone()).await;
let data_out: Vec<TopographicAnatomy> = data.iter().enumerate().filter(|(idx,(itm,_))|{
"prfl" => {
/* let data = CollsData::get_prfl_entries(db.colls.clone()).await;
let data_out: Vec<Profile> = data.iter().enumerate().filter(|(idx,(itm,_))|{
let mut skip = false;
if !opts.id.is_empty() && !itm.contains(&opts.id) { skip = true; }
if opts.start > 0 && idx < &(opts.start as usize) { skip = true; }
@ -110,7 +116,7 @@ pub async fn config (
.into_response())
/*
Ok(warp::reply::with_header(
// warp::reply::json(&CollsData::get_ta_entries(db.colls.clone()).await),
// warp::reply::json(&CollsData::get_prfl_entries(db.colls.clone()).await),
warp::http::Response::new(result),
// warp::http::Response::new(body),
"Access-Control-Allow-Origin",
@ -118,32 +124,6 @@ pub async fn config (
// Ok(warp::reply::json(&result))
*/
},
"tp" => {
// let result = CollsData::get_tp_entries(db.colls.clone()).await;
/* let data = CollsData::get_tp_entries(db.colls.clone()).await;
let data_out: Vec<TrackingPoint> = data.iter().enumerate().filter(|(idx,(itm,_))|{
let mut skip = false;
if !opts.id.is_empty() && !itm.contains(&opts.id) { skip = true; }
if opts.start > 0 && idx < &(opts.start as usize) { skip = true; }
if opts.end > 0 && idx > &(opts.end as usize) { skip = true; }
!skip
}).map(|(_,(_,value))| value).cloned().collect();
*/
let data_out: Vec<String> = Vec::new();
let result = serde_json::to_string(&data_out).unwrap_or_else(|_| String::from(""));
Ok(warp::http::Response::builder()
.body(result.to_string())
.into_response())
/*
Ok(warp::reply::with_header(
// warp::reply::json(&CollsData::get_tp_entries(db.colls.clone()).await),
warp::http::Response::new(result),
// warp::http::Response::new(body),
"Access-Control-Allow-Origin",
&allow_origin))
// Ok(warp::reply::json(&result))
*/
},
_ => {
//let result="";
let result = format!("list for '{}' undefined",&prfx);
@ -199,7 +179,7 @@ pub async fn provision (
// println!("User: {} | {}",&user.user_id,&user.token);
// println!("LANG: {}",language);
// if prfx.as_str() == "ta" {
// if prfx.as_str() == "prfl" {
// let cur = db.colls.ta.entries.read();
// }
// let allow_origin = reqenv.websrvr().allow_origin;
@ -222,9 +202,9 @@ pub async fn provision (
.body(result.to_string())
.into_response())
},
"ta" => {
/* let data = CollsData::get_ta_entries(db.colls.clone()).await;
let data_out: Vec<TopographicAnatomy> = data.iter().enumerate().filter(|(idx,(itm,_))|{
"prfl" => {
/* let data = CollsData::get_prfl_entries(db.colls.clone()).await;
let data_out: Vec<Profile> = data.iter().enumerate().filter(|(idx,(itm,_))|{
let mut skip = false;
if !opts.id.is_empty() && !itm.contains(&opts.id) { skip = true; }
if opts.start > 0 && idx < &(opts.start as usize) { skip = true; }
@ -239,7 +219,7 @@ pub async fn provision (
.into_response())
/*
Ok(warp::reply::with_header(
// warp::reply::json(&CollsData::get_ta_entries(db.colls.clone()).await),
// warp::reply::json(&CollsData::get_prfl_entries(db.colls.clone()).await),
warp::http::Response::new(result),
// warp::http::Response::new(body),
"Access-Control-Allow-Origin",
@ -247,32 +227,6 @@ pub async fn provision (
// Ok(warp::reply::json(&result))
*/
},
"tp" => {
// let result = CollsData::get_tp_entries(db.colls.clone()).await;
/* let data = CollsData::get_tp_entries(db.colls.clone()).await;
let data_out: Vec<TrackingPoint> = data.iter().enumerate().filter(|(idx,(itm,_))|{
let mut skip = false;
if !opts.id.is_empty() && !itm.contains(&opts.id) { skip = true; }
if opts.start > 0 && idx < &(opts.start as usize) { skip = true; }
if opts.end > 0 && idx > &(opts.end as usize) { skip = true; }
!skip
}).map(|(_,(_,value))| value).cloned().collect();
*/
let data_out: Vec<String> = Vec::new();
let result = serde_json::to_string(&data_out).unwrap_or_else(|_| String::from(""));
Ok(warp::http::Response::builder()
.body(result.to_string())
.into_response())
/*
Ok(warp::reply::with_header(
// warp::reply::json(&CollsData::get_tp_entries(db.colls.clone()).await),
warp::http::Response::new(result),
// warp::http::Response::new(body),
"Access-Control-Allow-Origin",
&allow_origin))
// Ok(warp::reply::json(&result))
*/
},
_ => {
//let result="";
let result = format!("list for '{}' undefined",&prfx);
@ -329,7 +283,7 @@ pub async fn status (
// println!("User: {} | {}",&user.user_id,&user.token);
// println!("LANG: {}",language);
// if prfx.as_str() == "ta" {
// if prfx.as_str() == "prfl" {
// let cur = db.colls.ta.entries.read();
// }
// let allow_origin = reqenv.websrvr().allow_origin;
@ -349,9 +303,9 @@ pub async fn status (
.body(result.to_string())
.into_response())
},
"ta" => {
/* let data = CollsData::get_ta_entries(db.colls.clone()).await;
let data_out: Vec<TopographicAnatomy> = data.iter().enumerate().filter(|(idx,(itm,_))|{
"prfl" => {
/* let data = CollsData::get_prfl_entries(db.colls.clone()).await;
let data_out: Vec<Profile> = data.iter().enumerate().filter(|(idx,(itm,_))|{
let mut skip = false;
if !opts.id.is_empty() && !itm.contains(&opts.id) { skip = true; }
if opts.start > 0 && idx < &(opts.start as usize) { skip = true; }
@ -366,7 +320,7 @@ pub async fn status (
.into_response())
/*
Ok(warp::reply::with_header(
// warp::reply::json(&CollsData::get_ta_entries(db.colls.clone()).await),
// warp::reply::json(&CollsData::get_prfl_entries(db.colls.clone()).await),
warp::http::Response::new(result),
// warp::http::Response::new(body),
"Access-Control-Allow-Origin",
@ -374,32 +328,6 @@ pub async fn status (
// Ok(warp::reply::json(&result))
*/
},
"tp" => {
// let result = CollsData::get_tp_entries(db.colls.clone()).await;
/* let data = CollsData::get_tp_entries(db.colls.clone()).await;
let data_out: Vec<TrackingPoint> = data.iter().enumerate().filter(|(idx,(itm,_))|{
let mut skip = false;
if !opts.id.is_empty() && !itm.contains(&opts.id) { skip = true; }
if opts.start > 0 && idx < &(opts.start as usize) { skip = true; }
if opts.end > 0 && idx > &(opts.end as usize) { skip = true; }
!skip
}).map(|(_,(_,value))| value).cloned().collect();
*/
let data_out: Vec<String> = Vec::new();
let result = serde_json::to_string(&data_out).unwrap_or_else(|_| String::from(""));
Ok(warp::http::Response::builder()
.body(result.to_string())
.into_response())
/*
Ok(warp::reply::with_header(
// warp::reply::json(&CollsData::get_tp_entries(db.colls.clone()).await),
warp::http::Response::new(result),
// warp::http::Response::new(body),
"Access-Control-Allow-Origin",
&allow_origin))
// Ok(warp::reply::json(&result))
*/
},
_ => {
//let result="";
let result = format!("list for '{}' undefined",&prfx);
@ -455,7 +383,7 @@ pub async fn liveness (
// println!("User: {} | {}",&user.user_id,&user.token);
// println!("LANG: {}",language);
// if prfx.as_str() == "ta" {
// if prfx.as_str() == "prfl" {
// let cur = db.colls.ta.entries.read();
// }
// let allow_origin = reqenv.websrvr().allow_origin;
@ -478,9 +406,9 @@ pub async fn liveness (
.body(result.to_string())
.into_response())
},
"ta" => {
/* let data = CollsData::get_ta_entries(db.colls.clone()).await;
let data_out: Vec<TopographicAnatomy> = data.iter().enumerate().filter(|(idx,(itm,_))|{
"prfl" => {
/* let data = CollsData::get_prfl_entries(db.colls.clone()).await;
let data_out: Vec<Profile> = data.iter().enumerate().filter(|(idx,(itm,_))|{
let mut skip = false;
if !opts.id.is_empty() && !itm.contains(&opts.id) { skip = true; }
if opts.start > 0 && idx < &(opts.start as usize) { skip = true; }
@ -495,7 +423,7 @@ pub async fn liveness (
.into_response())
/*
Ok(warp::reply::with_header(
// warp::reply::json(&CollsData::get_ta_entries(db.colls.clone()).await),
// warp::reply::json(&CollsData::get_prfl_entries(db.colls.clone()).await),
warp::http::Response::new(result),
// warp::http::Response::new(body),
"Access-Control-Allow-Origin",
@ -503,10 +431,88 @@ pub async fn liveness (
// Ok(warp::reply::json(&result))
*/
},
"tp" => {
// let result = CollsData::get_tp_entries(db.colls.clone()).await;
/* let data = CollsData::get_tp_entries(db.colls.clone()).await;
let data_out: Vec<TrackingPoint> = data.iter().enumerate().filter(|(idx,(itm,_))|{
_ => {
//let result="";
let result = format!("list for '{}' undefined",&prfx);
// (AuthError::UserNotFoundError.to_string())
println!("{}",&result);
Ok(warp::http::Response::builder()
.body(result.to_string())
.into_response())
/*
Ok(warp::reply::with_header(
// warp::reply::json(&""),
warp::http::Response::new(result),
// warp::http::Response::new(body),
"Access-Control-Allow-Origin",
&allow_origin))
*/
},
}
},
Err(e) => {
let result = format!("Error: no credentials found");
println!("{}",e);
Ok(warp::http::Response::builder()
.body(result.to_string())
.into_response())
/*
Ok(warp::reply::with_header(
// warp::reply::json(&""),
warp::http::Response::new(result),
"Access-Control-Allow-Origin",
&allow_origin))
*/
},
}
// }
}
pub async fn apps(
opts: KloudQueryConfigFilters,
header: HeaderMap<HeaderValue>,
method: Method,
// user: UserCtx,
db: DataDBs,
cloud: Cloud,
prfx: String,
// path: warp::path::FullPath, headers: warp::http::HeaderMap
) -> Result<impl Reply, Rejection> {
// dbg!("{:#?}",&db);
// dbg!("{:#?}",&header);
// dbg!("{:#?}",&opts);
let reqenv = ReqEnv::new(db.app, db.auth, header, method, "/apps", "apps", &prfx);
// if let Some(lang_str) = header.get("accept-language") {
// println!("{:?}",&lang_str);
// }
// println!("User: {} | {}",&user.user_id,&user.token);
// println!("LANG: {}",language);
// if prfx.as_str() == "prfl" {
// let cur = db.colls.ta.entries.read();
// }
// let allow_origin = reqenv.websrvr().allow_origin;
// let test = true;
// if test == true {
// let result = cloud_req("liveness",&cloud,&reqenv,&opts).await;
// println!("Result: {}",&result);
// return Ok(warp::http::Response::builder()
// .body(result.to_string())
// .into_response());
// } else {
match reqenv.user_authentication().await {
Ok(_auth) => {
// dbg!("auth: {}",&auth);
match prfx.as_str() {
"kloud" => {
let result = cloud_req("apps",&cloud,&reqenv,&opts).await;
println!("Result: {}",&result);
Ok(warp::http::Response::builder()
.body(result.to_string())
.into_response())
},
"prfl" => {
/* let data = CollsData::get_prfl_entries(db.colls.clone()).await;
let data_out: Vec<Profile> = data.iter().enumerate().filter(|(idx,(itm,_))|{
let mut skip = false;
if !opts.id.is_empty() && !itm.contains(&opts.id) { skip = true; }
if opts.start > 0 && idx < &(opts.start as usize) { skip = true; }
@ -521,11 +527,11 @@ pub async fn liveness (
.into_response())
/*
Ok(warp::reply::with_header(
// warp::reply::json(&CollsData::get_tp_entries(db.colls.clone()).await),
// warp::reply::json(&CollsData::get_prfl_entries(db.colls.clone()).await),
warp::http::Response::new(result),
// warp::http::Response::new(body),
"Access-Control-Allow-Origin",
&allow_origin))
&allow_origin))
// Ok(warp::reply::json(&result))
*/
},