mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-01 01:22:34 +02:00
refactor: streamline domain mismatch check in certState function
This commit is contained in:
parent
63c4bdc73d
commit
1cf18657b6
1 changed files with 13 additions and 15 deletions
|
@ -5,10 +5,11 @@ import (
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"reflect"
|
"slices"
|
||||||
"sort"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-acme/lego/v4/certificate"
|
"github.com/go-acme/lego/v4/certificate"
|
||||||
|
@ -283,22 +284,19 @@ func (p *Provider) certState() CertState {
|
||||||
return CertStateExpired
|
return CertStateExpired
|
||||||
}
|
}
|
||||||
|
|
||||||
certDomains := make([]string, len(p.certExpiries))
|
if len(p.certExpiries) != len(p.cfg.Domains) {
|
||||||
wantedDomains := make([]string, len(p.cfg.Domains))
|
|
||||||
i := 0
|
|
||||||
for domain := range p.certExpiries {
|
|
||||||
certDomains[i] = domain
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
copy(wantedDomains, p.cfg.Domains)
|
|
||||||
sort.Strings(wantedDomains)
|
|
||||||
sort.Strings(certDomains)
|
|
||||||
|
|
||||||
if !reflect.DeepEqual(certDomains, wantedDomains) {
|
|
||||||
log.Info().Msgf("cert domains mismatch: %v != %v", certDomains, p.cfg.Domains)
|
|
||||||
return CertStateMismatch
|
return CertStateMismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i := range len(p.cfg.Domains) {
|
||||||
|
if _, ok := p.certExpiries[p.cfg.Domains[i]]; !ok {
|
||||||
|
log.Info().Msgf("autocert domains mismatch: cert: %s, wanted: %s",
|
||||||
|
strings.Join(slices.Collect(maps.Keys(p.certExpiries)), ", "),
|
||||||
|
strings.Join(p.cfg.Domains, ", "))
|
||||||
|
return CertStateMismatch
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return CertStateValid
|
return CertStateValid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue