dnscontrol/providers/activedir/activedirProvider.go
Tom Limoncelli 87ad01d194
Add "get-zone" command (#613)
* Add GetZoneRecords to DNSProvider interface
* dnscontrol now uses ufave/cli/v2
* NEW: get-zones.md
* HasRecordTypeName should be a method on models.Records not models.DomainConfig
* Implement BIND's GetZoneRecords
* new WriteZoneFile implemented
* go mod vendor
* Update docs to use get-zone instead of convertzone
* Add CanGetZone capability and update all providers.
* Get all zones for a provider at once (#626)
* implement GetZoneRecords for cloudflare
* munge cloudflare ttls
* Implement GetZoneRecords for cloudflare (#625)

Co-authored-by: Craig Peterson <192540+captncraig@users.noreply.github.com>
2020-02-18 08:59:18 -05:00

67 lines
2 KiB
Go

package activedir
import (
"encoding/json"
"fmt"
"runtime"
"github.com/StackExchange/dnscontrol/v2/providers"
)
// 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
}
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(),
providers.CanGetZones: providers.Unimplemented(),
}
// 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)
}
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, fmt.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" {
srv := config["ADServer"]
if srv == "" {
return nil, fmt.Errorf("ADServer required for Active Directory provider")
}
p.adServer = srv
return p, nil
}
fmt.Printf("WARNING: PowerShell not available. Active Directory will not be updated.\n")
return providers.None{}, nil
}