9c681c4b03
Committed / committed (pull_request) Successful in 50s
CI / cargo shear (pull_request) Successful in 6m16s
CI / prek (pull_request) Successful in 6m21s
CI / cargo shear (push) Successful in 7m0s
CI / prek (push) Successful in 8m36s
Release-plz / Release-plz Release (push) Successful in 7m19s
Release-plz / Release-plz PR (push) Successful in 8m0s
48 lines
1.4 KiB
Rust
48 lines
1.4 KiB
Rust
use schemars::JsonSchema;
|
|
use serde::{Deserialize, Deserializer, Serialize};
|
|
|
|
use crate::get_talos_path;
|
|
|
|
fn deserialize_schematic<'de, D>(deserializer: D) -> Result<String, D::Error>
|
|
where
|
|
D: Deserializer<'de>,
|
|
{
|
|
let name: String = Deserialize::deserialize(deserializer)?;
|
|
let path = get_talos_path().join("schematics").join(name);
|
|
let content = std::fs::read_to_string(path).unwrap().trim().to_owned();
|
|
|
|
let client = reqwest::blocking::ClientBuilder::new()
|
|
.user_agent(format!(
|
|
"{}/{}",
|
|
std::env!("CARGO_PKG_NAME"),
|
|
std::env!("CARGO_PKG_VERSION")
|
|
))
|
|
.build()
|
|
.unwrap();
|
|
|
|
let res = client
|
|
.post("https://factory.talos.dev/schematics")
|
|
.body(content)
|
|
.send()
|
|
.map_err(serde::de::Error::custom)?;
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
struct Response {
|
|
id: String,
|
|
}
|
|
|
|
let response: Response = serde_json::from_str(&res.text().map_err(serde::de::Error::custom)?)
|
|
.map_err(serde::de::Error::custom)?;
|
|
|
|
Ok(response.id)
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone, PartialEq, Eq)]
|
|
pub(crate) struct Schematic(#[serde(deserialize_with = "deserialize_schematic")] String);
|
|
|
|
impl std::fmt::Display for Schematic {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
f.write_str(&self.0)
|
|
}
|
|
}
|