This commit is contained in:
6543 2023-02-10 16:42:29 +01:00
parent de175da42d
commit 008ce4ab02
3 changed files with 14 additions and 9 deletions

View File

@ -98,9 +98,6 @@ func listCerts(ctx *cli.Context) error {
fmt.Printf("Domain\tValidTill\n\n")
for _, cert := range items {
if cert.Domain[0] == '.' {
cert.Domain = "*" + cert.Domain
}
fmt.Printf("%s\t%s\n",
cert.Domain,
time.Unix(cert.ValidTill, 0).Format(time.RFC3339))

View File

@ -54,9 +54,11 @@ func toCert(name string, c *certificate.Resource) (*Cert, error) {
}
validTill := tlsCertificates[0].NotAfter.Unix()
// TODO: do we need this or can we just go with domain name for wildcard cert
// default *.mock cert is prefixed with '.'
if name != c.Domain && name[1:] != c.Domain && name[0] != '.' {
// handle wildcard certs
if name[:1] == "." {
name = "*" + name
}
if name != c.Domain {
return nil, fmt.Errorf("domain key and cert domain not equal")
}

View File

@ -3,7 +3,6 @@ package database
import (
"errors"
"fmt"
"strings"
"github.com/rs/zerolog/log"
@ -77,8 +76,10 @@ func (x xDB) Put(domain string, cert *certificate.Resource) error {
}
func (x xDB) Get(domain string) (*certificate.Resource, error) {
// TODO: do we need this or can we just go with domain name for wildcard cert
domain = strings.TrimPrefix(domain, ".")
// handle wildcard certs
if domain[:1] == "." {
domain = "*" + domain
}
cert := new(Cert)
log.Trace().Str("domain", domain).Msg("get cert from db")
@ -91,6 +92,11 @@ func (x xDB) Get(domain string) (*certificate.Resource, error) {
}
func (x xDB) Delete(domain string) error {
// handle wildcard certs
if domain[:1] == "." {
domain = "*" + domain
}
log.Trace().Str("domain", domain).Msg("delete cert from db")
_, err := x.engine.ID(domain).Delete(new(Cert))
return err