Source code
Revision control
Copy as Markdown
Other Tools
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
//! This module defines the custom configurations that consumers can set.
//! Those configurations override default values and can be used to set a custom server,
//! collection name, and bucket name.
//! The purpose of the configuration parameters are to allow consumers an easy debugging option,
//! and the ability to be explicit about the server.
use url::Url;
use crate::{ApiResult, Error, Result};
/// Custom configuration for the client.
/// Currently includes the following:
/// - `server`: The Remote Settings server to use. If not specified, defaults to the production server (`RemoteSettingsServer::Prod`).
/// - `server_url`: An optional custom Remote Settings server URL. Deprecated; please use `server` instead.
/// - `bucket_name`: The optional name of the bucket containing the collection on the server. If not specified, the standard bucket will be used.
/// - `collection_name`: The name of the collection for the settings server.
#[derive(Debug, Clone, uniffi::Record)]
pub struct RemoteSettingsConfig {
pub collection_name: String,
#[uniffi(default = None)]
pub bucket_name: Option<String>,
#[uniffi(default = None)]
pub server_url: Option<String>,
#[uniffi(default = None)]
pub server: Option<RemoteSettingsServer>,
}
/// The Remote Settings server that the client should use.
#[derive(Debug, Clone, uniffi::Enum)]
pub enum RemoteSettingsServer {
Prod,
Stage,
Dev,
Custom { url: String },
}
impl RemoteSettingsServer {
/// Get the [url::Url] for this server
#[error_support::handle_error(Error)]
pub fn url(&self) -> ApiResult<Url> {
self.get_url()
}
/// Internal version of `url()`.
///
/// The difference is that it uses `Error` instead of `ApiError`. This is what we need to use
/// inside the crate.
pub(crate) fn get_url(&self) -> Result<Url> {
Ok(match self {
Self::Custom { url } => Url::parse(url)?,
})
}
}