ab7317b0c0
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.
22 lines
510 B
Go
22 lines
510 B
Go
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
|
|
}
|