feat: funciones NordVPN bash y Go — CLI, contenedor Docker y parser de estado
Funciones bash para instalar, conectar, desconectar, estado, IP, ciudades, países y protocolo. Funciones Go para gestionar contenedor NordVPN (run/start/stop) y parsear estado. Incluye tipo NordVPNStatus y tests para el parser. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package infra
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// NordVPNContainerRunOpts opciones para ejecutar un container a traves del gateway NordVPN.
|
||||
type NordVPNContainerRunOpts struct {
|
||||
Image string // Imagen Docker a ejecutar (obligatorio)
|
||||
Cmd []string // Comando a ejecutar en el container
|
||||
Env map[string]string // Variables de entorno
|
||||
Volumes []string // Bind mounts
|
||||
Name string // Nombre del container (opcional)
|
||||
Gateway string // Nombre del container NordVPN gateway (default: "nordvpn")
|
||||
Detach bool // Ejecutar en background
|
||||
Remove bool // Eliminar al terminar (--rm)
|
||||
}
|
||||
|
||||
// NordVPNContainerRun ejecuta un container Docker cuyo trafico de red
|
||||
// pasa por el container gateway NordVPN usando --network=container:<gateway>.
|
||||
// Devuelve el ID del container creado.
|
||||
func NordVPNContainerRun(opts NordVPNContainerRunOpts) (string, error) {
|
||||
if opts.Image == "" {
|
||||
return "", fmt.Errorf("image required")
|
||||
}
|
||||
if opts.Gateway == "" {
|
||||
opts.Gateway = "nordvpn"
|
||||
}
|
||||
|
||||
id, err := DockerRunContainer(opts.Image, DockerRunOpts{
|
||||
Name: opts.Name,
|
||||
Env: opts.Env,
|
||||
Volumes: opts.Volumes,
|
||||
Detach: opts.Detach,
|
||||
Remove: opts.Remove,
|
||||
Network: "container:" + opts.Gateway,
|
||||
Cmd: opts.Cmd,
|
||||
})
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("nordvpn container run %s: %w", opts.Image, err)
|
||||
}
|
||||
|
||||
return id, nil
|
||||
}
|
||||
Reference in New Issue
Block a user