Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agent/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.2
3.0.3
9 changes: 8 additions & 1 deletion agent/runtime/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ func (o Options) Validate() error {
return nil
}

// loadEnvFile lee KEY=VALUE de un fichero env (líneas # = comentario).
// loadEnvFile lee KEY=VALUE de un fichero env. Soporta líneas de comentario
// completas (# al inicio) y comentarios inline (" #" tras el valor); estos
// últimos se recortan antes de quitar comillas y espacios. Los valores que
// genera el server (URL, token, FP SPKI) nunca contienen " #", así que
// recortar en el primero es seguro.
func loadEnvFile(path string) map[string]string {
out := map[string]string{}
data, err := os.ReadFile(path)
Expand All @@ -116,6 +120,9 @@ func loadEnvFile(path string) map[string]string {
if !ok {
continue
}
if before, _, found := strings.Cut(v, " #"); found {
v = before
}
out[strings.TrimSpace(k)] = strings.Trim(strings.TrimSpace(v), `"'`)
}
return out
Expand Down
29 changes: 29 additions & 0 deletions agent/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,35 @@ NETPULSE_HEARTBEAT_FILE=/tmp/hb
}
}

// #883: los comentarios inline (" #" tras el valor) no deben formar parte
// del valor; en concreto NETPULSE_SCAN_INTERVAL=0 con comentario debe
// aplicar "sin scans periódicos", no caer en el default.
func TestLoadConfigInlineComments(t *testing.T) {
dir := t.TempDir()
base := "NETPULSE_SERVER=http://s\nNETPULSE_TOKEN=t\nNETPULSE_SLUG=s\n"

env := filepath.Join(dir, "inline.env")
writeFile(t, env, base+"NETPULSE_SCAN_INTERVAL=0 # min entre scans de vecinos; \"0\" = sin scans periódicos\n")
opts, err := LoadConfigFromEnv(env)
if err != nil || opts.ScanInterval != probe.ScanDisabled {
t.Fatalf("SCAN_INTERVAL=0 con comentario inline: %v %v (quiero ScanDisabled)", opts.ScanInterval, err)
}

// Comentario inline tras una duración y tras un valor entrecomillado.
env = filepath.Join(dir, "inline2.env")
writeFile(t, env, base+"NETPULSE_INTERVAL=15s # segundos entre beats\nNETPULSE_WAN_TARGET=\"1.1.1.1\" # objetivo WAN\n")
opts, err = LoadConfigFromEnv(env)
if err != nil {
t.Fatalf("LoadConfigFromEnv: %v", err)
}
if opts.Interval != 15*time.Second {
t.Fatalf("Interval con comentario inline: %v", opts.Interval)
}
if opts.WanTarget != "1.1.1.1" {
t.Fatalf("WanTarget entrecomillado con comentario inline: %q", opts.WanTarget)
}
}

func TestLoadConfigIntervalFormats(t *testing.T) {
dir := t.TempDir()
base := "NETPULSE_SERVER=http://s\nNETPULSE_TOKEN=t\nNETPULSE_SLUG=s\n"
Expand Down
Loading