public inbox for nncp-devel@lists.stargrave.org
Atom feed
From: Emery Hemingway <ehmry@posteo•net>
To: nncp-devel@lists.cypherpunks.su
Subject: Config from stdin
Date: Fri, 26 Sep 2025 08:50:36 +0000	[thread overview]
Message-ID: <1758876614.75fo9ulbkn.astroid@laptop.none> (raw)

[-- Attachment #1: Type: text/plain, Size: 414 bytes --]

Hi,

A simple feature with a lot of potential value would be to support
passing nncp configuration on FD0 when the path is "-".

With that in place the configuration file can be outside nncp's
view of the file-system.

Also, the configuration could be piped through jq scripts that
attenuate the configuration by removing secret keys that would
be unnecessary for a given operation.


Cheers,
Emery

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: stdin.patch --]
[-- Type: text/x-patch; name=stdin.patch, Size: 1194 bytes --]

diff -Nuar a/src/ctx.go b/src/ctx.go
--- a/src/ctx.go	1981-01-01 00:00:00.000000000 +0000
+++ b/src/ctx.go	2025-09-21 09:44:18.301104773 +0000
@@ -18,6 +18,7 @@
 import (
 	"errors"
 	"fmt"
+	"io"
 	"io/fs"
 	"os"
 	"path/filepath"
@@ -106,25 +107,37 @@
 	if showPrgrs && omitPrgrs {
 		return nil, errors.New("simultaneous -progress and -noprogress")
 	}
-	fi, err := os.Stat(cfgPath)
-	if err != nil {
-		return nil, err
-	}
 	var cfg *CfgJSON
-	if fi.IsDir() {
-		cfg, err = DirToCfg(cfgPath)
+	if cfgPath == "-" {
+		cfgRaw, err := io.ReadAll(os.Stdin)
+		os.Stdin.Close()
 		if err != nil {
 			return nil, err
 		}
-	} else {
-		cfgRaw, err := os.ReadFile(cfgPath)
+		cfg, err = CfgParse(cfgRaw)
 		if err != nil {
 			return nil, err
 		}
-		cfg, err = CfgParse(cfgRaw)
+	} else {
+		fi, err := os.Stat(cfgPath)
 		if err != nil {
 			return nil, err
 		}
+		if fi.IsDir() {
+			cfg, err = DirToCfg(cfgPath)
+			if err != nil {
+				return nil, err
+			}
+		} else {
+			cfgRaw, err := os.ReadFile(cfgPath)
+			if err != nil {
+				return nil, err
+			}
+			cfg, err = CfgParse(cfgRaw)
+			if err != nil {
+				return nil, err
+			}
+		}
 	}
 	ctx, err := Cfg2Ctx(cfg)
 	if err != nil {

             reply	other threads:[~2025-09-26  9:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-26  8:50 Emery Hemingway [this message]
2025-09-28  9:12 ` Config from stdin Sergey Matveev