chore: move the module to git.kmalloc.org and track cmd/parsimony
- Rename the Go module from codeberg.org/squidd/parsimony to git.kmalloc.org/squid/parsimony in go.mod and every import. - Fix .gitignore: the bare `parsimony` pattern also ignored the cmd/parsimony folder, so the main package was never committed and a clean checkout could not be built. Anchor it to the root (`/parsimony`) and add cmd/parsimony.
This commit is contained in:
parent
23623c0df0
commit
93a3edc58f
35 changed files with 245 additions and 65 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,4 +1,4 @@
|
||||||
parsimony
|
/parsimony
|
||||||
*.db
|
*.db
|
||||||
*.db-*
|
*.db-*
|
||||||
admin/node_modules
|
admin/node_modules
|
||||||
|
|
|
||||||
35
cmd/parsimony/dispatch_test.go
Normal file
35
cmd/parsimony/dispatch_test.go
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestServeArgs(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
args []string
|
||||||
|
want []string
|
||||||
|
serve bool
|
||||||
|
}{
|
||||||
|
{"explicit serve", []string{"serve"}, []string{}, true},
|
||||||
|
{"explicit serve with flags", []string{"serve", "-config", "x.yaml"}, []string{"-config", "x.yaml"}, true},
|
||||||
|
{"legacy -config", []string{"-config", "x.yaml"}, []string{"-config", "x.yaml"}, true},
|
||||||
|
{"legacy --config", []string{"--config", "x.yaml"}, []string{"--config", "x.yaml"}, true},
|
||||||
|
{"legacy -config=", []string{"-config=x.yaml"}, []string{"-config=x.yaml"}, true},
|
||||||
|
{"legacy --config=", []string{"--config=x.yaml"}, []string{"--config=x.yaml"}, true},
|
||||||
|
{"admin command", []string{"list", "ls"}, nil, false},
|
||||||
|
{"global flag then admin command", []string{"--json", "list", "ls"}, nil, false},
|
||||||
|
{"url flag", []string{"--url", "http://x", "queue", "ls"}, nil, false},
|
||||||
|
{"help", []string{"help"}, nil, false},
|
||||||
|
{"nothing", nil, nil, false},
|
||||||
|
{"serve is only a command name in first position", []string{"list", "serve"}, nil, false},
|
||||||
|
{"a list called serve@x is not the serve command", []string{"list", "show", "serve@example.org"}, nil, false},
|
||||||
|
}
|
||||||
|
for _, c := range cases {
|
||||||
|
got, ok := serveArgs(c.args)
|
||||||
|
if ok != c.serve || (ok && !reflect.DeepEqual(got, c.want)) {
|
||||||
|
t.Errorf("%s: serveArgs(%v) = %v, %v; want %v, %v", c.name, c.args, got, ok, c.want, c.serve)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
75
cmd/parsimony/main.go
Normal file
75
cmd/parsimony/main.go
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
// Command parsimony runs the mailing list daemon and administers it.
|
||||||
|
//
|
||||||
|
// parsimony serve [-config FILE] run the server
|
||||||
|
// parsimony list|member|... command-line client (see "parsimony help")
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"git.kmalloc.org/squid/parsimony/internal/app"
|
||||||
|
"git.kmalloc.org/squid/parsimony/internal/cli"
|
||||||
|
"git.kmalloc.org/squid/parsimony/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// serveArgs reports whether the invocation starts the server and returns its flags.
|
||||||
|
// "parsimony -config FILE" (before the serve subcommand existed) still works.
|
||||||
|
func serveArgs(args []string) ([]string, bool) {
|
||||||
|
if len(args) == 0 {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
if args[0] == "serve" {
|
||||||
|
return args[1:], true
|
||||||
|
}
|
||||||
|
if a := args[0]; a == "-config" || a == "--config" || strings.HasPrefix(a, "-config=") || strings.HasPrefix(a, "--config=") {
|
||||||
|
return args, true
|
||||||
|
}
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if args, ok := serveArgs(os.Args[1:]); ok {
|
||||||
|
serve(args)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
os.Exit(cli.Run(os.Args[1:], cli.IO{In: os.Stdin, Out: os.Stdout, Err: os.Stderr}, os.Getenv))
|
||||||
|
}
|
||||||
|
|
||||||
|
func serve(args []string) {
|
||||||
|
fs := flag.NewFlagSet("parsimony serve", flag.ExitOnError)
|
||||||
|
cfgPath := fs.String("config", "parsimony.yaml", "path to the YAML config file")
|
||||||
|
fs.Parse(args)
|
||||||
|
|
||||||
|
cfg, err := config.Load(*cfgPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("config: %v", err)
|
||||||
|
}
|
||||||
|
token := os.Getenv("PARSIMONY_API_TOKEN")
|
||||||
|
if err := checkAPIToken(token); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
a, err := app.Start(cfg, token)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
log.Printf("LMTP listening on %s %s", cfg.LMTP.Network, a.LMTPAddr)
|
||||||
|
if a.APIAddr != "" {
|
||||||
|
log.Printf("API listening on %s", a.APIAddr)
|
||||||
|
} else {
|
||||||
|
log.Println("PARSIMONY_API_TOKEN is not set: REST API disabled")
|
||||||
|
}
|
||||||
|
if a.WebAddr != "" {
|
||||||
|
log.Printf("web listening on %s", a.WebAddr)
|
||||||
|
}
|
||||||
|
|
||||||
|
stop := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
<-stop
|
||||||
|
log.Println("shutting down")
|
||||||
|
a.Close()
|
||||||
|
}
|
||||||
28
cmd/parsimony/token.go
Normal file
28
cmd/parsimony/token.go
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"unicode"
|
||||||
|
)
|
||||||
|
|
||||||
|
// minTokenLength keeps the bearer token out of reach of guessing: 24 random characters.
|
||||||
|
const minTokenLength = 24
|
||||||
|
|
||||||
|
// checkAPIToken refuses a weak or malformed API token. An empty token is fine: the API is then disabled.
|
||||||
|
func checkAPIToken(token string) error {
|
||||||
|
if token == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
for _, r := range token {
|
||||||
|
switch {
|
||||||
|
case unicode.IsSpace(r):
|
||||||
|
return fmt.Errorf("PARSIMONY_API_TOKEN contains whitespace (a trailing newline from a file?): remove it")
|
||||||
|
case unicode.IsControl(r):
|
||||||
|
return fmt.Errorf("PARSIMONY_API_TOKEN contains a control character")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(token) < minTokenLength {
|
||||||
|
return fmt.Errorf("PARSIMONY_API_TOKEN is too short (%d characters): use at least %d random characters, for example the output of `openssl rand -hex 24`", len(token), minTokenLength)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
42
cmd/parsimony/token_test.go
Normal file
42
cmd/parsimony/token_test.go
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCheckAPIToken(t *testing.T) {
|
||||||
|
good := strings.Repeat("a", 24)
|
||||||
|
for name, tc := range map[string]struct {
|
||||||
|
token string
|
||||||
|
wantErr string // substring; "" means the token is fine
|
||||||
|
}{
|
||||||
|
"not set (API disabled)": {"", ""},
|
||||||
|
"24 characters": {good, ""},
|
||||||
|
"long": {strings.Repeat("x", 100), ""},
|
||||||
|
"23 characters": {good[:23], "at least 24"},
|
||||||
|
"a short word": {"tok", "at least 24"},
|
||||||
|
"trailing newline": {good + "\n", "whitespace"},
|
||||||
|
"inner space": {good[:12] + " " + good[12:], "whitespace"},
|
||||||
|
"tab": {good + "\t", "whitespace"},
|
||||||
|
"control character": {good + "\x00", "control"},
|
||||||
|
} {
|
||||||
|
err := checkAPIToken(tc.token)
|
||||||
|
switch {
|
||||||
|
case tc.wantErr == "" && err != nil:
|
||||||
|
t.Errorf("%s: unexpected error %v", name, err)
|
||||||
|
case tc.wantErr != "" && (err == nil || !strings.Contains(err.Error(), tc.wantErr)):
|
||||||
|
t.Errorf("%s: want an error containing %q, got %v", name, tc.wantErr, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTheTokenErrorSaysHowToMakeOne(t *testing.T) {
|
||||||
|
err := checkAPIToken("Zq9Xv7Kp")
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "openssl rand -hex 24") || !strings.Contains(err.Error(), "PARSIMONY_API_TOKEN") {
|
||||||
|
t.Fatalf("%v", err)
|
||||||
|
}
|
||||||
|
if strings.Contains(err.Error(), "Zq9Xv7Kp") {
|
||||||
|
t.Fatal("never echo the token")
|
||||||
|
}
|
||||||
|
}
|
||||||
2
go.mod
2
go.mod
|
|
@ -1,4 +1,4 @@
|
||||||
module codeberg.org/squidd/parsimony
|
module git.kmalloc.org/squid/parsimony
|
||||||
|
|
||||||
go 1.27.3
|
go 1.27.3
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ import (
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"codeberg.org/squidd/parsimony/internal/archive"
|
"git.kmalloc.org/squid/parsimony/internal/archive"
|
||||||
"codeberg.org/squidd/parsimony/internal/store"
|
"git.kmalloc.org/squid/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Releaser approves a held message: it delivers it to the list.
|
// Releaser approves a held message: it delivers it to the list.
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"codeberg.org/squidd/parsimony/internal/store"
|
"git.kmalloc.org/squid/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
const token = "s3cret"
|
const token = "s3cret"
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"codeberg.org/squidd/parsimony/internal/store"
|
"git.kmalloc.org/squid/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
type clock struct {
|
type clock struct {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"codeberg.org/squidd/parsimony/internal/store"
|
"git.kmalloc.org/squid/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
type postJSON struct {
|
type postJSON struct {
|
||||||
|
|
|
||||||
|
|
@ -14,16 +14,16 @@ import (
|
||||||
|
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
|
|
||||||
"codeberg.org/squidd/parsimony/internal/adminui"
|
"git.kmalloc.org/squid/parsimony/internal/adminui"
|
||||||
"codeberg.org/squidd/parsimony/internal/api"
|
"git.kmalloc.org/squid/parsimony/internal/api"
|
||||||
"codeberg.org/squidd/parsimony/internal/config"
|
"git.kmalloc.org/squid/parsimony/internal/config"
|
||||||
"codeberg.org/squidd/parsimony/internal/dkimsign"
|
"git.kmalloc.org/squid/parsimony/internal/dkimsign"
|
||||||
"codeberg.org/squidd/parsimony/internal/ingest"
|
"git.kmalloc.org/squid/parsimony/internal/ingest"
|
||||||
"codeberg.org/squidd/parsimony/internal/outbound"
|
"git.kmalloc.org/squid/parsimony/internal/outbound"
|
||||||
"codeberg.org/squidd/parsimony/internal/queue"
|
"git.kmalloc.org/squid/parsimony/internal/queue"
|
||||||
"codeberg.org/squidd/parsimony/internal/router"
|
"git.kmalloc.org/squid/parsimony/internal/router"
|
||||||
"codeberg.org/squidd/parsimony/internal/store"
|
"git.kmalloc.org/squid/parsimony/internal/store"
|
||||||
"codeberg.org/squidd/parsimony/internal/web"
|
"git.kmalloc.org/squid/parsimony/internal/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
// shutdownTimeout bounds how long Close waits for the sessions in flight before it cuts them.
|
// shutdownTimeout bounds how long Close waits for the sessions in flight before it cuts them.
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,8 @@ import (
|
||||||
"github.com/emersion/go-sasl"
|
"github.com/emersion/go-sasl"
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
|
|
||||||
"codeberg.org/squidd/parsimony/internal/config"
|
"git.kmalloc.org/squid/parsimony/internal/config"
|
||||||
"codeberg.org/squidd/parsimony/internal/store"
|
"git.kmalloc.org/squid/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
// sink is a fake SMTP relay that records what it receives.
|
// sink is a fake SMTP relay that records what it receives.
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"codeberg.org/squidd/parsimony/internal/mbox"
|
"git.kmalloc.org/squid/parsimony/internal/mbox"
|
||||||
"codeberg.org/squidd/parsimony/internal/store"
|
"git.kmalloc.org/squid/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"codeberg.org/squidd/parsimony/internal/store"
|
"git.kmalloc.org/squid/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
var importNow = time.Date(2031, 5, 6, 7, 8, 9, 0, time.UTC)
|
var importNow = time.Date(2031, 5, 6, 7, 8, 9, 0, time.UTC)
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,9 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"codeberg.org/squidd/parsimony/internal/api"
|
"git.kmalloc.org/squid/parsimony/internal/api"
|
||||||
"codeberg.org/squidd/parsimony/internal/dkimsign"
|
"git.kmalloc.org/squid/parsimony/internal/dkimsign"
|
||||||
"codeberg.org/squidd/parsimony/internal/store"
|
"git.kmalloc.org/squid/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
const token = "cli-token"
|
const token = "cli-token"
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"codeberg.org/squidd/parsimony/internal/dkimsign"
|
"git.kmalloc.org/squid/parsimony/internal/dkimsign"
|
||||||
)
|
)
|
||||||
|
|
||||||
// lookupTXT resolves DNS TXT records; tests replace it.
|
// lookupTXT resolves DNS TXT records; tests replace it.
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"codeberg.org/squidd/parsimony/internal/store"
|
"git.kmalloc.org/squid/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPostsLs(t *testing.T) {
|
func TestPostsLs(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
|
|
||||||
"codeberg.org/squidd/parsimony/internal/router"
|
"git.kmalloc.org/squid/parsimony/internal/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxMessageBytes = 25 << 20
|
const maxMessageBytes = 25 << 20
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,10 @@ import (
|
||||||
|
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
|
|
||||||
"codeberg.org/squidd/parsimony/internal/outbound"
|
"git.kmalloc.org/squid/parsimony/internal/outbound"
|
||||||
"codeberg.org/squidd/parsimony/internal/queue"
|
"git.kmalloc.org/squid/parsimony/internal/queue"
|
||||||
"codeberg.org/squidd/parsimony/internal/router"
|
"git.kmalloc.org/squid/parsimony/internal/router"
|
||||||
"codeberg.org/squidd/parsimony/internal/store"
|
"git.kmalloc.org/squid/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
const msg = "From: Alice <alice@example.com>\r\nSubject: hi\r\n\r\nbody\r\n"
|
const msg = "From: Alice <alice@example.com>\r\nSubject: hi\r\n\r\nbody\r\n"
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
|
|
||||||
"codeberg.org/squidd/parsimony/internal/store"
|
"git.kmalloc.org/squid/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestANonPublisherIsRefusedPermanentlyByANewsletter(t *testing.T) {
|
func TestANonPublisherIsRefusedPermanentlyByANewsletter(t *testing.T) {
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue