1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

Update bind docs and Getting Started (#53)

* intitial work for bind refactor

* relax requirement that creds.json exists.

* Updating bind docs.
Fixes #48

* typo

* can exclude provider from default set in creds.json

* Add bind to integration tests. Fix for IDNs.
This commit is contained in:
Craig Peterson
2017-03-22 10:38:08 -06:00
committed by GitHub
parent 33b4d2b748
commit 854c84e652
8 changed files with 98 additions and 84 deletions

47
main.go
View File

@ -23,15 +23,12 @@ import (
//go:generate go run build/generate/generate.go
// One of these config options must be set.
var jsFile = flag.String("js", "dnsconfig.js", "Javascript file containing dns config")
var stdin = flag.Bool("stdin", false, "Read domain config JSON from stdin")
var jsonInput = flag.String("json", "", "Read domain config from specified JSON file.")
var credsFile = flag.String("creds", "creds.json", "Provider credentials JSON file")
var jsonOutputPre = flag.String("debugrawjson", "", "Write JSON intermediate to this file pre-normalization.")
var jsonOutputPost = flag.String("debugjson", "", "During preview, write JSON intermediate to this file instead of stdout.")
var configFile = flag.String("creds", "creds.json", "Provider credentials JSON file")
var devMode = flag.Bool("dev", false, "Use helpers.js from disk instead of embedded")
var flagProviders = flag.String("providers", "", "Providers to enable (comma seperated list); default is all-but-bind. Specify 'all' for all (including bind)")
@ -49,11 +46,7 @@ func main() {
}
var dnsConfig *models.DNSConfig
if *stdin {
log.Fatal("Read from stdin not implemented yet.")
} else if *jsonInput != "" {
log.Fatal("Direct JSON read not implemented")
} else if *jsFile != "" {
if *jsFile != "" {
text, err := ioutil.ReadFile(*jsFile)
if err != nil {
log.Fatalf("Error reading %v: %v\n", *jsFile, err)
@ -117,9 +110,17 @@ func main() {
return
}
providerConfigs, err := config.LoadProviderConfigs(*configFile)
providerConfigs, err := config.LoadProviderConfigs(*credsFile)
if err != nil {
log.Fatalf("error loading provider configurations: %s", err)
log.Fatalf(err.Error())
}
nonDefaultProviders := []string{}
for name, vals := range providerConfigs {
// add "_exclude_from_defaults":"true" to a domain to exclude it from being run unless
// -providers=all or -providers=name
if vals["_exclude_from_defaults"] == "true" {
nonDefaultProviders = append(nonDefaultProviders, name)
}
}
registrars, err := providers.CreateRegistrars(dnsConfig, providerConfigs)
if err != nil {
@ -168,7 +169,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
shouldrun := shouldRunProvider(prov, dc)
shouldrun := shouldRunProvider(prov, dc, nonDefaultProviders)
statusLbl := ""
if !shouldrun {
statusLbl = "(skipping)"
@ -197,7 +198,7 @@ func main() {
fmt.Printf("%d correction%s\n", len(corrections), plural)
anyErrors = printOrRunCorrections(corrections, command) || anyErrors
}
if run := shouldRunProvider(domain.Registrar, domain); !run {
if run := shouldRunProvider(domain.Registrar, domain, nonDefaultProviders); !run {
continue
}
fmt.Printf("----- Registrar: %s\n", domain.Registrar)
@ -272,23 +273,17 @@ func printOrRunCorrections(corrections []*models.Correction, command string) (an
return anyErrors
}
func shouldRunProvider(p string, dc *models.DomainConfig) bool {
func shouldRunProvider(p string, dc *models.DomainConfig, nonDefaultProviders []string) bool {
if *flagProviders == "all" {
return true
}
if *flagProviders == "" {
return (p != "bind")
// NOTE(tlim): Hardcoding bind is a hacky way to make it off by default.
// As a result, bind only runs if you list it in -providers or use
// -providers=all.
// If you always want bind to run, call it something else in dnsconfig.js
// for example `NewDSP('bindyes', 'BIND',`.
// We don't want this hack, but we shouldn't need this in the future
// so it doesn't make sense to write a lot of code to make it work.
// In the future, the above `return p != "bind"` can become `return true`.
// Alternatively we might want to add a complex system that permits
// fancy whitelist/blacklisting of providers with defaults and so on.
// In that case, all of this hack will go away.
for _, pr := range nonDefaultProviders {
if pr == p {
return false
}
}
return true
}
for _, prov := range strings.Split(*flagProviders, ",") {
if prov == p {