diff options
author | 2022-06-11 11:09:31 +0200 | |
---|---|---|
committer | 2022-06-11 11:09:31 +0200 | |
commit | cf5c6d724d381a867a7ff5d82fb9432e26c395e8 (patch) | |
tree | 859bb6fa4a3de2fdcb218b24bb33ab7219e80ce7 /internal/config/validate.go | |
parent | [chore] Webfinger rework (#627) (diff) | |
download | gotosocial-cf5c6d724d381a867a7ff5d82fb9432e26c395e8.tar.xz |
[chore] Validate/set account domain (#619)
* add miekg/dns dependency
* set/validate accountDomain
Diffstat (limited to 'internal/config/validate.go')
-rw-r--r-- | internal/config/validate.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/internal/config/validate.go b/internal/config/validate.go index b9dab0f56..b2bdda960 100644 --- a/internal/config/validate.go +++ b/internal/config/validate.go @@ -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": |