feat: add session and local id vars

This commit is contained in:
əlemi 2024-10-30 01:40:36 +01:00
parent ca228593e5
commit d7dff98c8a
3 changed files with 18 additions and 0 deletions

10
Cargo.lock generated
View file

@ -832,6 +832,7 @@ dependencies = [
"tokio",
"toml",
"toml_edit",
"uuid",
]
[[package]]
@ -1385,6 +1386,15 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "uuid"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a"
dependencies = [
"getrandom",
]
[[package]]
name = "vcpkg"
version = "0.2.15"

View file

@ -25,6 +25,7 @@ thiserror = "1.0.64"
tokio = { version = "1.40", features = ["rt-multi-thread"] }
toml = { version = "0.8", features = ["preserve_order"] }
toml_edit = { version = "0.22", features = ["serde"] } # only to pretty print tables ...
uuid = { version = "1.11", features = ["v4"] }
[profile.release]
opt-level = "z"

View file

@ -1,5 +1,10 @@
use std::{collections::HashMap, sync::OnceLock};
pub fn sid() -> &'static str {
static SID: std::sync::OnceLock<String> = std::sync::OnceLock::new();
SID.get_or_init(|| uuid::Uuid::new_v4().to_string())
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum StringOr<T> {
@ -75,6 +80,8 @@ pub trait FillableFromEnvironment: Sized {
let mut vars: std::collections::HashMap<String, String> = std::collections::HashMap::default();
vars.insert("POSTWOMAN_TIMESTAMP".to_string(), chrono::Local::now().timestamp().to_string());
vars.insert("POSTWOMAN_LOCAL_ID".to_string(), uuid::Uuid::new_v4().to_string());
vars.insert("POSTWOMAN_SESSION_ID".to_string(), sid().to_string());
for (k, v) in env {
vars.insert(k.to_string(), stringify_toml(v));