diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-12-31 09:00:21 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-12-31 12:10:10 +0200 |
commit | acf1ba3f8f1492b961c9a6eb09eb93e882f5eb3f (patch) | |
tree | 1ce0288f878cac71990bb01f358d6035f1626c92 /src/config.rs | |
parent | 686e87981db210fa443404c8473dfe7a3f39b241 (diff) | |
download | obnam2-acf1ba3f8f1492b961c9a6eb09eb93e882f5eb3f.tar.gz |
docs: add documentation comments to crate
Also, make it an error for a public symbol to not be documented.
Sponsored-by: author
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs index 8f5d4d8..a9be716 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,3 +1,5 @@ +//! Client configuration. + use crate::passwords::{passwords_filename, PasswordError, Passwords}; use bytesize::MIB; @@ -19,18 +21,29 @@ struct TentativeClientConfig { exclude_cache_tag_directories: Option<bool>, } +/// Configuration for the Obnam client. #[derive(Debug, Serialize, Clone)] pub struct ClientConfig { + /// Name of configuration file. pub filename: PathBuf, + /// URL of Obnam server. pub server_url: String, + /// Should server's TLS certificate be verified using CA + /// signatures? Set to false, for self-signed certificates. pub verify_tls_cert: bool, + /// Size of chunks when splitting files for backup. pub chunk_size: usize, + /// Backup root directories. pub roots: Vec<PathBuf>, + /// File where logs should be written. pub log: PathBuf, + /// Should cache directories be excluded? Cache directories + /// contain a specially formatted CACHEDIR.TAG file. pub exclude_cache_tag_directories: bool, } impl ClientConfig { + /// Read a client configuration from a file. pub fn read(filename: &Path) -> Result<Self, ClientConfigError> { trace!("read_config: filename={:?}", filename); let config = std::fs::read_to_string(filename) @@ -75,29 +88,39 @@ impl ClientConfig { Ok(()) } + /// Read encryption passwords from a file. + /// + /// The password file is expected to be next to the configuration file. pub fn passwords(&self) -> Result<Passwords, ClientConfigError> { Passwords::load(&passwords_filename(&self.filename)) .map_err(ClientConfigError::PasswordsMissing) } } +/// Possible errors from configuration files. #[derive(Debug, thiserror::Error)] pub enum ClientConfigError { + /// The configuration specifies the server URL as an empty string. #[error("server_url is empty")] ServerUrlIsEmpty, + /// The configuration does not specify any backup root directories. #[error("No backup roots in config; at least one is needed")] NoBackupRoot, + /// The server URL is not an https: one. #[error("server URL doesn't use https: {0}")] NotHttps(String), + /// There are no passwords stored. #[error("No passwords are set: you may need to run 'obnam init': {0}")] PasswordsMissing(PasswordError), + /// Error reading a configuation file. #[error("failed to read configuration file {0}: {1}")] Read(PathBuf, std::io::Error), + /// Error parsing configuration file as YAML. #[error("failed to parse configuration file {0} as YAML: {1}")] YamlParse(PathBuf, serde_yaml::Error), } |