dnscontrol/providers/activedir/activedirProvider.go

68 lines
2 KiB
Go
Raw Normal View History

2016-08-23 08:31:50 +08:00
package activedir
import (
"encoding/json"
"fmt"
"runtime"
"github.com/StackExchange/dnscontrol/providers"
"github.com/pkg/errors"
2016-08-23 08:31:50 +08:00
)
// This is the struct that matches either (or both) of the Registrar and/or DNSProvider interfaces:
type adProvider struct {
adServer string
fake bool
psOut string
psLog string
2016-08-23 08:31:50 +08:00
}
var features = providers.DocumentationNotes{
providers.CanUseAlias: providers.Cannot(),
providers.CanUseCAA: providers.Cannot(),
providers.CanUsePTR: providers.Cannot(),
providers.CanUseSRV: providers.Cannot(),
providers.DocCreateDomains: providers.Cannot("AD depends on the zone already existing on the dns server"),
providers.DocDualHost: providers.Cannot("This driver does not manage NS records, so should not be used for dual-host scenarios"),
providers.DocOfficiallySupported: providers.Can(),
}
2016-08-23 08:31:50 +08:00
// Register with the dnscontrol system.
// This establishes the name (all caps), and the function to call to initialize it.
func init() {
providers.RegisterDomainServiceProviderType("ACTIVEDIRECTORY_PS", newDNS, features)
2016-08-23 08:31:50 +08:00
}
func newDNS(config map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) {
fake := false
if fVal := config["fakeps"]; fVal == "true" {
fake = true
} else if fVal != "" && fVal != "false" {
return nil, errors.Errorf("fakeps value must be 'true' or 'false'")
}
psOut, psLog := config["psout"], config["pslog"]
if psOut == "" {
psOut = "dns_update_commands.ps1"
}
if psLog == "" {
psLog = "powershell.log"
}
p := &adProvider{psLog: psLog, psOut: psOut, fake: fake}
if fake {
return p, nil
}
if runtime.GOOS == "windows" {
2016-08-23 08:31:50 +08:00
srv := config["ADServer"]
if srv == "" {
return nil, errors.Errorf("ADServer required for Active Directory provider")
2016-08-23 08:31:50 +08:00
}
p.adServer = srv
return p, nil
2016-08-23 08:31:50 +08:00
}
fmt.Printf("WARNING: PowerShell not available. ActiveDirectory will not be updated.\n")
return providers.None{}, nil
}