wasmcloud_core/
secrets.rs1use std::fmt::{Debug, Formatter, Result};
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Deserialize, Serialize, Clone)]
6#[serde(tag = "kind", content = "value")]
9pub enum SecretValue {
10 String(String),
11 Bytes(Vec<u8>),
12}
13
14impl SecretValue {
15 #[must_use]
19 pub fn as_string(&self) -> Option<&str> {
20 match self {
21 SecretValue::String(s) => Some(s),
22 SecretValue::Bytes(_) => None,
23 }
24 }
25
26 #[must_use]
30 pub fn as_bytes(&self) -> Option<&[u8]> {
31 match self {
32 SecretValue::String(_) => None,
33 SecretValue::Bytes(b) => Some(b),
34 }
35 }
36}
37
38impl Debug for SecretValue {
40 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
41 match self {
42 SecretValue::String(_) => write!(f, "string(redacted)"),
43 SecretValue::Bytes(_) => write!(f, "bytes(redacted)"),
44 }
45 }
46}