Skip to content

Commit

Permalink
fix: execute totp command correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrutchf committed Nov 25, 2024
1 parent 7139f23 commit 607f370
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
23 changes: 13 additions & 10 deletions src/credential_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,19 @@ impl Credential {
match self.totp_command.clone() {
Some(totp_command) => {
info!("TOTP command found.");

let parts = totp_command.split(" ").collect::<Vec<&str>>();
let command = parts.first()?.to_string();
let args = totp_command[command.len()..].to_string();

debug!("Executing TOTP command.");
let output = Command::new(command.as_str())
.arg(args.as_str())
.output()
.expect("failed to execute process");

let output = if cfg!(target_os = "windows") {
Command::new("cmd")
.args(["/C", totp_command.as_str()])
.output()
.expect("failed to execute process")
} else {
Command::new("sh")
.arg("-c")
.arg(totp_command.as_str())
.output()
.expect("failed to execute process")
};

Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
},
Expand Down
3 changes: 1 addition & 2 deletions src/subcommands/login_subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ impl Subcommand for LoginSubcommand {

let mut file_station = SynologyFileStation::new(url);
file_station.login(&credential).await?;

// TODO; Handle InvalidUserDoesThisFileOperation

credential_manager.set_credential(url, &credential)?;

Ok(())
Expand Down

0 comments on commit 607f370

Please sign in to comment.