From 9a2264e867a1237d13ef2fdbddd6ec95c1e89cff Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Mon, 7 Jul 2025 09:02:41 +0200 Subject: [PATCH] Remove old comments; Count auth mechanisms independently --- src/main.go | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main.go b/src/main.go index f4fc107..7e6730d 100644 --- a/src/main.go +++ b/src/main.go @@ -14,15 +14,6 @@ import ( const Version = "1.3.0" -// Config and SSH types are now in separate packages - -// SSH connection methods are now in ssh.go - -// YAML processing is now handled by the config package - -// SSH helper functions are now in ssh.go - -// processDevice handles backup processing for a single device func processDevice(hostname string, deviceConfig Device, commands []string, excludePatterns []string, password, keyFile string, port int, outputDir string) bool { // Create backup instance backup := NewRouterBackup(hostname, deviceConfig.Address, deviceConfig.User, password, keyFile, port) @@ -82,18 +73,25 @@ func main() { } // Check authentication setup - if password == "" && keyFile == "" { - if os.Getenv("SSH_AUTH_SOCK") != "" { - fmt.Println("Using SSH agent for authentication") - } else { - keyFile = findDefaultSSHKey() - if keyFile == "" { - log.Fatal("No SSH key found and no password provided") - } else { - fmt.Printf("Using SSH key: %s\n", keyFile) - } + hasAuth := 0 + if os.Getenv("SSH_AUTH_SOCK") != "" { + fmt.Println("Using SSH agent for authentication") + hasAuth++ + } + if keyFile == "" { + keyFile = findDefaultSSHKey() + if keyFile != "" { + fmt.Printf("Using SSH key: %s\n", keyFile) + hasAuth++ } } + if password != "" { + fmt.Println("Using --password for authentication") + hasAuth++ + } + if hasAuth == 0 { + log.Fatal("No authentication mechanisms found.") + } // Process devices if len(cfg.Devices) == 0 {