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

View file

@ -10,7 +10,7 @@ var ServeFlags = []cli.Flag{
// TODO: Usage
EnvVars: []string{"DEBUG"},
},
// 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
// https://{owner}.{MainDomain}[/{repo}], with repo defaulting to "pages".