1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
45mod fs_client;
6pub(crate) mod http_client;
7pub(crate) mod null_client;
8use crate::error::{NimbusError, Result};
9use crate::Experiment;
10use fs_client::FileSystemClient;
11use null_client::NullClient;
12use remote_settings::RemoteSettings;
13use remote_settings::RemoteSettingsConfig;
1415pub(crate) fn create_client(
16 config: Option<RemoteSettingsConfig>,
17) -> Result<Box<dyn SettingsClient + Send>> {
18Ok(match config {
19Some(config) => {
20assert!(config.server_url.is_none());
21let Some(remote_settings_server) = config.server.as_ref() else {
22return Ok(Box::new(RemoteSettings::new(config)?));
23 };
24let url = remote_settings_server.url()?;
25if url.scheme() == "file" {
26// Everything in `config` other than the url/path is ignored for the
27 // file-system - we could insist on a sub-directory, but that doesn't
28 // seem valuable for the use-cases we care about here.
29let path = match url.to_file_path() {
30Ok(path) => path,
31_ => return Err(NimbusError::InvalidPath(url.into())),
32 };
33 Box::new(FileSystemClient::new(path)?)
34 } else {
35 Box::new(RemoteSettings::new(config)?)
36 }
37 }
38// If no server is provided, then we still want Nimbus to work, but serving
39 // an empty list of experiments.
40None => Box::new(NullClient::new()),
41 })
42}
4344// The trait used to fetch experiments.
45pub(crate) trait SettingsClient {
46#[allow(dead_code)]
47fn get_experiments_metadata(&self) -> Result<String>;
48fn fetch_experiments(&self) -> Result<Vec<Experiment>>;
49}