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"
@ -12,17 +11,21 @@ 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")
@ -31,14 +34,13 @@ func certs(ctx *cli.Context) error {
} }
for _, domain := range domains { for _, domain := range domains {
fmt.Printf("Removing domain %s from the database...\n", domain)
if err := keyDatabase.Delete([]byte(domain)); err != nil { if err := keyDatabase.Delete([]byte(domain)); err != nil {
panic(err) return err
} }
} }
if err := keyDatabase.Close(); err != nil { if err := keyDatabase.Close(); err != nil {
panic(err) return err
}
os.Exit(0)
} }
return nil return nil
} }