cmd/cli: write auto split rule for AD to config file

This commit is contained in:
Cuong Manh Le
2024-09-24 15:09:05 +07:00
committed by Cuong Manh Le
parent 4befd33866
commit ce353cd4d9
4 changed files with 15 additions and 13 deletions
+13 -11
View File
@@ -8,10 +8,7 @@ import (
)
// addExtraSplitDnsRule adds split DNS rule for domain if it's part of active directory.
func addExtraSplitDnsRule(lc *ctrld.ListenerConfig) {
if lc.Policy == nil {
lc.Policy = &ctrld.ListenerPolicyConfig{}
}
func addExtraSplitDnsRule(cfg *ctrld.Config) {
domain, err := getActiveDirectoryDomain()
if err != nil {
mainLog.Load().Debug().Msgf("unable to get active directory domain: %v", err)
@@ -21,15 +18,20 @@ func addExtraSplitDnsRule(lc *ctrld.ListenerConfig) {
mainLog.Load().Debug().Msg("no active directory domain found")
return
}
domainRule := "*." + strings.TrimPrefix(domain, ".")
for _, rule := range lc.Policy.Rules {
if _, ok := rule[domainRule]; ok {
mainLog.Load().Debug().Msg("domain rule already exist")
return
for n, lc := range cfg.Listener {
if lc.Policy == nil {
lc.Policy = &ctrld.ListenerPolicyConfig{}
}
domainRule := "*." + strings.TrimPrefix(domain, ".")
for _, rule := range lc.Policy.Rules {
if _, ok := rule[domainRule]; ok {
mainLog.Load().Debug().Msgf("domain rule already exist for listener.%s", n)
return
}
}
mainLog.Load().Debug().Msgf("adding active directory domain for listener.%s", n)
lc.Policy.Rules = append(lc.Policy.Rules, ctrld.Rule{domainRule: []string{}})
}
mainLog.Load().Debug().Msg("adding active directory domain")
lc.Policy.Rules = append(lc.Policy.Rules, ctrld.Rule{domainRule: []string{}})
}
// getActiveDirectoryDomain returns AD domain name of this computer.