pages-server/cmd/certs.go

45 lines
895 B
Go
Raw Permalink Normal View History

2021-12-03 01:12:51 +00:00
package cmd
import (
2021-12-03 03:15:48 +00:00
"fmt"
2021-12-03 01:12:51 +00:00
"os"
"github.com/urfave/cli/v2"
2021-12-03 03:15:48 +00:00
"codeberg.org/codeberg/pages/server/database"
2021-12-03 01:12:51 +00:00
)
var Certs = &cli.Command{
Name: "certs",
Usage: "manage certs manually",
Action: certs,
}
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)
}
domains := ctx.Args().Slice()[2:]
2021-12-03 03:15:48 +00:00
// 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)
2021-12-03 01:12:51 +00:00
}
2021-12-03 03:15:48 +00:00
2021-12-03 01:12:51 +00:00
for _, domain := range domains {
2021-12-03 03:15:48 +00:00
if err := keyDatabase.Delete([]byte(domain)); err != nil {
2021-12-03 01:12:51 +00:00
panic(err)
}
}
2021-12-05 16:42:53 +00:00
if err := keyDatabase.Close(); err != nil {
2021-12-03 01:12:51 +00:00
panic(err)
}
os.Exit(0)
}
return nil
}