vault_client_rs/types/
consul.rs1use std::fmt;
2
3use secrecy::{ExposeSecret, SecretString};
4use serde::{Deserialize, Serialize};
5use zeroize::{Zeroize, ZeroizeOnDrop};
6
7use super::redaction::redact;
8
9#[derive(Debug, Serialize, Default, Zeroize, ZeroizeOnDrop)]
10pub struct ConsulConfigRequest {
11 pub address: String,
12 #[serde(skip_serializing_if = "Option::is_none")]
13 pub scheme: Option<String>,
14 #[serde(
15 serialize_with = "super::serde_secret::serialize_option",
16 skip_serializing_if = "Option::is_none"
17 )]
18 pub token: Option<SecretString>,
19}
20
21impl Clone for ConsulConfigRequest {
22 fn clone(&self) -> Self {
23 Self {
24 address: self.address.clone(),
25 scheme: self.scheme.clone(),
26 token: self.token.clone(),
27 }
28 }
29}
30
31#[derive(Debug, Deserialize, Clone)]
32#[non_exhaustive]
33pub struct ConsulConfig {
34 #[serde(default)]
35 pub address: String,
36 #[serde(default)]
37 pub scheme: String,
38}
39
40#[derive(Debug, Serialize, Default, Clone)]
41pub struct ConsulRoleRequest {
42 #[serde(skip_serializing_if = "Option::is_none")]
43 pub consul_policies: Option<Vec<String>>,
44 #[serde(skip_serializing_if = "Option::is_none")]
45 pub consul_roles: Option<Vec<String>>,
46 #[serde(skip_serializing_if = "Option::is_none")]
47 pub service_identities: Option<Vec<String>>,
48 #[serde(skip_serializing_if = "Option::is_none")]
49 pub node_identities: Option<Vec<String>>,
50 #[serde(skip_serializing_if = "Option::is_none")]
51 pub consul_namespace: Option<String>,
52 #[serde(skip_serializing_if = "Option::is_none")]
53 pub partition: Option<String>,
54 #[serde(skip_serializing_if = "Option::is_none")]
55 pub ttl: Option<String>,
56 #[serde(skip_serializing_if = "Option::is_none")]
57 pub max_ttl: Option<String>,
58 #[serde(skip_serializing_if = "Option::is_none")]
59 pub local: Option<bool>,
60}
61
62#[derive(Debug, Deserialize, Clone)]
63#[non_exhaustive]
64pub struct ConsulRole {
65 #[serde(default)]
66 pub consul_policies: Vec<String>,
67 #[serde(default)]
68 pub consul_roles: Vec<String>,
69 #[serde(default)]
70 pub service_identities: Vec<String>,
71 #[serde(default)]
72 pub node_identities: Vec<String>,
73 #[serde(default)]
74 pub ttl: u64,
75 #[serde(default)]
76 pub max_ttl: u64,
77 #[serde(default)]
78 pub local: bool,
79}
80
81#[derive(Deserialize, Zeroize, ZeroizeOnDrop)]
82#[non_exhaustive]
83pub struct ConsulCredentials {
84 pub token: SecretString,
85}
86
87impl Clone for ConsulCredentials {
88 fn clone(&self) -> Self {
89 Self {
90 token: self.token.clone(),
91 }
92 }
93}
94
95impl From<SecretString> for ConsulCredentials {
96 fn from(token: SecretString) -> Self {
97 Self { token }
98 }
99}
100
101impl From<&str> for ConsulCredentials {
102 fn from(token: &str) -> Self {
103 Self {
104 token: SecretString::from(token.to_owned()),
105 }
106 }
107}
108
109impl fmt::Debug for ConsulCredentials {
110 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
111 f.debug_struct("ConsulCredentials")
112 .field("token", &redact(self.token.expose_secret()))
113 .finish()
114 }
115}