github.com/teknogeek/dnscontrol/v2@v2.10.1-0.20200227202244-ae299b55ba42/providers/activedir/activedirProvider.go (about)

     1  package activedir
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"runtime"
     7  
     8  	"github.com/StackExchange/dnscontrol/v2/providers"
     9  )
    10  
    11  // This is the struct that matches either (or both) of the Registrar and/or DNSProvider interfaces:
    12  type adProvider struct {
    13  	adServer string
    14  	fake     bool
    15  	psOut    string
    16  	psLog    string
    17  }
    18  
    19  var features = providers.DocumentationNotes{
    20  	providers.CanUseAlias:            providers.Cannot(),
    21  	providers.CanUseCAA:              providers.Cannot(),
    22  	providers.CanUsePTR:              providers.Cannot(),
    23  	providers.CanUseSRV:              providers.Cannot(),
    24  	providers.DocCreateDomains:       providers.Cannot("AD depends on the zone already existing on the dns server"),
    25  	providers.DocDualHost:            providers.Cannot("This driver does not manage NS records, so should not be used for dual-host scenarios"),
    26  	providers.DocOfficiallySupported: providers.Can(),
    27  	providers.CanGetZones:            providers.Unimplemented(),
    28  }
    29  
    30  // Register with the dnscontrol system.
    31  //   This establishes the name (all caps), and the function to call to initialize it.
    32  func init() {
    33  	providers.RegisterDomainServiceProviderType("ACTIVEDIRECTORY_PS", newDNS, features)
    34  }
    35  
    36  func newDNS(config map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) {
    37  
    38  	fake := false
    39  	if fVal := config["fakeps"]; fVal == "true" {
    40  		fake = true
    41  	} else if fVal != "" && fVal != "false" {
    42  		return nil, fmt.Errorf("fakeps value must be 'true' or 'false'")
    43  	}
    44  
    45  	psOut, psLog := config["psout"], config["pslog"]
    46  	if psOut == "" {
    47  		psOut = "dns_update_commands.ps1"
    48  	}
    49  	if psLog == "" {
    50  		psLog = "powershell.log"
    51  	}
    52  
    53  	p := &adProvider{psLog: psLog, psOut: psOut, fake: fake}
    54  	if fake {
    55  		return p, nil
    56  	}
    57  	if runtime.GOOS == "windows" {
    58  		srv := config["ADServer"]
    59  		if srv == "" {
    60  			return nil, fmt.Errorf("ADServer required for Active Directory provider")
    61  		}
    62  		p.adServer = srv
    63  		return p, nil
    64  	}
    65  	fmt.Printf("WARNING: PowerShell not available. Active Directory will not be updated.\n")
    66  	return providers.None{}, nil
    67  }