couchbase_core/options/
ondemand_agentmanager.rs

1/*
2 *
3 *  * Copyright (c) 2025 Couchbase, Inc.
4 *  *
5 *  * Licensed under the Apache License, Version 2.0 (the "License");
6 *  * you may not use this file except in compliance with the License.
7 *  * You may obtain a copy of the License at
8 *  *
9 *  *    http://www.apache.org/licenses/LICENSE-2.0
10 *  *
11 *  * Unless required by applicable law or agreed to in writing, software
12 *  * distributed under the License is distributed on an "AS IS" BASIS,
13 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  * See the License for the specific language governing permissions and
15 *  * limitations under the License.
16 *
17 */
18
19use crate::auth_mechanism::AuthMechanism;
20use crate::authenticator::Authenticator;
21use crate::memdx::dispatcher::OrphanResponseHandler;
22use crate::options::agent::{
23    AgentOptions, CompressionConfig, ConfigPollerConfig, HttpConfig, KvConfig, SeedConfig,
24};
25use crate::tls_config::TlsConfig;
26use std::sync::Arc;
27use std::time::Duration;
28
29#[derive(Clone)]
30#[non_exhaustive]
31pub struct OnDemandAgentManagerOptions {
32    pub seed_config: SeedConfig,
33    pub authenticator: Authenticator,
34
35    pub auth_mechanisms: Vec<AuthMechanism>,
36    pub tls_config: Option<TlsConfig>,
37
38    pub compression_config: CompressionConfig,
39    pub config_poller_config: ConfigPollerConfig,
40    pub kv_config: KvConfig,
41    pub http_config: HttpConfig,
42    pub tcp_keep_alive_time: Option<Duration>,
43    pub orphan_response_handler: Option<OrphanResponseHandler>,
44}
45
46impl OnDemandAgentManagerOptions {
47    pub fn new(seed_config: SeedConfig, authenticator: Authenticator) -> Self {
48        Self {
49            tls_config: None,
50            authenticator,
51            seed_config,
52            compression_config: CompressionConfig::default(),
53            config_poller_config: ConfigPollerConfig::default(),
54            auth_mechanisms: vec![],
55            kv_config: KvConfig::default(),
56            http_config: HttpConfig::default(),
57            tcp_keep_alive_time: None,
58            orphan_response_handler: None,
59        }
60    }
61
62    pub fn seed_config(mut self, seed_config: SeedConfig) -> Self {
63        self.seed_config = seed_config;
64        self
65    }
66
67    pub fn authenticator(mut self, authenticator: Authenticator) -> Self {
68        self.authenticator = authenticator;
69        self
70    }
71
72    pub fn tls_config(mut self, tls_config: impl Into<Option<TlsConfig>>) -> Self {
73        self.tls_config = tls_config.into();
74        self
75    }
76
77    pub fn compression_config(mut self, compression_config: CompressionConfig) -> Self {
78        self.compression_config = compression_config;
79        self
80    }
81
82    pub fn config_poller_config(mut self, config_poller_config: ConfigPollerConfig) -> Self {
83        self.config_poller_config = config_poller_config;
84        self
85    }
86
87    pub fn auth_mechanisms(mut self, auth_mechanisms: impl Into<Vec<AuthMechanism>>) -> Self {
88        self.auth_mechanisms = auth_mechanisms.into();
89        self
90    }
91
92    pub fn kv_config(mut self, kv_config: KvConfig) -> Self {
93        self.kv_config = kv_config;
94        self
95    }
96
97    pub fn http_config(mut self, http_config: HttpConfig) -> Self {
98        self.http_config = http_config;
99        self
100    }
101
102    pub fn tcp_keep_alive_time(mut self, tcp_keep_alive: Duration) -> Self {
103        self.tcp_keep_alive_time = Some(tcp_keep_alive);
104        self
105    }
106
107    pub fn orphan_reporter_handler(
108        mut self,
109        orphan_response_handler: Option<OrphanResponseHandler>,
110    ) -> Self {
111        self.orphan_response_handler = orphan_response_handler;
112        self
113    }
114}
115
116impl From<OnDemandAgentManagerOptions> for AgentOptions {
117    fn from(opts: OnDemandAgentManagerOptions) -> Self {
118        AgentOptions {
119            tls_config: opts.tls_config,
120            authenticator: opts.authenticator,
121            bucket_name: None,
122            seed_config: opts.seed_config,
123            compression_config: opts.compression_config,
124            config_poller_config: opts.config_poller_config,
125            auth_mechanisms: opts.auth_mechanisms,
126            kv_config: opts.kv_config,
127            http_config: opts.http_config,
128            tcp_keep_alive_time: opts.tcp_keep_alive_time,
129            orphan_response_handler: opts.orphan_response_handler,
130        }
131    }
132}
133
134impl From<AgentOptions> for OnDemandAgentManagerOptions {
135    fn from(opts: AgentOptions) -> Self {
136        OnDemandAgentManagerOptions {
137            authenticator: opts.authenticator,
138            tls_config: opts.tls_config,
139            seed_config: opts.seed_config,
140            compression_config: opts.compression_config,
141            config_poller_config: opts.config_poller_config,
142            auth_mechanisms: opts.auth_mechanisms,
143            kv_config: opts.kv_config,
144            http_config: opts.http_config,
145            tcp_keep_alive_time: opts.tcp_keep_alive_time,
146            orphan_response_handler: opts.orphan_response_handler,
147        }
148    }
149}