From d18a4fb168de77ae93d8b8a3c43e9a75ca62e18b Mon Sep 17 00:00:00 2001 From: "Christopher L. Crutchfield" Date: Fri, 15 Nov 2024 22:53:57 -0800 Subject: [PATCH] feat: stubs of credential manager --- src/credential_manager.rs | 23 +++++++++++++++++++--- src/main.rs | 40 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/src/credential_manager.rs b/src/credential_manager.rs index 9f0cfef..ff0a2e5 100644 --- a/src/credential_manager.rs +++ b/src/credential_manager.rs @@ -1,12 +1,29 @@ +pub struct Credential { + // user: String, + // password: String, + // totp_command: String +} + pub struct CredentialManager { } impl CredentialManager { - fn get_password(&self, user: &str, url: &str) { - + pub fn get_credential(&self, url: &str) -> Credential { + Credential { + // user: "", + // password: "" + } + } + + pub fn has_credential(&self, url: &str) -> bool { + true + } + + pub fn remove_credential(&self, url: &str) { + } - fn set_password(&self, user: &str, url: &str, password: &str) { + pub fn set_credential(&self, url: &str, credential: &Credential) { } } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 06fcc5c..f1d1f0d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,10 +28,43 @@ fn cli() -> Command { .help("The URL for the Synology NAS") ) ) + .subcommand( + Command::new("logout") + .about("Deletes a login for the Synology NAS.") + .args_conflicts_with_subcommands(true) + .flatten_help(true) + .arg( + Arg::new("URL") + .short('l') + .long("url") + .required(true) + .help("The URL for the Synology NAS") + ) + ) +} + +fn login(user: &str, url: &str) { + let credential_manager = CredentialManager { }; + + if credential_manager.has_credential(url) { + // get password and totp command + } + else { + // get password and totop command + } + + // try login + // if success store + + // else throw error } -fn login() { +fn logout(url: &str) { let credential_manager = CredentialManager { }; + + if credential_manager.has_credential(url) { + credential_manager.remove_credential(url); + } } fn main() { @@ -39,8 +72,11 @@ fn main() { match matches.subcommand() { Some(("login", _)) => { - login(); + // login(); }, + Some(("logout", _)) => { + // logout(); + } _ => println!("No subcommand") } }