feat: check the remote profile

This commit is contained in:
GyDi 2022-05-06 01:26:24 +08:00
parent 28a4386975
commit 9694af82f4
No known key found for this signature in database
GPG Key ID: 1C95E0D3467B3084

View File

@ -1,6 +1,7 @@
use crate::utils::{dirs, help, tmpl}; use crate::utils::{dirs, help, tmpl};
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_yaml::Mapping;
use std::fs; use std::fs;
#[derive(Debug, Clone, Deserialize, Serialize)] #[derive(Debug, Clone, Deserialize, Serialize)]
@ -228,6 +229,11 @@ impl PrfItem {
let name = name.unwrap_or(uid.clone()); let name = name.unwrap_or(uid.clone());
let data = resp.text_with_charset("utf-8").await?; let data = resp.text_with_charset("utf-8").await?;
// check the data whether the valid yaml format
if !serde_yaml::from_str::<Mapping>(&data).is_ok() {
bail!("the remote profile data is not valid yaml");
}
Ok(PrfItem { Ok(PrfItem {
uid: Some(uid), uid: Some(uid),
itype: Some("remote".into()), itype: Some("remote".into()),