nimbus/stateful/client/
mod.rs1mod fs_client;
6pub(crate) mod http_client;
7pub(crate) mod null_client;
8use std::sync::Arc;
9
10use crate::error::{NimbusError, Result};
11use crate::Experiment;
12use fs_client::FileSystemClient;
13use null_client::NullClient;
14use remote_settings::RemoteSettingsService;
15use url::Url;
16
17pub(crate) fn create_client(
18 rs_service: Option<Arc<RemoteSettingsService>>,
19 collection_name: Option<String>,
20) -> Result<Box<dyn SettingsClient + Send>> {
21 Ok(match (rs_service, collection_name) {
22 (Some(rs_service), Some(collection_name)) => {
23 let url = Url::parse(&rs_service.client_url())?; match url.scheme() {
25 "file" => {
26 let path = match url.to_file_path() {
30 Ok(path) => path,
31 _ => return Err(NimbusError::InvalidPath(url.into())),
32 };
33 Box::new(FileSystemClient::new(path)?)
34 }
35 _ => Box::new(rs_service.make_client(collection_name)),
36 }
37 }
38 (Some(_), None) => return Err(NimbusError::InternalError("collection name required")),
39 (None, _) => Box::new(NullClient::new()),
40 })
41}
42
43pub(crate) trait SettingsClient {
45 #[allow(dead_code)]
46 fn get_experiments_metadata(&self) -> Result<String>;
47 fn fetch_experiments(&self) -> Result<Vec<Experiment>>;
48}