use std::{thread, time};
use zap_api::ZapApiError;
use zap_api::ZapService;
fn main() -> Result<(), ZapApiError> {
let zap_url = "http://localhost:8090".to_string();
let zap_api_key = "ChangeMe".to_string();
let target_url = "http://localhost:8080".to_string();
let service = ZapService {
url: zap_url,
api_key: zap_api_key,
};
let res = zap_api::core::version(&service);
let zap_version;
match res {
Ok(v) => zap_version = v["version"].to_string(),
Err(e) => return Err(e),
}
println!("ZAP version : {}", zap_version);
println!("Starting the std spider");
let res = zap_api::spider::scan(
&service,
target_url,
"-1".to_string(), "true".to_string(), "".to_string(), "false".to_string(), );
let scan_id;
match res {
Ok(v) => scan_id = v["scan"].to_string(),
Err(e) => return Err(e),
}
println!("Scan id : {}", scan_id);
let mut status: i32 = 0;
while status < 100 {
thread::sleep(time::Duration::from_secs(1));
let res = zap_api::spider::status(&service, scan_id.clone());
match res {
Ok(v) => {
let res_status = &v["status"].as_str().unwrap();
status = res_status.parse::<i32>().unwrap();
}
Err(e) => return Err(e),
}
println!("Scan status : {}", status);
}
Ok(())
}