1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use crate::agent::AgentConfig;
use crate::{Agent, AgentError, Identity, NonceFactory, PasswordManager};
pub struct AgentBuilder {
config: AgentConfig,
}
impl Default for AgentBuilder {
fn default() -> Self {
Self {
config: Default::default(),
}
}
}
impl AgentBuilder {
pub fn build(self) -> Result<Agent, AgentError> {
Agent::new(self.config)
}
pub fn with_url<S: Into<String>>(self, url: S) -> Self {
AgentBuilder {
config: AgentConfig {
url: url.into(),
..self.config
},
}
}
pub fn with_nonce_factory(self, nonce_factory: NonceFactory) -> Self {
AgentBuilder {
config: AgentConfig {
nonce_factory,
..self.config
},
}
}
pub fn with_identity<I>(self, identity: I) -> Self
where
I: 'static + Identity + Send + Sync,
{
AgentBuilder {
config: AgentConfig {
identity: Box::new(identity),
..self.config
},
}
}
pub fn with_boxed_identity(self, identity: Box<dyn Identity + Send + Sync>) -> Self {
AgentBuilder {
config: AgentConfig {
identity,
..self.config
},
}
}
pub fn with_password_manager<P>(self, password_manager: P) -> Self
where
P: 'static + PasswordManager + Send + Sync,
{
AgentBuilder {
config: AgentConfig {
password_manager: Some(Box::new(password_manager)),
..self.config
},
}
}
pub fn with_boxed_password_manager(
self,
password_manager: Box<impl 'static + PasswordManager + Send + Sync>,
) -> Self {
AgentBuilder {
config: AgentConfig {
password_manager: Some(password_manager),
..self.config
},
}
}
pub fn with_ingress_expiry(self, duration: Option<std::time::Duration>) -> Self {
AgentBuilder {
config: AgentConfig {
ingress_expiry_duration: duration,
..self.config
},
}
}
}