fix ssh relative path

This commit is contained in:
Noor 2025-07-24 16:39:07 +05:30
parent 6893e8185e
commit 685418b6f0
Signed by: noormohammedb
GPG Key ID: D83EFB8B3B967146
3 changed files with 23 additions and 8 deletions

@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
use clap::builder::PossibleValue; use clap::builder::{PossibleValue, ValueParser};
use clap::{Arg, Command}; use clap::{Arg, Command};
use detee_cli::general::cli_handler::{ use detee_cli::general::cli_handler::{
handle_account, handle_completion, handle_operators, handle_packagers, handle_account, handle_completion, handle_operators, handle_packagers,
@ -642,6 +642,8 @@ fn clap_cmd() -> Command {
.subcommand(Command::new("ssh-pubkey-path").about("define the SSH pubkey that you want to use") .subcommand(Command::new("ssh-pubkey-path").about("define the SSH pubkey that you want to use")
.arg( .arg(
Arg::new("path") Arg::new("path")
.value_name("FILE")
.value_parser(ValueParser::path_buf())
.help("supply path to your public SSH key") .help("supply path to your public SSH key")
.required(true) .required(true)
) )

@ -187,9 +187,7 @@ impl Config {
} }
pub fn cli_dir_path() -> Result<String, Error> { pub fn cli_dir_path() -> Result<String, Error> {
let dir = std::env::var(CONFIG_OVERRIDE_PATH_ENV) let dir = Self::override_path();
.unwrap_or_else(|_| Self::home_dir() + ("/.detee/cli"));
if !Path::new(&dir).exists() { if !Path::new(&dir).exists() {
warn!("Could not config dir. Creating {dir}"); warn!("Could not config dir. Creating {dir}");
std::fs::create_dir_all(dir.clone())?; std::fs::create_dir_all(dir.clone())?;
@ -197,6 +195,12 @@ impl Config {
Ok(dir) Ok(dir)
} }
fn override_path() -> String {
let dir = std::env::var(CONFIG_OVERRIDE_PATH_ENV)
.unwrap_or_else(|_| Self::home_dir() + ("/.detee/cli"));
dir
}
fn config_path() -> Result<String, Error> { fn config_path() -> Result<String, Error> {
let config_path = Self::cli_dir_path()? + ("/cli-config.yaml"); let config_path = Self::cli_dir_path()? + ("/cli-config.yaml");
Ok(config_path) Ok(config_path)
@ -308,7 +312,13 @@ impl Config {
if self.ssh_key_path.is_empty() { if self.ssh_key_path.is_empty() {
return Err(Error::SshKeyNoDefined); return Err(Error::SshKeyNoDefined);
} }
if Path::new(&self.ssh_key_path).is_absolute() {
Ok(self.ssh_key_path.clone()) Ok(self.ssh_key_path.clone())
} else {
let ssh_key_path = format!("{}/{}", Self::override_path(), &self.ssh_key_path);
Ok(ssh_key_path)
}
} }
pub fn get_root_ca_path() -> Result<String, Error> { pub fn get_root_ca_path() -> Result<String, Error> {
@ -402,13 +412,13 @@ impl Config {
log::error!("The network is not set! To configure it, run:"); log::error!("The network is not set! To configure it, run:");
eprintln!(" detee-cli account network testnet"); eprintln!(" detee-cli account network testnet");
} else { } else {
account_data.network = config.network; account_data.network = config.network.clone();
} }
if config.ssh_key_path.is_empty() { if config.ssh_key_path.is_empty() {
log::error!("SSH public key path not set! To configure it, run:"); log::error!("SSH public key path not set! To configure it, run:");
eprintln!(" detee-cli account ssh-pubkey-path /home/your_user/.ssh/id_ed25519.pub"); eprintln!(" detee-cli account ssh-pubkey-path /home/your_user/.ssh/id_ed25519.pub");
} else { } else {
account_data.ssh_pubkey = config.ssh_key_path; account_data.ssh_pubkey = config.get_ssh_pubkey().unwrap_or_default();
} }
match Self::get_detee_wallet() { match Self::get_detee_wallet() {
Ok(key) => { Ok(key) => {

@ -6,6 +6,7 @@ use clap::{ArgMatches, Command};
use clap_complete::{generate, Shell}; use clap_complete::{generate, Shell};
use std::error::Error; use std::error::Error;
use std::io; use std::io;
use std::path::PathBuf;
pub fn handle_operators(matches: &ArgMatches) { pub fn handle_operators(matches: &ArgMatches) {
match matches.subcommand() { match matches.subcommand() {
@ -52,7 +53,9 @@ pub fn handle_account(matches: &ArgMatches) {
config::Config::init_config().sign_file(&path); config::Config::init_config().sign_file(&path);
} }
Some(("ssh-pubkey-path", path_subcommand)) => { Some(("ssh-pubkey-path", path_subcommand)) => {
let path: String = path_subcommand.get_one::<String>("path").unwrap().clone(); let path_buff = path_subcommand.get_one::<PathBuf>("path").unwrap().clone();
let canonical_path = path_buff.canonicalize().unwrap_or(path_buff);
let path = canonical_path.to_str().unwrap_or_default();
config::Config::set_ssh_pubkey_path(&path); config::Config::set_ssh_pubkey_path(&path);
} }
Some(("network", path_subcommand)) => { Some(("network", path_subcommand)) => {