Fix cert removal command

This commit is contained in:
Moritz Marquardt 2022-01-25 20:56:48 +01:00
parent f5e613bfdb
commit 6d9a8e2226
No known key found for this signature in database
GPG key ID: D5788327BEE388B6
2 changed files with 27 additions and 25 deletions

View file

@ -2,7 +2,6 @@ package cmd
import ( import (
"fmt" "fmt"
"os"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -10,35 +9,38 @@ import (
) )
var Certs = &cli.Command{ var Certs = &cli.Command{
Name: "certs", Name: "certs",
Usage: "manage certs manually", Usage: "manage certs manually",
Action: certs, Subcommands: []*cli.Command{
&cli.Command{
Name: "remove",
Usage: "remove a certificate from the database",
Action: removeCert,
},
},
} }
func certs(ctx *cli.Context) error { func removeCert(ctx *cli.Context) error {
if ctx.Args().Len() >= 1 && ctx.Args().First() == "--remove-certificate" { if ctx.Args().Len() < 1 {
if ctx.Args().Len() == 1 { return fmt.Errorf("'certs remove' requires at least one domain as an argument")
println("--remove-certificate requires at least one domain as an argument") }
os.Exit(1)
}
domains := ctx.Args().Slice()[2:] domains := ctx.Args().Slice()
// TODO: make "key-database.pogreb" set via flag // TODO: make "key-database.pogreb" set via flag
keyDatabase, err := database.New("key-database.pogreb") keyDatabase, err := database.New("key-database.pogreb")
if err != nil { if err != nil {
return fmt.Errorf("could not create database: %v", err) return fmt.Errorf("could not create database: %v", err)
} }
for _, domain := range domains { for _, domain := range domains {
if err := keyDatabase.Delete([]byte(domain)); err != nil { fmt.Printf("Removing domain %s from the database...\n", domain)
panic(err) if err := keyDatabase.Delete([]byte(domain)); err != nil {
} return err
} }
if err := keyDatabase.Close(); err != nil { }
panic(err) if err := keyDatabase.Close(); err != nil {
} return err
os.Exit(0)
} }
return nil return nil
} }

View file

@ -10,7 +10,7 @@ var ServeFlags = []cli.Flag{
// TODO: Usage // TODO: Usage
EnvVars: []string{"DEBUG"}, EnvVars: []string{"DEBUG"},
}, },
// MainDomainSuffix specifies the main domain (starting with a dot) for which subdomains shall be served as static // MainDomainSuffix specifies the main domain (starting with a dot) for which subdomains shall be served as static
// pages, or used for comparison in CNAME lookups. Static pages can be accessed through // pages, or used for comparison in CNAME lookups. Static pages can be accessed through
// https://{owner}.{MainDomain}[/{repo}], with repo defaulting to "pages". // https://{owner}.{MainDomain}[/{repo}], with repo defaulting to "pages".