♻️ refactor(rules): remove credentials config

- remove unused credentials configuration
- remove credentials file setting/getting logic
- rename config file to rules.toml
This commit is contained in:
Jeremiah Russell
2025-10-15 14:26:21 +01:00
committed by Jeremiah Russell
parent f3f3e22458
commit 2fa7cd21ab
2 changed files with 12 additions and 26 deletions

View File

@@ -84,6 +84,15 @@ fn get_logging(level: log::LevelFilter) -> env_logger::Builder {
}
fn get_config() -> Result<Rules> {
// let settings = Config::builder()
// // Add in `./Settings.toml`
// .add_source(config::File::with_name("examples/simple/Settings"))
// // Add in settings from the environment (with a prefix of APP)
// // Eg.. `APP_DEBUG=1 ./target/app` would set the `debug` key
// .add_source(config::Environment::with_prefix("APP"))
// .build()
// .unwrap();
match Rules::load() {
Ok(c) => Ok(c),
Err(_) => {

View File

@@ -16,7 +16,6 @@ use crate::{EolAction, Error, MessageAge, Result, Retention};
/// Configuration file for the program
#[derive(Debug, Serialize, Deserialize)]
pub struct Rules {
credentials: Option<String>,
rules: BTreeMap<String, EolRule>,
}
@@ -24,10 +23,7 @@ impl Default for Rules {
fn default() -> Self {
let rules = BTreeMap::new();
let mut cfg = Self {
credentials: Some("credential.json".to_string()),
rules,
};
let mut cfg = Self { rules };
cfg.add_rule(Retention::new(MessageAge::Years(1), true), None, false)
.add_rule(Retention::new(MessageAge::Weeks(1), true), None, false)
@@ -44,12 +40,6 @@ impl Rules {
Rules::default()
}
/// Set a name for the credentials file
pub fn set_credentials(&mut self, file_name: &str) -> &mut Self {
self.credentials = Some(file_name.to_string());
self
}
/// Get the contents of an existing rule
pub fn get_rule(&self, id: usize) -> Option<EolRule> {
self.rules.get(&id.to_string()).cloned()
@@ -189,9 +179,7 @@ impl Rules {
/// Save the current configuration to the file
pub fn save(&self) -> Result<()> {
let home_dir = env::home_dir().unwrap();
let path = PathBuf::new()
.join(home_dir)
.join(".cull-gmail/cull-gmail.toml");
let path = PathBuf::new().join(home_dir).join(".cull-gmail/rules.toml");
let res = toml::to_string(self);
log::trace!("toml conversion result: {res:#?}");
@@ -207,9 +195,7 @@ impl Rules {
/// Load the current configuration
pub fn load() -> Result<Rules> {
let home_dir = env::home_dir().unwrap();
let path = PathBuf::new()
.join(home_dir)
.join(".cull-gmail/cull-gmail.toml");
let path = PathBuf::new().join(home_dir).join(".cull-gmail/rules.toml");
log::trace!("Loading config from {}", path.display());
let input = read_to_string(path)?;
@@ -217,15 +203,6 @@ impl Rules {
Ok(config)
}
/// Return the credential file name
pub fn credential_file(&self) -> &str {
if let Some(file) = &self.credentials {
file
} else {
""
}
}
/// List the end of life rules set in the configuration
pub fn list_rules(&self) -> Result<()> {
for rule in self.rules.values() {