restflow_core/models/
secrets.rs

1//! Secret model for secure credential storage.
2//! Values are base64 encoded in storage for additional security.
3
4use serde::{Deserialize, Serialize};
5use ts_rs::TS;
6
7#[derive(Debug, Clone, Serialize, Deserialize, TS)]
8#[ts(export)]
9pub struct Secret {
10    pub key: String,
11    pub value: String,
12    pub description: Option<String>,
13    #[ts(type = "number")]
14    pub created_at: i64,
15    #[ts(type = "number")]
16    pub updated_at: i64,
17}
18
19impl Secret {
20    pub fn new(key: String, value: String, description: Option<String>) -> Self {
21        let now = chrono::Utc::now().timestamp_millis();
22        Self {
23            key,
24            value,
25            description,
26            created_at: now,
27            updated_at: now,
28        }
29    }
30
31    pub fn update(&mut self, value: String, description: Option<String>) {
32        self.value = value;
33        self.description = description;
34        self.updated_at = chrono::Utc::now().timestamp_millis();
35    }
36}