Merge commit '52c4d1f' into feat/remote-node
# Conflicts: # internal/db/db.go
This commit is contained in:
@@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/david/knox/internal/db"
|
||||
"github.com/david/knox/internal/watch"
|
||||
@@ -77,7 +78,7 @@ func NewGossipCmd(kdb *db.KnoxDB) *cobra.Command {
|
||||
// gossipDiff compares this node's observation log + auto-threads with a peer's
|
||||
// via /v1/diff. Never writes; it is the preview for what a sync would adopt.
|
||||
func gossipDiff(kdb *db.KnoxDB, peerAddr string) error {
|
||||
c := &watch.Client{Addr: peerAddr}
|
||||
c := &watch.Client{Addr: peerAddr, Timeout: 10 * time.Second}
|
||||
remote, err := c.Diff()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -98,6 +98,8 @@ func NewIngestCmd(kdb *db.KnoxDB) *cobra.Command {
|
||||
for _, r := range results {
|
||||
record(r)
|
||||
}
|
||||
} else {
|
||||
log.Printf("[knox] obsidian ingest failed: %v", err)
|
||||
}
|
||||
}
|
||||
log.Printf("[knox] ingesting browser-history...")
|
||||
@@ -105,12 +107,16 @@ func NewIngestCmd(kdb *db.KnoxDB) *cobra.Command {
|
||||
for _, r := range results {
|
||||
record(r)
|
||||
}
|
||||
} else {
|
||||
log.Printf("[knox] browser-history ingest failed: %v", err)
|
||||
}
|
||||
log.Printf("[knox] ingesting gitea...")
|
||||
if results, err := ingest.NewGiteaIngester().IngestAll(); err == nil {
|
||||
for _, r := range results {
|
||||
record(r)
|
||||
}
|
||||
} else {
|
||||
log.Printf("[knox] gitea ingest failed: %v", err)
|
||||
}
|
||||
log.Printf("[knox] ingesting karakeep...")
|
||||
if results, err := ingest.NewKarakeepIngester().IngestAll(); err == nil {
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/david/knox/internal/httpauth"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// NewTLSCmd exposes certificate management for nodes that must serve TLS
|
||||
// without a public DNS name or a CA-issued certificate.
|
||||
func NewTLSCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "tls",
|
||||
Short: "Manage TLS material for a remote knox node",
|
||||
}
|
||||
|
||||
var (
|
||||
hosts []string
|
||||
out string
|
||||
days int
|
||||
)
|
||||
initCmd := &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "Generate a self-signed certificate usable without a public name",
|
||||
Long: `Generate a self-signed certificate and key for this node.
|
||||
|
||||
The certificate is its own CA, so peers (and MCP clients) trust it by pointing
|
||||
KNOX_TLS_CA at the certificate file. No public DNS name or external certificate
|
||||
authority is involved: pass the addresses clients actually dial, e.g.
|
||||
|
||||
knox tls init --host 172.30.170.155 --host knox.dhg.lol --out /data/tls`,
|
||||
RunE: func(c *cobra.Command, args []string) error {
|
||||
certPath := filepath.Join(out, "cert.pem")
|
||||
keyPath := filepath.Join(out, "key.pem")
|
||||
if err := httpauth.GenerateSelfSigned(certPath, keyPath, hosts, time.Duration(days)*24*time.Hour); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("wrote %s\nwrote %s\n\n", certPath, keyPath)
|
||||
fmt.Println("serve with:")
|
||||
fmt.Printf(" %s=%s\n %s=%s\n %s=<shared-secret>\n",
|
||||
httpauth.CertEnv, certPath, httpauth.KeyEnv, keyPath, httpauth.TokenEnv)
|
||||
fmt.Println("\npeers trust it with:")
|
||||
fmt.Printf(" %s=%s\n %s=<same-secret>\n", httpauth.CAEnv, certPath, httpauth.TokenEnv)
|
||||
if len(hosts) > 0 {
|
||||
fmt.Printf("\ncertificate covers: %s\n", strings.Join(hosts, ", "))
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
initCmd.Flags().StringSliceVar(&hosts, "host", nil, "DNS names and/or IP addresses clients dial (repeatable)")
|
||||
initCmd.Flags().StringVar(&out, "out", "./tls", "Directory to write cert.pem and key.pem into")
|
||||
initCmd.Flags().IntVar(&days, "days", 825, "Validity in days")
|
||||
|
||||
cmd.AddCommand(initCmd)
|
||||
return cmd
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/david/knox/internal/db"
|
||||
"github.com/david/knox/internal/watch"
|
||||
@@ -25,7 +27,10 @@ func NewWatchCmd(kdb *db.KnoxDB) *cobra.Command {
|
||||
log.Printf("[knox] starting watcher, scanning %d directories", len(dirs))
|
||||
w := watch.New(kdb, dirs)
|
||||
if err := w.Start(); err != nil {
|
||||
log.Fatalf("watcher error: %v", err)
|
||||
// Not log.Fatalf: --quiet redirects the logger to io.Discard,
|
||||
// so a fatal exit must reach the user on stderr directly.
|
||||
fmt.Fprintf(os.Stderr, "watcher error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user