pub struct Var { /* private fields */ }Expand description
A managed environment variable.
Var carries only metadata. The actual value is stored separately:
- For
VarKind::Secret, the value lives in theSecretStore. - For
VarKind::Plain, the value lives in theMetadataStoreand is fetched on demand so we do not keep it in memory across operations.
§Examples
use evault_core::model::{Var, Group, VarKind};
let v = Var::new("DATABASE_URL", Group::User, VarKind::Secret);
assert_eq!(v.name(), "DATABASE_URL");
assert_eq!(v.kind(), VarKind::Secret);Implementations§
Source§impl Var
impl Var
Sourcepub fn new(name: impl Into<String>, group: Group, kind: VarKind) -> Self
pub fn new(name: impl Into<String>, group: Group, kind: VarKind) -> Self
Create a new Var from already-validated input.
This constructor does not call Self::validate_name; it is
intended for tests and code paths that have already validated the
name upstream. Never call this directly with user-supplied input:
use Self::try_new instead.
Sourcepub fn try_new(
name: impl Into<String>,
group: Group,
kind: VarKind,
) -> Result<Self, MetadataError>
pub fn try_new( name: impl Into<String>, group: Group, kind: VarKind, ) -> Result<Self, MetadataError>
Create a new Var from possibly-untrusted input, validating the
name through Self::validate_name.
This is the constructor that CLI/TUI surfaces and any other path that accepts user input should use.
§Errors
Returns MetadataError::Invalid if name does not satisfy
Self::validate_name.
§Examples
use evault_core::model::{Var, Group, VarKind};
assert!(Var::try_new("DATABASE_URL", Group::User, VarKind::Plain).is_ok());
assert!(Var::try_new("1BAD", Group::User, VarKind::Plain).is_err());Sourcepub const fn from_trusted_parts(
id: VarId,
name: String,
group: Group,
kind: VarKind,
tags: Vec<String>,
length: usize,
created_at: OffsetDateTime,
updated_at: OffsetDateTime,
) -> Self
pub const fn from_trusted_parts( id: VarId, name: String, group: Group, kind: VarKind, tags: Vec<String>, length: usize, created_at: OffsetDateTime, updated_at: OffsetDateTime, ) -> Self
Reconstruct a Var from already-stored fields without re-validating.
This bypasses Self::validate_name. Reach for it only from a code path
where the data has demonstrably been validated upstream — e.g. tests or
in-process serialization. Backends that rehydrate from external storage
(SQLite, files, …) must call Self::try_from_parts instead so that a
corrupted or tampered row cannot inject malformed names into the rest of
the system.
Sourcepub fn try_from_parts(
id: VarId,
name: String,
group: Group,
kind: VarKind,
tags: Vec<String>,
length: usize,
created_at: OffsetDateTime,
updated_at: OffsetDateTime,
) -> Result<Self, MetadataError>
pub fn try_from_parts( id: VarId, name: String, group: Group, kind: VarKind, tags: Vec<String>, length: usize, created_at: OffsetDateTime, updated_at: OffsetDateTime, ) -> Result<Self, MetadataError>
Reconstruct a Var from already-stored fields, re-validating the
name through Self::validate_name.
This is the entry point that storage backends (SQLCipher,
in-memory, …) should use when rehydrating rows: it ensures a tampered
or corrupted database cannot smuggle in a malformed variable name.
§Errors
Returns MetadataError::Invalid if name does not satisfy
Self::validate_name.
Sourcepub fn validate_name(candidate: &str) -> Result<&str, MetadataError>
pub fn validate_name(candidate: &str) -> Result<&str, MetadataError>
Validate that candidate is acceptable as a variable name.
Accepted names follow the conventional environment-variable shape:
- non-empty
- 64 characters or fewer
- first character is an ASCII letter or underscore
- subsequent characters are ASCII alphanumerics or underscores
§Errors
Returns MetadataError::Invalid if any rule is violated.
§Examples
use evault_core::model::Var;
assert!(Var::validate_name("DATABASE_URL").is_ok());
assert!(Var::validate_name("").is_err());
assert!(Var::validate_name("1BAD").is_err());Returns the tag list.
Replaces the tag list.
Tags are not deduplicated nor sorted; callers should apply their own normalization where it matters.
Sourcepub const fn length(&self) -> usize
pub const fn length(&self) -> usize
Returns the length of the value (without revealing it).
The length is captured at write-time by the registry and is intended for display only.
Sourcepub fn set_length(&mut self, length: usize)
pub fn set_length(&mut self, length: usize)
Sets the recorded value length and bumps updated_at.
Sourcepub const fn created_at(&self) -> OffsetDateTime
pub const fn created_at(&self) -> OffsetDateTime
Returns when the variable was created (UTC).
Sourcepub const fn updated_at(&self) -> OffsetDateTime
pub const fn updated_at(&self) -> OffsetDateTime
Returns when the variable was last modified (UTC).