feat: add Go SSH config management functions and type

7 funciones Go del dominio infra para gestion programatica de ~/.ssh/config:
ssh_config_parse (parser de bloques Host/Match), ssh_config_read (lectura del
archivo), ssh_config_find (busqueda por host), ssh_config_add_entry y
ssh_config_remove_entry (CRUD), ssh_config_render (serializacion a texto),
ssh_config_write (escritura atomica). Incluye tipo SshConfigEntry (product type)
y tests unitarios del parser.
This commit is contained in:
2026-04-12 13:54:43 +02:00
parent 773bb3a523
commit f2753e6fff
17 changed files with 834 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
package infra
import (
"fmt"
"os"
"path/filepath"
)
// SSHConfigRead lee y parsea el archivo ~/.ssh/config. Si el archivo no existe,
// retorna una lista vacia sin error (config todavia no creado).
func SSHConfigRead() ([]SSHConfigEntry, error) {
path := filepath.Join(os.Getenv("HOME"), ".ssh", "config")
data, err := os.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, fmt.Errorf("ssh config read: %w", err)
}
return SSHConfigParse(string(data)), nil
}