1
0
Fork 0
anime-calendar/build.rs
2024-11-28 23:37:28 +01:00

47 Zeilen
1,3 KiB
Rust

use serde::Deserialize;
use tokio::runtime::LocalRuntime;
#[cfg(feature = "secrets")]
use vaultrs::{
client::{VaultClient, VaultClientSettingsBuilder},
error::ClientError,
kv2,
};
#[derive(Debug, Deserialize)]
struct MALKey {
clientid: String,
clientsecret: String,
}
impl Default for MALKey {
fn default() -> Self {
MALKey {
clientid: "UNSET".into(),
clientsecret: "UNSET".into(),
}
}
}
fn main() {
println!("cargo::rerun-if-changed=build.rs");
#[allow(unused_variables)]
let runtime = LocalRuntime::new().expect("Local runtime failed to setup");
let mut data = MALKey::default();
#[cfg(feature = "mal")]
{
let client = VaultClient::new(
VaultClientSettingsBuilder::default()
.build()
.unwrap(),
)
.unwrap();
let secret: Result<MALKey, ClientError> = runtime.block_on(async { kv2::read(&client, "builds", "myanimelist").await });
match secret {
Ok(vaultdata) => data = vaultdata,
Err(error) => {
println!("cargo::warning=Failed to get secret from the vault: {}", error.to_string());
},
};
}
println!("cargo::rustc-env=MAL_CLIENTID={}\ncargo::rustc-env=MAL_CLIENTSECRET={}", data.clientid, data.clientsecret);
}