Make add a postmaster user and check for its existence on

This commit is contained in:
2018-03-06 00:32:49 +00:00
parent 4973a683fb
commit 5aa6607746
16 changed files with 934 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"context"
"fmt"
"io/ioutil"
"log"
@@ -16,6 +17,7 @@ func crockeryInit(c *cli.Context) error {
domain := c.String("domain")
certFile := c.String("cert")
keyFile := c.String("key")
postmasterPassword := c.String("postmaster-password")
if db == "" {
return fmt.Errorf("No crockery database file specified")
@@ -35,6 +37,10 @@ func crockeryInit(c *cli.Context) error {
return fmt.Errorf("A key file must be specified")
}
if postmasterPassword == "" {
return fmt.Errorf("A password must be specified for the postmaster user")
}
if _, err := os.Stat(db); !os.IsNotExist(err) {
return fmt.Errorf("File %q already exists, refusing to overwrite", db)
}
@@ -53,6 +59,26 @@ func crockeryInit(c *cli.Context) error {
return fmt.Errorf("Couldn't initialize datase %q: %v", db, err)
}
datastore, err := store.New(context.Background(), db)
if err != nil {
return err
}
hash, err := store.HashPassword(postmasterPassword)
if err != nil {
return err
}
postmaster := &store.Account{
Username: "postmaster@" + domain,
Admin: true,
PasswordHash: hash,
}
if err := datastore.CreateAccount(postmaster); err != nil {
return fmt.Errorf("Failed to create admin account %s: %v", postmaster.Username, err)
}
log.Printf("Created %q for domain %q. Next step:\n\t%s -db %s run", db, domain, os.Args[0], db)
return nil

View File

@@ -34,6 +34,10 @@ func crockeryRun(c *cli.Context) error {
return fmt.Errorf("No domain configured in file %q", db)
}
if _, err := datastore.FindAccount("postmaster@" + datastore.Domain()); err != nil {
return fmt.Errorf("Couldn't find postmaster: %v", err)
}
log.Printf("Starting crockery for domain %q", datastore.Domain())
srv, err := services.New(ctx, datastore)

View File

@@ -47,6 +47,11 @@ func main() {
Usage: "File containing the PEM-encoded private key for the domain",
EnvVar: "CROCKERY_KEY_FILE",
},
cli.StringFlag{
Name: "postmaster-password",
Usage: "Password for the postmaster user",
EnvVar: "CROCKERY_POSTMASTER_PASSWORD",
},
},
},
{