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 {