Remove old comments; Count auth mechanisms independently

This commit is contained in:
Pim van Pelt
2025-07-07 09:02:41 +02:00
parent 6c1993282c
commit 9a2264e867

View File

@ -14,15 +14,6 @@ import (
const Version = "1.3.0" 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 { func processDevice(hostname string, deviceConfig Device, commands []string, excludePatterns []string, password, keyFile string, port int, outputDir string) bool {
// Create backup instance // Create backup instance
backup := NewRouterBackup(hostname, deviceConfig.Address, deviceConfig.User, password, keyFile, port) backup := NewRouterBackup(hostname, deviceConfig.Address, deviceConfig.User, password, keyFile, port)
@ -82,18 +73,25 @@ func main() {
} }
// Check authentication setup // Check authentication setup
if password == "" && keyFile == "" { hasAuth := 0
if os.Getenv("SSH_AUTH_SOCK") != "" { if os.Getenv("SSH_AUTH_SOCK") != "" {
fmt.Println("Using SSH agent for authentication") fmt.Println("Using SSH agent for authentication")
} else { hasAuth++
keyFile = findDefaultSSHKey() }
if keyFile == "" { if keyFile == "" {
log.Fatal("No SSH key found and no password provided") keyFile = findDefaultSSHKey()
} else { if keyFile != "" {
fmt.Printf("Using SSH key: %s\n", 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 // Process devices
if len(cfg.Devices) == 0 { if len(cfg.Devices) == 0 {