diff --git a/src/utils.rs b/src/utils.rs index e68aca7..f03f47b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -7,10 +7,37 @@ use std::io::{Write}; use std::net::TcpStream; use std::path::Path; use std::process::{Command}; +use hyper_tls::HttpsConnector; +use hyper::Client; +use hyper::http::StatusCode; +use std::error::Error; use crate::defs::{SSHAccess,Cntrllr}; use crate::clouds::defs::{Cloud}; +pub async fn https_check(url: &str) -> Result<(), Box> { + let https = HttpsConnector::new(); + let client = Client::builder().build::<_, hyper::Body>(https); + let req = client.get(url.parse()?).await; + match req { + Ok(res) => + match res.status() { + StatusCode::OK => { + println!("OK"); + Ok(()) + }, + _ => { + dbg!(res.status()); + println!("Err"); + Err("Error".into()) + }, + }, + Err(e) => { + Err(format!("Error {}: {}",&url,e).into()) + }, + } +} + pub fn parse_yaml_value(value: serde_yaml::Value, key: String, ctx: &mut tera::Context ) { if let Some(v) = value.as_str() { ctx.insert(key.to_owned(),&v);