github.com/philhug/dnscontrol@v0.2.4-0.20180625181521-921fa9849001/providers/activedir/activedirProvider.go (about)

     1  package activedir
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"runtime"
     7  
     8  	"github.com/StackExchange/dnscontrol/providers"
     9  	"github.com/pkg/errors"
    10  )
    11  
    12  // This is the struct that matches either (or both) of the Registrar and/or DNSProvider interfaces:
    13  type adProvider struct {
    14  	adServer string
    15  	fake     bool
    16  	psOut    string
    17  	psLog    string
    18  }
    19  
    20  var features = providers.DocumentationNotes{
    21  	providers.CanUseAlias:            providers.Cannot(),
    22  	providers.CanUseCAA:              providers.Cannot(),
    23  	providers.CanUsePTR:              providers.Cannot(),
    24  	providers.CanUseSRV:              providers.Cannot(),
    25  	providers.DocCreateDomains:       providers.Cannot("AD depends on the zone already existing on the dns server"),
    26  	providers.DocDualHost:            providers.Cannot("This driver does not manage NS records, so should not be used for dual-host scenarios"),
    27  	providers.DocOfficiallySupported: providers.Can(),
    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, errors.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, errors.Errorf("ADServer required for Active Directory provider")
    61  		}
    62  		p.adServer = srv
    63  		return p, nil
    64  	}
    65  	fmt.Printf("WARNING: PowerShell not available. ActiveDirectory will not be updated.\n")
    66  	return providers.None{}, nil
    67  }