Hack in command-line specification of domain, cert and key

This commit is contained in:
2018-03-05 19:53:48 +00:00
parent 811b90224f
commit bf1ca421aa
6 changed files with 107 additions and 8 deletions

View File

@@ -2,6 +2,8 @@ package main
import (
"context"
"crypto/tls"
"flag"
"log"
"os"
"os/signal"
@@ -10,7 +12,19 @@ import (
"ur.gs/crockery/internal/store"
)
var (
domain = flag.String("domain", "", "Domain to serve email for")
certFile = flag.String("cert", "", "Path to a PEM-encoded certificate bundle for TLS support")
keyFile = flag.String("key", "", "Path to a PEM-encoded key for TLS support")
)
func main() {
flag.Parse()
if *domain == "" {
log.Fatal("A domain must be specified on the command line (for now!)")
}
ctx, cancel := context.WithCancel(context.Background())
datastore, err := store.New(ctx, "crockery.db")
@@ -18,6 +32,25 @@ func main() {
log.Fatal("Couldn't open crockery.db:", err)
}
// FIXME: This will eventually come from the datastore itself, via `crockery init`
datastore.SetDomain(*domain)
log.Printf("Running as %s", datastore.Domain())
// FIXME: This will eventually come from the datastore itself, via ACME
if *certFile != "" || *keyFile != "" {
cert, err := tls.LoadX509KeyPair(*certFile, *keyFile)
if err != nil {
log.Fatalf("Couldn't setup TLS: %v", err)
}
if cert.PrivateKey == nil {
log.Fatal("No private key for TLS certificate")
}
datastore.SetTLS(cert)
log.Print("Successfully loaded TLS certificate and key")
}
srv, err := services.New(ctx, datastore)
if err != nil {
log.Fatal("Couldn't start services:", err)