fixed get function of latest hayabusa version data #710
This commit is contained in:
@@ -124,19 +124,19 @@ impl App {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let now_version = configs::CONFIG.read().unwrap().app.get_version().unwrap();
|
||||
let now_version = &format!("v{}",configs::CONFIG.read().unwrap().app.get_version().unwrap());
|
||||
if latest_version_data.is_some()
|
||||
&& now_version
|
||||
!= latest_version_data
|
||||
.as_ref()
|
||||
.unwrap_or(&now_version.to_string())
|
||||
.unwrap_or(now_version)
|
||||
{
|
||||
write_color_buffer(
|
||||
&BufferWriter::stdout(ColorChoice::Always),
|
||||
None,
|
||||
&format!(
|
||||
"There is a new version of Hayabusa: {}",
|
||||
latest_version_data.unwrap()
|
||||
latest_version_data.unwrap().replace('\"',"")
|
||||
),
|
||||
true,
|
||||
)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use serde_json::Value;
|
||||
use crate::detections::message::AlertMessage;
|
||||
use crate::detections::utils::write_color_buffer;
|
||||
use crate::filter;
|
||||
@@ -21,15 +22,19 @@ pub struct Update {}
|
||||
impl Update {
|
||||
/// get latest hayabusa version number.
|
||||
pub fn get_latest_hayabusa_version() -> Result<Option<String>, Box<dyn std::error::Error>> {
|
||||
let res = reqwest::blocking::get(
|
||||
let res = reqwest::blocking::Client::new().get(
|
||||
"https://api.github.com/repos/Yamato-Security/hayabusa/releases/latest",
|
||||
)?
|
||||
.json::<std::collections::HashMap<String, String>>()?;
|
||||
if let Some(o) = res.get("tag_name") {
|
||||
Ok(Some(o.to_owned()))
|
||||
} else {
|
||||
).header("User-Agent", "HayabusaUpdateChecker")
|
||||
.header("Accept", "application/vnd.github.v3+json").send()?;
|
||||
let text = res.text()?;
|
||||
let json_res:Value = serde_json::from_str(&text)?;
|
||||
|
||||
if json_res["tag_name"].is_null() {
|
||||
Ok(None)
|
||||
} else {
|
||||
Ok(Some(json_res["tag_name"].to_string()))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// update rules(hayabusa-rules subrepository)
|
||||
|
||||
Reference in New Issue
Block a user