[chore] Validate/set account domain (#619)

* add miekg/dns dependency

* set/validate accountDomain
This commit is contained in:
tobi
2022-06-11 11:09:31 +02:00
committed by GitHub
parent dfdc473cef
commit cf5c6d724d
304 changed files with 34218 additions and 1 deletions

View File

@@ -23,6 +23,7 @@ import (
"fmt"
"strings"
"github.com/miekg/dns"
"github.com/sirupsen/logrus"
)
@@ -31,10 +32,23 @@ func Validate() error {
errs := []error{}
// host
if GetHost() == "" {
host := GetHost()
if host == "" {
errs = append(errs, fmt.Errorf("%s must be set", HostFlag()))
}
// accountDomain; only check if host was set, otherwise there's no point
if host != "" {
switch ad := GetAccountDomain(); ad {
case "":
SetAccountDomain(GetHost())
default:
if !dns.IsSubDomain(ad, host) {
errs = append(errs, fmt.Errorf("%s was %s and %s was %s, but %s is not a valid subdomain of %s", HostFlag(), host, AccountDomainFlag(), ad, host, ad))
}
}
}
// protocol
switch proto := GetProtocol(); proto {
case "https":