Skip to main content

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::time::Duration;
27
28#[derive(Clone)]
29#[non_exhaustive]
30pub struct OnDemandAgentManagerOptions {
31    pub seed_config: SeedConfig,
32    pub authenticator: Authenticator,
33
34    pub auth_mechanisms: Vec<AuthMechanism>,
35    pub tls_config: Option<TlsConfig>,
36    pub network: Option<String>,
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            network: None,
56            kv_config: KvConfig::default(),
57            http_config: HttpConfig::default(),
58            tcp_keep_alive_time: None,
59            orphan_response_handler: None,
60        }
61    }
62
63    pub fn seed_config(mut self, seed_config: SeedConfig) -> Self {
64        self.seed_config = seed_config;
65        self
66    }
67
68    pub fn authenticator(mut self, authenticator: Authenticator) -> Self {
69        self.authenticator = authenticator;
70        self
71    }
72
73    pub fn tls_config(mut self, tls_config: impl Into<Option<TlsConfig>>) -> Self {
74        self.tls_config = tls_config.into();
75        self
76    }
77
78    pub fn compression_config(mut self, compression_config: CompressionConfig) -> Self {
79        self.compression_config = compression_config;
80        self
81    }
82
83    pub fn config_poller_config(mut self, config_poller_config: ConfigPollerConfig) -> Self {
84        self.config_poller_config = config_poller_config;
85        self
86    }
87
88    pub fn auth_mechanisms(mut self, auth_mechanisms: impl Into<Vec<AuthMechanism>>) -> Self {
89        self.auth_mechanisms = auth_mechanisms.into();
90        self
91    }
92
93    pub fn network(mut self, network: impl Into<String>) -> Self {
94        self.network = Some(network.into());
95        self
96    }
97
98    pub fn kv_config(mut self, kv_config: KvConfig) -> Self {
99        self.kv_config = kv_config;
100        self
101    }
102
103    pub fn http_config(mut self, http_config: HttpConfig) -> Self {
104        self.http_config = http_config;
105        self
106    }
107
108    pub fn tcp_keep_alive_time(mut self, tcp_keep_alive: Duration) -> Self {
109        self.tcp_keep_alive_time = Some(tcp_keep_alive);
110        self
111    }
112
113    pub fn orphan_reporter_handler(
114        mut self,
115        orphan_response_handler: Option<OrphanResponseHandler>,
116    ) -> Self {
117        self.orphan_response_handler = orphan_response_handler;
118        self
119    }
120}
121
122impl From<OnDemandAgentManagerOptions> for AgentOptions {
123    fn from(opts: OnDemandAgentManagerOptions) -> Self {
124        AgentOptions {
125            tls_config: opts.tls_config,
126            authenticator: opts.authenticator,
127            bucket_name: None,
128            network: opts.network,
129            seed_config: opts.seed_config,
130            compression_config: opts.compression_config,
131            config_poller_config: opts.config_poller_config,
132            auth_mechanisms: opts.auth_mechanisms,
133            kv_config: opts.kv_config,
134            http_config: opts.http_config,
135            tcp_keep_alive_time: opts.tcp_keep_alive_time,
136            orphan_response_handler: opts.orphan_response_handler,
137        }
138    }
139}
140
141impl From<AgentOptions> for OnDemandAgentManagerOptions {
142    fn from(opts: AgentOptions) -> Self {
143        OnDemandAgentManagerOptions {
144            authenticator: opts.authenticator,
145            network: opts.network,
146            tls_config: opts.tls_config,
147            seed_config: opts.seed_config,
148            compression_config: opts.compression_config,
149            config_poller_config: opts.config_poller_config,
150            auth_mechanisms: opts.auth_mechanisms,
151            kv_config: opts.kv_config,
152            http_config: opts.http_config,
153            tcp_keep_alive_time: opts.tcp_keep_alive_time,
154            orphan_response_handler: opts.orphan_response_handler,
155        }
156    }
157}