Files
fn_registry/functions/infra/ssh_tunnel_open.md
T
egutierrez 5f4f1f7508 docs: params/output semántico en 506 funciones para composabilidad
Añade campos params y output al frontmatter YAML de las 506 funciones del registry.
Cada parámetro tiene descripción semántica (qué representa, unidades, rango típico)
y cada función describe qué produce su output. Permite a agentes razonar sobre
cadenas de composición (ej: prices → log_return → sharpe_ratio) sin leer código.
2026-04-05 18:45:16 +02:00

1.6 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports params output tested tests test_file_path file_path
ssh_tunnel_open function go infra 1.0.0 impure func SSHTunnelOpen(conn SSHConn, localPort int, remoteHost string, remotePort int) (int, error) Abre un tunel SSH (local port forwarding) en background. Retorna el PID del proceso para cerrarlo despues.
ssh
tunnel
port-forwarding
remote
ssh_conn_go_infra
false error_go_core
fmt
os/exec
strings
time
name desc
conn estructura SSHConn con Host, User, Port, IdentityFile
name desc
localPort puerto local donde escuchar conexiones
name desc
remoteHost host remoto accesible desde el servidor SSH
name desc
remotePort puerto en el host remoto
PID del proceso ssh del tunel para cerrarlo despues true
abre tunel y lo cierra
functions/infra/ssh_tunnel_test.go functions/infra/ssh_tunnel_open.go

Ejemplo

conn := SSHConn{Host: "bastion.example.com", User: "deploy"}
// Tunel: localhost:5432 -> db-server:5432 via bastion
pid, err := SSHTunnelOpen(conn, 5432, "db-server", 5432)
if err != nil {
    log.Fatal(err)
}
fmt.Println("tunnel PID:", pid)
// Usar localhost:5432 para conectar a la BD remota
// Cerrar con SSHTunnelClose(pid)

Notas

Usa ssh -N -f -L para crear el tunel en background. ExitOnForwardFailure=yes falla inmediatamente si el puerto local esta ocupado. remoteHost vacio se interpreta como "localhost" (el servidor SSH mismo). El PID se obtiene buscando el proceso ssh en la tabla de procesos.