entrust_agent/
env.rs

1use std::borrow::Cow;
2use std::env::VarError;
3
4const ENT_AGENT_BIN: &str = "ENT_AGENT_BIN";
5const ENT_AGENT_PIN: &str = "ENT_AGENT_PIN";
6const ENT_AGENT_SECONDS: &str = "ENT_AGENT_SECONDS";
7pub const ENT_AGENT_SOCKET_NAME: &str = "ENT_AGENT_SOCKET_NAME";
8
9pub fn agent_bin() -> Cow<'static, str> {
10    std::env::var(ENT_AGENT_BIN)
11        .map(Cow::Owned)
12        .unwrap_or(Cow::Borrowed("ent-agent"))
13}
14
15pub fn agent_pin() -> Result<String, VarError> {
16    std::env::var(ENT_AGENT_PIN)
17}
18
19pub fn agent_seconds() -> Cow<'static, str> {
20    std::env::var(ENT_AGENT_SECONDS)
21        .ok()
22        .and_then(|v| v.parse::<usize>().ok().map(|_| Cow::Owned(v)))
23        .unwrap_or(Cow::Borrowed("600"))
24}
25
26pub fn agent_socket_name() -> Cow<'static, str> {
27    std::env::var(ENT_AGENT_SOCKET_NAME)
28        .map(Cow::Owned)
29        .unwrap_or(Cow::Borrowed("entrust-agent.sock"))
30}