From 8f3b51d85eb3f192b23357b94a23f06ba2a7fff6 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 3 Mar 2021 10:55:19 +0200 Subject: refactor: rename Config, ConfigError to show they are for server --- src/bin/obnam-server.rs | 8 ++++---- src/server.rs | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/bin/obnam-server.rs b/src/bin/obnam-server.rs index 47f2b16..ddbfce3 100644 --- a/src/bin/obnam-server.rs +++ b/src/bin/obnam-server.rs @@ -5,7 +5,7 @@ use obnam::chunk::DataChunk; use obnam::chunkid::ChunkId; use obnam::chunkmeta::ChunkMeta; use obnam::indexedstore::IndexedStore; -use obnam::server::{Config, ConfigError}; +use obnam::server::{ServerConfig, ServerConfigError}; use serde::Serialize; use std::collections::HashMap; use std::default::Default; @@ -35,7 +35,7 @@ async fn main() -> anyhow::Result<()> { if addresses.is_empty() { error!("specified address is empty set: {:?}", addresses); eprintln!("ERROR: server address is empty: {:?}", addresses); - return Err(ConfigError::BadServerAddress.into()); + return Err(ServerConfigError::BadServerAddress.into()); } let store = IndexedStore::new(&config.chunks)?; @@ -84,8 +84,8 @@ async fn main() -> anyhow::Result<()> { Ok(()) } -fn load_config(filename: &Path) -> Result { - let config = Config::read_config(&filename).with_context(|| { +fn load_config(filename: &Path) -> Result { + let config = ServerConfig::read_config(&filename).with_context(|| { format!( "Couldn't read default configuration file {}", filename.display() diff --git a/src/server.rs b/src/server.rs index 01a6958..2bd32ef 100644 --- a/src/server.rs +++ b/src/server.rs @@ -7,7 +7,7 @@ use std::default::Default; use std::path::{Path, PathBuf}; #[derive(Debug, Deserialize, Clone)] -pub struct Config { +pub struct ServerConfig { pub chunks: PathBuf, pub address: String, pub tls_key: PathBuf, @@ -15,7 +15,7 @@ pub struct Config { } #[derive(Debug, thiserror::Error)] -pub enum ConfigError { +pub enum ServerConfigError { #[error("Directory for chunks {0} does not exist")] ChunksDirNotFound(PathBuf), @@ -29,23 +29,23 @@ pub enum ConfigError { BadServerAddress, } -impl Config { - pub fn read_config(filename: &Path) -> anyhow::Result { +impl ServerConfig { + pub fn read_config(filename: &Path) -> anyhow::Result { let config = std::fs::read_to_string(filename)?; - let config: Config = serde_yaml::from_str(&config)?; + let config: Self = serde_yaml::from_str(&config)?; config.check()?; Ok(config) } pub fn check(&self) -> anyhow::Result<()> { if !self.chunks.exists() { - return Err(ConfigError::ChunksDirNotFound(self.chunks.clone()).into()); + return Err(ServerConfigError::ChunksDirNotFound(self.chunks.clone()).into()); } if !self.tls_cert.exists() { - return Err(ConfigError::TlsCertNotFound(self.tls_cert.clone()).into()); + return Err(ServerConfigError::TlsCertNotFound(self.tls_cert.clone()).into()); } if !self.tls_key.exists() { - return Err(ConfigError::TlsKeyNotFound(self.tls_key.clone()).into()); + return Err(ServerConfigError::TlsKeyNotFound(self.tls_key.clone()).into()); } Ok(()) } -- cgit v1.2.1