diff --git a/pkg/printer/printer.go b/pkg/printer/printer.go index ab0df97bd..a03cc6274 100644 --- a/pkg/printer/printer.go +++ b/pkg/printer/printer.go @@ -27,7 +27,9 @@ type CLI interface { type Printer interface { Debugf(fmt string, args ...interface{}) Printf(fmt string, args ...interface{}) + Println(lines ...string) Warnf(fmt string, args ...interface{}) + Errorf(fmt string, args ...interface{}) } // Debugf is called to print/format debug information. @@ -40,11 +42,21 @@ func Printf(fmt string, args ...interface{}) { DefaultPrinter.Printf(fmt, args...) } +// Println is called to print/format information. +func Println(lines ...string) { + DefaultPrinter.Println(lines...) +} + // Warnf is called to print/format a warning. func Warnf(fmt string, args ...interface{}) { DefaultPrinter.Warnf(fmt, args...) } +// Errorf is called to print/format an error. +func Errorf(fmt string, args ...interface{}) { + DefaultPrinter.Errorf(fmt, args...) +} + var ( // DefaultPrinter is the default Printer, used by Debugf, Printf, and Warnf. DefaultPrinter = &ConsolePrinter{ @@ -143,7 +155,17 @@ func (c ConsolePrinter) Printf(format string, args ...interface{}) { fmt.Fprintf(c.Writer, format, args...) } +// Println is called to print/format information. +func (c ConsolePrinter) Println(lines ...string) { + fmt.Fprintln(c.Writer, lines) +} + // Warnf is called to print/format a warning. func (c ConsolePrinter) Warnf(format string, args ...interface{}) { fmt.Fprintf(c.Writer, "WARNING: "+format, args...) } + +// Errorf is called to print/format an error. +func (c ConsolePrinter) Errorf(format string, args ...interface{}) { + fmt.Fprintf(c.Writer, "ERROR: "+format, args...) +} diff --git a/providers/activedir/activedirProvider.go b/providers/activedir/activedirProvider.go index 23af604ae..4f6157118 100644 --- a/providers/activedir/activedirProvider.go +++ b/providers/activedir/activedirProvider.go @@ -3,6 +3,7 @@ package activedir import ( "encoding/json" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "runtime" "github.com/StackExchange/dnscontrol/v3/providers" @@ -38,7 +39,7 @@ func init() { } func newDNS(config map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) { - fmt.Printf("WARNING: ACTIVEDIRECTORY_PS provider is being replaced by MSDNS. Please convert. Details in https://stackexchange.github.io/dnscontrol/providers/msdns\n") + printer.Printf("WARNING: ACTIVEDIRECTORY_PS provider is being replaced by MSDNS. Please convert. Details in https://stackexchange.github.io/dnscontrol/providers/msdns\n") fake := false if fVal := config["fakeps"]; fVal == "true" { @@ -67,6 +68,6 @@ func newDNS(config map[string]string, metadata json.RawMessage) (providers.DNSSe p.adServer = srv return p, nil } - fmt.Printf("WARNING: PowerShell not available. Active Directory will not be updated.\n") + printer.Printf("WARNING: PowerShell not available. Active Directory will not be updated.\n") return providers.None{}, nil } diff --git a/providers/activedir/getzones_windows.go b/providers/activedir/getzones_windows.go index cefefd6c1..c31be91e4 100644 --- a/providers/activedir/getzones_windows.go +++ b/providers/activedir/getzones_windows.go @@ -6,6 +6,8 @@ import ( "strconv" "strings" "sync" + + "github.com/StackExchange/dnscontrol/v3/pkg/printer" ) var checkPS sync.Once @@ -20,12 +22,12 @@ func (c *activedirProvider) getRecords(domainname string) ([]byte, error) { checkPS.Do(func() { psAvailible = c.isPowerShellReady() if !psAvailible { - fmt.Printf("\n\n\n") - fmt.Printf("***********************************************\n") - fmt.Printf("PowerShell DnsServer module not installed.\n") - fmt.Printf("See http://social.technet.microsoft.com/wiki/contents/articles/2202.remote-server-administration-tools-rsat-for-windows-client-and-windows-server-dsforum2wiki.aspx\n") - fmt.Printf("***********************************************\n") - fmt.Printf("\n\n\n") + printer.Printf("\n\n\n") + printer.Printf("***********************************************\n") + printer.Printf("PowerShell DnsServer module not installed.\n") + printer.Printf("See http://social.technet.microsoft.com/wiki/contents/articles/2202.remote-server-administration-tools-rsat-for-windows-client-and-windows-server-dsforum2wiki.aspx\n") + printer.Printf("***********************************************\n") + printer.Printf("\n\n\n") } }) if !psAvailible { diff --git a/providers/autodns/autoDnsProvider.go b/providers/autodns/autoDnsProvider.go index 4c8727c5f..e67914874 100644 --- a/providers/autodns/autoDnsProvider.go +++ b/providers/autodns/autoDnsProvider.go @@ -3,6 +3,7 @@ package autodns import ( "encoding/json" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "net/http" "net/url" "regexp" @@ -102,17 +103,17 @@ func (api *autoDnsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mo for _, m := range del { // Just notify, these records don't have to be deleted explicitly - fmt.Println(m) + printer.Debugf(m.String()) } for _, m := range create { - fmt.Println(m) + printer.Debugf(m.String()) changes = append(changes, m.Desired) } for _, m := range modify { - fmt.Println("mod") - fmt.Println(m) + printer.Debugf("mod") + printer.Debugf(m.String()) changes = append(changes, m.Desired) } @@ -168,7 +169,7 @@ func (api *autoDnsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mo err := api.updateZone(domain, resourceRecords, nameServers, zoneTTL) if err != nil { - fmt.Println(err) + fmt.Errorf(err.Error()) } return nil diff --git a/providers/axfrddns/axfrddnsProvider.go b/providers/axfrddns/axfrddnsProvider.go index d6172fcad..802908c95 100644 --- a/providers/axfrddns/axfrddnsProvider.go +++ b/providers/axfrddns/axfrddnsProvider.go @@ -17,6 +17,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "math" "math/rand" "net" @@ -96,7 +97,7 @@ func initAxfrDdns(config map[string]string, providermeta json.RawMessage) (provi case "udp": api.updateMode = "" default: - fmt.Printf("[Warning] AXFRDDNS: Unknown update-mode in `creds.json` (%s)\n", config["update-mode"]) + printer.Printf("[Warning] AXFRDDNS: Unknown update-mode in `creds.json` (%s)\n", config["update-mode"]) } } else { api.updateMode = "" @@ -107,7 +108,7 @@ func initAxfrDdns(config map[string]string, providermeta json.RawMessage) (provi "tcp-tls": api.transferMode = config["transfer-mode"] default: - fmt.Printf("[Warning] AXFRDDNS: Unknown transfer-mode in `creds.json` (%s)\n", config["transfer-mode"]) + printer.Printf("[Warning] AXFRDDNS: Unknown transfer-mode in `creds.json` (%s)\n", config["transfer-mode"]) } } else { api.transferMode = "tcp" @@ -140,7 +141,7 @@ func initAxfrDdns(config map[string]string, providermeta json.RawMessage) (provi "transfer-mode": continue default: - fmt.Printf("[Warning] AXFRDDNS: unknown key in `creds.json` (%s)\n", key) + printer.Printf("[Warning] AXFRDDNS: unknown key in `creds.json` (%s)\n", key) } } return api, err @@ -336,10 +337,10 @@ func (c *axfrddnsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mod // TODO(tlim): This check should be done on all providers. Move to the global validation code. if dc.AutoDNSSEC == "on" && !hasDnssecRecords { - fmt.Printf("Warning: AUTODNSSEC is enabled, but no DNSKEY or RRSIG record was found in the AXFR answer!\n") + printer.Printf("Warning: AUTODNSSEC is enabled, but no DNSKEY or RRSIG record was found in the AXFR answer!\n") } if dc.AutoDNSSEC == "off" && hasDnssecRecords { - fmt.Printf("Warning: AUTODNSSEC is disabled, but DNSKEY or RRSIG records were found in the AXFR answer!\n") + printer.Printf("Warning: AUTODNSSEC is disabled, but DNSKEY or RRSIG records were found in the AXFR answer!\n") } // Normalize diff --git a/providers/azuredns/azureDnsProvider.go b/providers/azuredns/azureDnsProvider.go index c3131535a..3cd501677 100644 --- a/providers/azuredns/azureDnsProvider.go +++ b/providers/azuredns/azureDnsProvider.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "sort" "strings" "time" @@ -586,7 +587,7 @@ func (a *azurednsProvider) EnsureDomainExists(domain string) error { if _, ok := a.zones[domain]; ok { return nil } - fmt.Printf("Adding zone for %s to Azure dns account\n", domain) + printer.Printf("Adding zone for %s to Azure dns account\n", domain) ctx, cancel := context.WithTimeout(context.Background(), 6000*time.Second) defer cancel() diff --git a/providers/bind/bindProvider.go b/providers/bind/bindProvider.go index 7a76ea4be..b57ec255e 100644 --- a/providers/bind/bindProvider.go +++ b/providers/bind/bindProvider.go @@ -17,6 +17,7 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "io/ioutil" "os" "path/filepath" @@ -156,7 +157,7 @@ func (c *bindProvider) GetZoneRecords(domain string) (models.Records, error) { foundRecords := models.Records{} if _, err := os.Stat(c.directory); os.IsNotExist(err) { - fmt.Printf("\nWARNING: BIND directory %q does not exist!\n", c.directory) + printer.Printf("\nWARNING: BIND directory %q does not exist!\n", c.directory) } if c.zonefile == "" { @@ -289,7 +290,7 @@ func (c *bindProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*models. &models.Correction{ Msg: msg, F: func() error { - fmt.Printf("WRITING ZONEFILE: %v\n", c.zonefile) + printer.Printf("WRITING ZONEFILE: %v\n", c.zonefile) zf, err := os.Create(c.zonefile) if err != nil { return fmt.Errorf("could not create zonefile: %w", err) diff --git a/providers/cloudflare/cloudflareProvider.go b/providers/cloudflare/cloudflareProvider.go index 59558aeb0..8664a35d6 100644 --- a/providers/cloudflare/cloudflareProvider.go +++ b/providers/cloudflare/cloudflareProvider.go @@ -177,9 +177,9 @@ func (c *cloudflareProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*m if c.manageRedirects { prs, err := c.getPageRules(id, dc.Name) - //fmt.Printf("GET PAGE RULES:\n") + //printer.Printf("GET PAGE RULES:\n") //for i, p := range prs { - // fmt.Printf("%03d: %q\n", i, p.GetTargetField()) + // printer.Printf("%03d: %q\n", i, p.GetTargetField()) //} if err != nil { return nil, err @@ -701,7 +701,7 @@ func (c *cloudflareProvider) EnsureDomainExists(domain string) error { } var id string id, err := c.createZone(domain) - fmt.Printf("Added zone for %s to Cloudflare account: %s\n", domain, id) + printer.Printf("Added zone for %s to Cloudflare account: %s\n", domain, id) return err } diff --git a/providers/cscglobal/api.go b/providers/cscglobal/api.go index 31084c417..29dcc2141 100644 --- a/providers/cscglobal/api.go +++ b/providers/cscglobal/api.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "io/ioutil" "net/http" "os" @@ -316,9 +317,9 @@ func (client *providerClient) getDomains() ([]string, error) { return nil, err } - //fmt.Printf("------------------\n") - //fmt.Printf("DEBUG: GETDOMAINS bodystring = %s\n", bodyString) - //fmt.Printf("------------------\n") + //printer.Printf("------------------\n") + //printer.Printf("DEBUG: GETDOMAINS bodystring = %s\n", bodyString) + //printer.Printf("------------------\n") var dr domainsResult json.Unmarshal(bodyString, &dr) @@ -332,9 +333,9 @@ func (client *providerClient) getDomains() ([]string, error) { r = append(r, d.QualifiedDomainName) } - //fmt.Printf("------------------\n") - //fmt.Printf("DEBUG: GETDOMAINS dr = %+v\n", dr) - //fmt.Printf("------------------\n") + //printer.Printf("------------------\n") + //printer.Printf("DEBUG: GETDOMAINS dr = %+v\n", dr) + //printer.Printf("------------------\n") return r, nil } @@ -346,9 +347,9 @@ func (client *providerClient) getZoneRecordsAll(zone string) (*zoneResponse, err } if cscDebug { - fmt.Printf("------------------\n") - fmt.Printf("DEBUG: ZONE RESPONSE = %s\n", bodyString) - fmt.Printf("------------------\n") + printer.Printf("------------------\n") + printer.Printf("DEBUG: ZONE RESPONSE = %s\n", bodyString) + printer.Printf("------------------\n") } var dr zoneResponse @@ -369,7 +370,7 @@ func (client *providerClient) sendZoneEditRequest(domainname string, edits []zon return err } if cscDebug { - fmt.Printf("DEBUG: edit request = %s\n", requestBody) + printer.Printf("DEBUG: edit request = %s\n", requestBody) } responseBody, err := client.post("/zones/edits", requestBody) if err != nil { @@ -399,13 +400,11 @@ func (client *providerClient) waitRequestURL(statusURL string) error { for { statusBody, err := client.geturl(statusURL) if err != nil { - fmt.Println() return fmt.Errorf("CSC Global API error: %s DATA: %q", err, statusBody) } var statusResp zoneEditStatusResultZoneEditStatusResult err = json.Unmarshal(statusBody, &statusResp) if err != nil { - fmt.Println() return fmt.Errorf("CSC Global API error: %s DATA: %q", err, statusBody) } status, msg := statusResp.Content.Status, statusResp.Content.ErrorDescription @@ -413,19 +412,17 @@ func (client *providerClient) waitRequestURL(statusURL string) error { if isatty.IsTerminal(os.Stdout.Fd()) { dur := time.Since(t1).Round(time.Second) if msg == "" { - fmt.Printf("WAITING: % 6s STATUS=%s \r", dur, status) + printer.Printf("WAITING: % 6s STATUS=%s \r", dur, status) } else { - fmt.Printf("WAITING: % 6s STATUS=%s MSG=%q \r", dur, status, msg) + printer.Printf("WAITING: % 6s STATUS=%s MSG=%q \r", dur, status, msg) } } if status == "FAILED" { - fmt.Println() parts := strings.Split(statusResp.Links.Cancel, "/") client.cancelRequest(parts[len(parts)-1]) return fmt.Errorf("update failed: %s %s", msg, statusURL) } if status == "COMPLETED" { - fmt.Println() break } time.Sleep(1 * time.Second) @@ -476,15 +473,15 @@ func (client *providerClient) clearRequests(domain string) error { for i, ze := range dr.ZoneEdits { if cscDebug { if ze.Status != "COMPLETED" && ze.Status != "CANCELED" { - fmt.Printf("REQUEST %d: %s %s\n", i, ze.ID, ze.Status) + printer.Printf("REQUEST %d: %s %s\n", i, ze.ID, ze.Status) } } switch ze.Status { case "PROPAGATING": - fmt.Printf("INFO: Waiting for id=%s status=%s\n", ze.ID, ze.Status) + printer.Printf("INFO: Waiting for id=%s status=%s\n", ze.ID, ze.Status) client.waitRequest(ze.ID) case "FAILED": - fmt.Printf("INFO: Deleting request status=%s id=%s\n", ze.Status, ze.ID) + printer.Printf("INFO: Deleting request status=%s id=%s\n", ze.Status, ze.ID) client.cancelRequest(ze.ID) case "COMPLETED", "CANCELED": continue @@ -538,7 +535,7 @@ func (client *providerClient) put(endpoint string, requestBody []byte) ([]byte, func (client *providerClient) delete(endpoint string) ([]byte, error) { hclient := &http.Client{} - fmt.Printf("DEBUG: delete endpoint: %q\n", apiBase+endpoint) + printer.Printf("DEBUG: delete endpoint: %q\n", apiBase+endpoint) req, _ := http.NewRequest("DELETE", apiBase+endpoint, nil) // Add headers @@ -554,10 +551,10 @@ func (client *providerClient) delete(endpoint string) ([]byte, error) { bodyString, _ := ioutil.ReadAll(resp.Body) if resp.StatusCode == 200 { - fmt.Printf("DEBUG: Delete successful (200)\n") + printer.Printf("DEBUG: Delete successful (200)\n") return bodyString, nil } - fmt.Printf("DEBUG: Delete failed (%d)\n", resp.StatusCode) + printer.Printf("DEBUG: Delete failed (%d)\n", resp.StatusCode) // Got a error response from API, see if it's json format var errResp errorResponse @@ -589,10 +586,10 @@ func (client *providerClient) post(endpoint string, requestBody []byte) ([]byte, } bodyString, _ := ioutil.ReadAll(resp.Body) - //fmt.Printf("------------------\n") - //fmt.Printf("DEBUG: resp.StatusCode == %d\n", resp.StatusCode) - //fmt.Printf("POST RESPONSE = %s\n", bodyString) - //fmt.Printf("------------------\n") + //printer.Printf("------------------\n") + //printer.Printf("DEBUG: resp.StatusCode == %d\n", resp.StatusCode) + //printer.Printf("POST RESPONSE = %s\n", bodyString) + //printer.Printf("------------------\n") if resp.StatusCode == 201 { return bodyString, nil } diff --git a/providers/cscglobal/dns.go b/providers/cscglobal/dns.go index 21929356b..02490af15 100644 --- a/providers/cscglobal/dns.go +++ b/providers/cscglobal/dns.go @@ -213,7 +213,7 @@ func makePurge(domainname string, cor diff.Correlation) zoneResourceRecordEdit { if cor.Existing.Type == "CAA" { var tagValue = cor.Existing.CaaTag - //fmt.Printf("DEBUG: CAA TAG = %q\n", tagValue) + //printer.Printf("DEBUG: CAA TAG = %q\n", tagValue) zer.CurrentTag = &tagValue } diff --git a/providers/desec/convert.go b/providers/desec/convert.go index 760b803d6..731da5c91 100644 --- a/providers/desec/convert.go +++ b/providers/desec/convert.go @@ -4,7 +4,6 @@ package desec import ( "fmt" - "github.com/StackExchange/dnscontrol/v3/models" "github.com/StackExchange/dnscontrol/v3/pkg/printer" ) diff --git a/providers/desec/desecProvider.go b/providers/desec/desecProvider.go index 6c4f8f197..0c40e0d26 100644 --- a/providers/desec/desecProvider.go +++ b/providers/desec/desecProvider.go @@ -74,7 +74,7 @@ func (c *desecProvider) GetNameservers(domain string) ([]*models.Nameserver, err func (c *desecProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) { if dc.AutoDNSSEC == "off" { - fmt.Printf("Notice: DNSSEC signing was not requested, but cannot be turned off. (deSEC always signs all records.)\n") + printer.Printf("Notice: DNSSEC signing was not requested, but cannot be turned off. (deSEC always signs all records.)\n") } existing, err := c.GetZoneRecords(dc.Name) diff --git a/providers/desec/protocol.go b/providers/desec/protocol.go index df1f7413e..7f79b8f26 100644 --- a/providers/desec/protocol.go +++ b/providers/desec/protocol.go @@ -146,13 +146,13 @@ func (c *desecProvider) convertLinks(links string) map[string]string { for _, link := range strings.Split(links, ", ") { tmpurl := strings.Split(link, "; ") if len(tmpurl) != 2 { - fmt.Printf("unexpected link header %s", link) + printer.Printf("unexpected link header %s", link) continue } r := regexp.MustCompile(`rel="(.*)"`) matches := r.FindStringSubmatch(tmpurl[1]) if len(matches) != 2 { - fmt.Printf("unexpected label %s", tmpurl[1]) + printer.Printf("unexpected label %s", tmpurl[1]) continue } // mapping["$label"] = "$URL" diff --git a/providers/digitalocean/auditrecords.go b/providers/digitalocean/auditrecords.go index b70ff47ad..b1d093024 100644 --- a/providers/digitalocean/auditrecords.go +++ b/providers/digitalocean/auditrecords.go @@ -2,7 +2,6 @@ package digitalocean import ( "fmt" - "github.com/StackExchange/dnscontrol/v3/models" "github.com/StackExchange/dnscontrol/v3/pkg/recordaudit" ) diff --git a/providers/dnsimple/dnsimpleProvider.go b/providers/dnsimple/dnsimpleProvider.go index d63336fff..835b095ac 100644 --- a/providers/dnsimple/dnsimpleProvider.go +++ b/providers/dnsimple/dnsimpleProvider.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "sort" "strconv" "strings" @@ -563,7 +564,7 @@ func removeOtherApexNS(dc *models.DomainConfig) { // Child delegations are supported so we allow non-apex NS records. if rec.GetLabelFQDN() == dc.Name { if !strings.HasSuffix(rec.GetTargetField(), ".dnsimple.com.") { - fmt.Printf("Warning: dnsimple.com does not allow NS records to be modified. %s will not be added.\n", rec.GetTargetField()) + printer.Printf("Warning: dnsimple.com does not allow NS records to be modified. %s will not be added.\n", rec.GetTargetField()) } continue } diff --git a/providers/dnsmadeeasy/api.go b/providers/dnsmadeeasy/api.go index 8030892da..305d64d45 100644 --- a/providers/dnsmadeeasy/api.go +++ b/providers/dnsmadeeasy/api.go @@ -2,6 +2,7 @@ package dnsmadeeasy import ( "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "net/http" "time" ) @@ -17,7 +18,7 @@ func newProvider(apiKey string, secretKey string, sandbox bool, debug bool) *dns baseURL = sandboxBaseURLV2_0 } - fmt.Printf("Creating DNSMADEEASY provider for %q\n", baseURL) + printer.Printf("Creating DNSMADEEASY provider for %q\n", baseURL) return &dnsMadeEasyProvider{ restAPI: &dnsMadeEasyRestAPI{ diff --git a/providers/dnsmadeeasy/restApi.go b/providers/dnsmadeeasy/restApi.go index 2f942a51e..55a8371cb 100644 --- a/providers/dnsmadeeasy/restApi.go +++ b/providers/dnsmadeeasy/restApi.go @@ -7,6 +7,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "net/http" "net/http/httputil" "strings" @@ -221,7 +222,7 @@ retry: if restApi.dumpHTTPRequest { dump, _ := httputil.DumpRequest(req, true) - fmt.Println(string(dump)) + printer.Printf(string(dump)) } res, err := restApi.httpClient.Do(req) @@ -233,7 +234,7 @@ retry: if restApi.dumpHTTPResponse { dump, _ := httputil.DumpResponse(res, true) - fmt.Println(string(dump)) + printer.Printf(string(dump)) } if res.StatusCode < http.StatusOK || res.StatusCode >= http.StatusBadRequest { @@ -244,7 +245,7 @@ retry: } if len(apiErr.Error) == 1 && apiErr.Error[0] == "Rate limit exceeded" { - fmt.Printf("pausing DNSMADEEASY due to ratelimit: %v seconds\n", backoff) + printer.Printf("pausing DNSMADEEASY due to ratelimit: %v seconds\n", backoff) time.Sleep(backoff) diff --git a/providers/exoscale/exoscaleProvider.go b/providers/exoscale/exoscaleProvider.go index 6fd582337..d0bfc0c6c 100644 --- a/providers/exoscale/exoscaleProvider.go +++ b/providers/exoscale/exoscaleProvider.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "strings" "github.com/exoscale/egoscale" @@ -257,7 +258,7 @@ func removeOtherNS(dc *models.DomainConfig) { if rec.GetLabelFQDN() == dc.Name && defaultNSSUffix(rec.GetTargetField()) { continue } - fmt.Printf("Warning: exoscale.com(.io, .ch, .net) does not allow NS records to be modified. %s will not be added.\n", rec.GetTargetField()) + printer.Printf("Warning: exoscale.com(.io, .ch, .net) does not allow NS records to be modified. %s will not be added.\n", rec.GetTargetField()) continue } newList = append(newList, rec) diff --git a/providers/gandiv5/convert.go b/providers/gandiv5/convert.go index 08022fb8c..0187a756c 100644 --- a/providers/gandiv5/convert.go +++ b/providers/gandiv5/convert.go @@ -4,7 +4,6 @@ package gandiv5 import ( "fmt" - "github.com/go-gandi/go-gandi/livedns" "github.com/StackExchange/dnscontrol/v3/models" diff --git a/providers/gandiv5/gandi_v5Provider.go b/providers/gandiv5/gandi_v5Provider.go index 7b72ada83..61416f148 100644 --- a/providers/gandiv5/gandi_v5Provider.go +++ b/providers/gandiv5/gandi_v5Provider.go @@ -338,9 +338,9 @@ func (client *gandiv5Provider) GenerateDomainCorrections(dc *models.DomainConfig // debugRecords prints a list of RecordConfig. func debugRecords(note string, recs []*models.RecordConfig) { - fmt.Println("DEBUG:", note) + printer.Debugf(note) for k, v := range recs { - fmt.Printf(" %v: %v %v %v %v\n", k, v.GetLabel(), v.Type, v.TTL, v.GetTargetCombined()) + printer.Printf(" %v: %v %v %v %v\n", k, v.GetLabel(), v.Type, v.TTL, v.GetTargetCombined()) } } diff --git a/providers/gcloud/gcloudProvider.go b/providers/gcloud/gcloudProvider.go index 7db60e426..dfec2207d 100644 --- a/providers/gcloud/gcloudProvider.go +++ b/providers/gcloud/gcloudProvider.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "log" "strings" "time" @@ -86,7 +87,7 @@ func New(cfg map[string]string, metadata json.RawMessage) (providers.DNSServiceP } var nss *string if val, ok := cfg["name_server_set"]; ok { - fmt.Printf("GCLOUD :name_server_set %s configured\n", val) + printer.Printf("GCLOUD :name_server_set %s configured\n", val) nss = sPtr(val) } @@ -320,7 +321,7 @@ func (g *gcloudProvider) EnsureDomainExists(domain string) error { } var mz *gdns.ManagedZone if g.nameServerSet != nil { - fmt.Printf("Adding zone for %s to gcloud account with name_server_set %s\n", domain, *g.nameServerSet) + printer.Printf("Adding zone for %s to gcloud account with name_server_set %s\n", domain, *g.nameServerSet) mz = &gdns.ManagedZone{ DnsName: domain + ".", NameServerSet: *g.nameServerSet, @@ -328,7 +329,7 @@ func (g *gcloudProvider) EnsureDomainExists(domain string) error { Description: "zone added by dnscontrol", } } else { - fmt.Printf("Adding zone for %s to gcloud account \n", domain) + printer.Printf("Adding zone for %s to gcloud account \n", domain) mz = &gdns.ManagedZone{ DnsName: domain + ".", Name: "zone-" + strings.Replace(domain, ".", "-", -1), diff --git a/providers/hetzner/api.go b/providers/hetzner/api.go index 5de28e24e..f481d136e 100644 --- a/providers/hetzner/api.go +++ b/providers/hetzner/api.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "io" "io/ioutil" "net/http" @@ -236,7 +237,7 @@ func (api *hetznerProvider) request(endpoint string, method string, request inte cleanupResponseBody := func() { err := resp.Body.Close() if err != nil { - fmt.Printf("failed closing response body: %q\n", err) + printer.Printf("failed closing response body: %q\n", err) } } @@ -251,7 +252,7 @@ func (api *hetznerProvider) request(endpoint string, method string, request inte defer cleanupResponseBody() if !statusOK(resp.StatusCode) { data, _ := ioutil.ReadAll(resp.Body) - fmt.Println(string(data)) + printer.Printf(string(data)) return fmt.Errorf("bad status code from HETZNER: %d not 200", resp.StatusCode) } if target == nil { @@ -325,7 +326,7 @@ func (requestRateLimiter *requestRateLimiter) handleRateLimitedRequest() { case "second": message = fmt.Sprintf(message, "Second", "Minute") } - fmt.Println(message) + printer.Printf(message) } func (requestRateLimiter *requestRateLimiter) handleResponse(resp http.Response) { diff --git a/providers/hexonet/error.go b/providers/hexonet/error.go index 6713110ba..cdacd4186 100644 --- a/providers/hexonet/error.go +++ b/providers/hexonet/error.go @@ -2,7 +2,6 @@ package hexonet import ( "fmt" - "github.com/hexonet/go-sdk/v3/response" ) diff --git a/providers/hexonet/hexonetProvider.go b/providers/hexonet/hexonetProvider.go index 2d5712f61..59eb70924 100644 --- a/providers/hexonet/hexonetProvider.go +++ b/providers/hexonet/hexonetProvider.go @@ -4,7 +4,6 @@ package hexonet import ( "encoding/json" "fmt" - "github.com/StackExchange/dnscontrol/v3/pkg/version" "github.com/StackExchange/dnscontrol/v3/providers" hxcl "github.com/hexonet/go-sdk/v3/apiclient" diff --git a/providers/hexonet/records.go b/providers/hexonet/records.go index 5753de411..9125852ec 100644 --- a/providers/hexonet/records.go +++ b/providers/hexonet/records.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "regexp" "strconv" "strings" @@ -162,9 +163,9 @@ func toRecord(r *HXRecord, origin string) *models.RecordConfig { func (n *HXClient) showCommand(cmd map[string]string) { b, err := json.MarshalIndent(cmd, "", " ") if err != nil { - fmt.Println("error:", err) + fmt.Errorf("error: %w", err) } - fmt.Print(string(b)) + printer.Printf(string(b)) } func (n *HXClient) updateZoneBy(params map[string]interface{}, domain string) error { diff --git a/providers/inwx/inwxProvider.go b/providers/inwx/inwxProvider.go index a4baa0458..2fcbee703 100644 --- a/providers/inwx/inwxProvider.go +++ b/providers/inwx/inwxProvider.go @@ -3,6 +3,7 @@ package inwx import ( "encoding/json" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "sort" "strings" "time" @@ -100,7 +101,7 @@ func (api *inwxAPI) loginHelper(TOTPValue string, TOTPKey string) error { switch TFA := resp.TFA; TFA { case "0": if TOTPKey != "" || TOTPValue != "" { - fmt.Printf("INWX: Warning: no TOTP requested by INWX but totp/totp-key is present in `creds.json`\n") + printer.Printf("INWX: Warning: no TOTP requested by INWX but totp/totp-key is present in `creds.json`\n") } case "GOOGLE-AUTH": tan, err := getOTP(TOTPValue, TOTPKey) @@ -417,6 +418,6 @@ func (api *inwxAPI) EnsureDomainExists(domain string) error { if err != nil { return err } - fmt.Printf("Added zone for %s to INWX account with id %d\n", domain, id) + printer.Printf("Added zone for %s to INWX account with id %d\n", domain, id) return nil } diff --git a/providers/msdns/corrections.go b/providers/msdns/corrections.go index a80ef4082..b9dfec7b5 100644 --- a/providers/msdns/corrections.go +++ b/providers/msdns/corrections.go @@ -2,7 +2,6 @@ package msdns import ( "fmt" - "github.com/StackExchange/dnscontrol/v3/models" "github.com/StackExchange/dnscontrol/v3/pkg/diff" "github.com/StackExchange/dnscontrol/v3/pkg/txtutil" diff --git a/providers/msdns/msdnsProvider.go b/providers/msdns/msdnsProvider.go index 2a0808d37..b71bd8c7a 100644 --- a/providers/msdns/msdnsProvider.go +++ b/providers/msdns/msdnsProvider.go @@ -2,7 +2,7 @@ package msdns import ( "encoding/json" - "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "runtime" "github.com/StackExchange/dnscontrol/v3/models" @@ -46,7 +46,7 @@ func init() { func newDNS(config map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) { if runtime.GOOS != "windows" { - fmt.Println("INFO: PowerShell not available. Disabling Active Directory provider.") + printer.Printf("INFO: PowerShell not available. Disabling Active Directory provider.") return providers.None{}, nil } diff --git a/providers/msdns/naptr.go b/providers/msdns/naptr.go index 38a7044d7..bd026c908 100644 --- a/providers/msdns/naptr.go +++ b/providers/msdns/naptr.go @@ -7,6 +7,7 @@ import ( "bytes" "encoding/hex" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "log" "strconv" @@ -77,7 +78,7 @@ func decodeRecordDataNaptr(s string) models.RecordConfig { // At this point we should have consumed the entire string. if s != "" { - fmt.Printf("WARNING: REMAINDER:=%q\n", s) + printer.Printf("WARNING: REMAINDER:=%q\n", s) } return rc diff --git a/providers/msdns/powershell.go b/providers/msdns/powershell.go index 582b5a1f0..ed7d63416 100644 --- a/providers/msdns/powershell.go +++ b/providers/msdns/powershell.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "io/ioutil" "log" "os" @@ -30,7 +31,7 @@ func newPowerShell(config map[string]string) (*psHandle, error) { pssession := config["pssession"] if pssession != "" { - fmt.Printf("INFO: PowerShell commands will run on %q\n", pssession) + printer.Printf("INFO: PowerShell commands will run on %q\n", pssession) // create a remote shell by wrapping the existing one in the session middleware mconfig := middleware.NewSessionConfig() mconfig.ComputerName = pssession @@ -68,7 +69,7 @@ func (psh *psHandle) GetDNSServerZoneAll(dnsserver string) ([]string, error) { return nil, err } if stderr != "" { - fmt.Printf("STDERROR = %q\n", stderr) + printer.Printf("STDERROR = %q\n", stderr) return nil, fmt.Errorf("unexpected stderr from Get-DnsServerZones: %q", stderr) } @@ -113,11 +114,11 @@ func (psh *psHandle) GetDNSZoneRecords(dnsserver, domain string) ([]nativeRecord return nil, err } if stderr != "" { - fmt.Printf("STDERROR GetDNSZR = %q\n", stderr) + printer.Printf("STDERROR GetDNSZR = %q\n", stderr) return nil, fmt.Errorf("unexpected stderr from PSZoneDump: %q", stderr) } if stdout != "" { - fmt.Printf("STDOUT GetDNSZR = %q\n", stdout) + printer.Printf("STDOUT GetDNSZR = %q\n", stdout) } contents, err := utfutil.ReadFile(filename, utfutil.UTF8) @@ -126,9 +127,9 @@ func (psh *psHandle) GetDNSZoneRecords(dnsserver, domain string) ([]nativeRecord } os.Remove(filename) // TODO(tlim): There should be a debug flag that leaves the tmp file around. - //fmt.Printf("CONTENTS = %s\n", contents) - //fmt.Printf("CONTENTS STR = %q\n", contents[:10]) - //fmt.Printf("CONTENTS HEX = %v\n", []byte(contents)[:10]) + //printer.Printf("CONTENTS = %s\n", contents) + //printer.Printf("CONTENTS STR = %q\n", contents[:10]) + //printer.Printf("CONTENTS HEX = %v\n", []byte(contents)[:10]) //ioutil.WriteFile("/temp/list.json", contents, 0777) var records []nativeRecord err = json.Unmarshal(contents, &records) @@ -195,7 +196,7 @@ func (psh *psHandle) RecordDelete(dnsserver, domain string, rec *models.RecordCo var c string if rec.Type == "NAPTR" { c = generatePSDeleteNaptr(dnsserver, domain, rec) - //fmt.Printf("DEBUG: deleteNAPTR: %s\n", c) + //printer.Printf("DEBUG: deleteNAPTR: %s\n", c) } else { c = generatePSDelete(dnsserver, domain, rec) } @@ -205,7 +206,7 @@ func (psh *psHandle) RecordDelete(dnsserver, domain string, rec *models.RecordCo return err } if stderr != "" { - fmt.Printf("STDERROR = %q\n", stderr) + printer.Printf("STDERROR = %q\n", stderr) return fmt.Errorf("unexpected stderr from PSDelete: %q", stderr) } return nil @@ -219,7 +220,7 @@ func generatePSDelete(dnsserver, domain string, rec *models.RecordConfig) string if rec.Type == "NAPTR" { x := b.String() + generatePSDeleteNaptr(dnsserver, domain, rec) - //fmt.Printf("NAPTR DELETE: %s\n", x) + //printer.Printf("NAPTR DELETE: %s\n", x) return x } @@ -241,7 +242,7 @@ func generatePSDelete(dnsserver, domain string, rec *models.RecordConfig) string } else { fmt.Fprintf(&b, ` -RecordData "%s"`, rec.GetTargetField()) } - //fmt.Printf("DEBUG PSDelete CMD = (\n%s\n)\n", b.String()) + //printer.Printf("DEBUG PSDelete CMD = (\n%s\n)\n", b.String()) return b.String() } @@ -250,10 +251,10 @@ func (psh *psHandle) RecordCreate(dnsserver, domain string, rec *models.RecordCo var c string if rec.Type == "NAPTR" { c = generatePSCreateNaptr(dnsserver, domain, rec) - //fmt.Printf("DEBUG: createNAPTR: %s\n", c) + //printer.Printf("DEBUG: createNAPTR: %s\n", c) } else { c = generatePSCreate(dnsserver, domain, rec) - //fmt.Printf("DEBUG: PScreate\n") + //printer.Printf("DEBUG: PScreate\n") } stdout, stderr, err := psh.shell.Execute(c) @@ -261,8 +262,8 @@ func (psh *psHandle) RecordCreate(dnsserver, domain string, rec *models.RecordCo return err } if stderr != "" { - fmt.Printf("STDOUT RecordCreate = %s\n", stdout) - fmt.Printf("STDERROR RecordCreate = %q\n", stderr) + printer.Printf("STDOUT RecordCreate = %s\n", stdout) + printer.Printf("STDERROR RecordCreate = %q\n", stderr) return fmt.Errorf("unexpected stderr from PSCreate: %q", stderr) } return nil @@ -302,8 +303,8 @@ func generatePSCreate(dnsserver, domain string, rec *models.RecordConfig) string //case "WKS": // fmt.Fprintf(&b, ` -Wks -InternetAddress -InternetProtocol {UDP | TCP} -Service `, rec.GetTargetField()) case "TXT": - //fmt.Printf("DEBUG TXT len = %v\n", rec.TxtStrings) - //fmt.Printf("DEBUG TXT target = %q\n", rec.GetTargetField()) + //printer.Printf("DEBUG TXT len = %v\n", rec.TxtStrings) + //printer.Printf("DEBUG TXT target = %q\n", rec.GetTargetField()) fmt.Fprintf(&b, ` -Txt -DescriptiveText %s`, rec.GetTargetField()) //case "RT": // fmt.Fprintf(&b, ` -RT -IntermediateHost -Preference `, rec.GetTargetField()) @@ -331,7 +332,7 @@ func generatePSCreate(dnsserver, domain string, rec *models.RecordConfig) string // We panic so that we quickly find any switch statements // that have not been updated for a new RR type. } - //fmt.Printf("DEBUG PSCreate CMD = (\n%s\n)\n", b.String()) + //printer.Printf("DEBUG PSCreate CMD = (\n%s\n)\n", b.String()) return b.String() } @@ -341,7 +342,7 @@ func (psh *psHandle) RecordModify(dnsserver, domain string, old, rec *models.Rec return err } if stderr != "" { - fmt.Printf("STDERROR = %q\n", stderr) + printer.Printf("STDERROR = %q\n", stderr) return fmt.Errorf("unexpected stderr from PSModify: %q", stderr) } return nil @@ -494,11 +495,11 @@ func generatePSModify(dnsserver, domain string, old, rec *models.RecordConfig) s // // that have not been updated for a new RR type. // } // fmt.Fprintf(&b, " ; ") -// //fmt.Printf("DEBUG CCMD: %s\n", b.String()) +// //printer.Printf("DEBUG CCMD: %s\n", b.String()) // // fmt.Fprintf(&b, "Set-DnsServerResourceRecord") // fmt.Fprintf(&b, ` -ZoneName "%s"`, domain) // fmt.Fprintf(&b, ` -NewInputObject $NewObj -OldInputObject $OldObj`) // -// fmt.Printf("DEBUG MCMD: %s", b.String()) +// printer.Printf("DEBUG MCMD: %s", b.String()) // return b.String() diff --git a/providers/namecheap/namecheapProvider.go b/providers/namecheap/namecheapProvider.go index 178f62872..f2fae5675 100644 --- a/providers/namecheap/namecheapProvider.go +++ b/providers/namecheap/namecheapProvider.go @@ -146,7 +146,7 @@ func (n *namecheapProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mo dc.Filter(func(r *models.RecordConfig) bool { if r.Type == "NS" && r.GetLabel() == "@" { if !strings.HasSuffix(r.GetTargetField(), "registrar-servers.com.") { - fmt.Println("\n", r.GetTargetField(), "Namecheap does not support changing apex NS records. Skipping.") + printer.Println("\n", r.GetTargetField(), "Namecheap does not support changing apex NS records. Skipping.") } return false } diff --git a/providers/namedotcom/auditrecords.go b/providers/namedotcom/auditrecords.go index 661108d4d..378a613b0 100644 --- a/providers/namedotcom/auditrecords.go +++ b/providers/namedotcom/auditrecords.go @@ -2,7 +2,6 @@ package namedotcom import ( "fmt" - "github.com/StackExchange/dnscontrol/v3/models" "github.com/StackExchange/dnscontrol/v3/pkg/recordaudit" ) diff --git a/providers/netcup/netcupProvider.go b/providers/netcup/netcupProvider.go index 0adaa9031..eb7ec0d9d 100644 --- a/providers/netcup/netcupProvider.go +++ b/providers/netcup/netcupProvider.go @@ -3,7 +3,6 @@ package netcup import ( "encoding/json" "fmt" - "github.com/StackExchange/dnscontrol/v3/models" "github.com/StackExchange/dnscontrol/v3/pkg/diff" // no need for txtutil.SplitSingleLongTxt in function GetDomainCorrections diff --git a/providers/octodns/octodnsProvider.go b/providers/octodns/octodnsProvider.go index 76a388f47..ea692aef6 100644 --- a/providers/octodns/octodnsProvider.go +++ b/providers/octodns/octodnsProvider.go @@ -22,6 +22,7 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "log" "os" "path/filepath" @@ -162,7 +163,7 @@ func (c *octodnsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode &models.Correction{ Msg: msg, F: func() error { - fmt.Printf("CREATING CONFIGFILE: %v\n", zoneFileName) + printer.Printf("CREATING CONFIGFILE: %v\n", zoneFileName) zf, err := os.Create(zoneFileName) if err != nil { log.Fatalf("Could not create zonefile: %v", err) diff --git a/providers/octodns/octoyaml/js.go b/providers/octodns/octoyaml/js.go index bd30f8032..3e2dcb294 100644 --- a/providers/octodns/octoyaml/js.go +++ b/providers/octodns/octoyaml/js.go @@ -2,7 +2,7 @@ package octoyaml import ( "encoding/json" - "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "io/ioutil" "github.com/StackExchange/dnscontrol/v3/models" @@ -62,7 +62,7 @@ func require(call otto.FunctionCall) otto.Value { throw(call.Otto, "require takes exactly one argument") } file := call.Argument(0).String() - fmt.Printf("requiring: %s\n", file) + printer.Printf("requiring: %s\n", file) data, err := ioutil.ReadFile(file) if err != nil { throw(call.Otto, err.Error()) diff --git a/providers/octodns/octoyaml/read.go b/providers/octodns/octoyaml/read.go index 672f6e7a7..bb9e601bc 100644 --- a/providers/octodns/octoyaml/read.go +++ b/providers/octodns/octoyaml/read.go @@ -36,15 +36,15 @@ func ReadYaml(r io.Reader, origin string) (models.Records, error) { if err != nil { return nil, fmt.Errorf("could not unmarshal yaml: %w", err) } - //fmt.Printf("ReadYaml: mysterydata == %v\n", mysterydata) + //printer.Printf("ReadYaml: mysterydata == %v\n", mysterydata) // Traverse every key/value pair. for k, v := range mysterydata { // Each label // k, v: k is the label, v is everything we know about the label. // In other code, k1, v2 refers to one level deeper, k3, k3 refers to // one more level deeper, and so on. - //fmt.Printf("ReadYaml: NEXT KEY\n") - //fmt.Printf("ReadYaml: KEY=%s v.(type)=%s\n", k, reflect.TypeOf(v).String()) + //printer.Printf("ReadYaml: NEXT KEY\n") + //printer.Printf("ReadYaml: KEY=%s v.(type)=%s\n", k, reflect.TypeOf(v).String()) switch v.(type) { case map[interface{}]interface{}: // The value is itself a map. This means we have a label with @@ -82,10 +82,10 @@ func ReadYaml(r io.Reader, origin string) (models.Records, error) { // value: mx2.example.com. for i, v3 := range v.([]interface{}) { // All the label's list _ = i - //fmt.Printf("ReadYaml: list key=%s i=%d v3.(type)=%s\n", k, i, typeof(v3)) + //printer.Printf("ReadYaml: list key=%s i=%d v3.(type)=%s\n", k, i, typeof(v3)) switch v3.(type) { case map[interface{}]interface{}: - //fmt.Printf("ReadYaml: v3=%v\n", v3) + //printer.Printf("ReadYaml: v3=%v\n", v3) results, err = parseLeaf(results, k, v3, origin) if err != nil { return results, fmt.Errorf("leaf v3=%v: %w", v3, err) @@ -101,7 +101,7 @@ func ReadYaml(r io.Reader, origin string) (models.Records, error) { } sortRecs(results, origin) - //fmt.Printf("ReadYaml: RESULTS=%v\n", results) + //printer.Printf("ReadYaml: RESULTS=%v\n", results) return results, nil } @@ -111,14 +111,14 @@ func parseLeaf(results models.Records, k string, v interface{}, origin string) ( rTargets := []string{} var someresults models.Records for k2, v2 := range v.(map[interface{}]interface{}) { // All the label's items - // fmt.Printf("ReadYaml: ifs tk2=%s tv2=%s len(rTargets)=%d\n", typeof(k2), typeof(v2), len(rTargets)) + // printer.Printf("ReadYaml: ifs tk2=%s tv2=%s len(rTargets)=%d\n", typeof(k2), typeof(v2), len(rTargets)) if typeof(k2) == "string" && (typeof(v2) == "string" || typeof(v2) == "int") { // The 2nd level key is a string, and the 2nd level value is a string or int. // Here are 3 examples: // type: CNAME // value: foo.example.com. // ttl: 3 - //fmt.Printf("parseLeaf: k2=%s v2=%v\n", k2, v2) + //printer.Printf("parseLeaf: k2=%s v2=%v\n", k2, v2) switch k2.(string) { case "type": rType = v2.(string) @@ -153,7 +153,7 @@ func parseLeaf(results models.Records, k string, v interface{}, origin string) ( // - 1.2.3.3 // We collect all the values for later, when we'll need to generate // one RecordConfig for each value. - //fmt.Printf("parseLeaf: s-append %s\n", v3.(string)) + //printer.Printf("parseLeaf: s-append %s\n", v3.(string)) rTargets = append(rTargets, v3.(string)) case map[interface{}]interface{}: // Example: @@ -166,7 +166,7 @@ func parseLeaf(results models.Records, k string, v interface{}, origin string) ( // we should have enough to generate a single RecordConfig. newRc := newRecordConfig(k, rType, "", rTTL, origin) for k4, v4 := range v3.(map[interface{}]interface{}) { - //fmt.Printf("parseLeaf: k4=%s v4=%s\n", k4, v4) + //printer.Printf("parseLeaf: k4=%s v4=%s\n", k4, v4) switch k4.(string) { case "priority": // MX,SRV priority := uint16(v4.(int)) @@ -181,7 +181,7 @@ func parseLeaf(results models.Records, k string, v interface{}, origin string) ( newRc.SetTarget(v4.(string)) } } - //fmt.Printf("parseLeaf: append %v\n", newRc) + //printer.Printf("parseLeaf: append %v\n", newRc) someresults = append(someresults, newRc) default: return nil, fmt.Errorf("parseLeaf: unknown type in map: rtype=%s k=%s v3.(type)=%T v3=%v", rType, k, v3, v3) @@ -191,9 +191,9 @@ func parseLeaf(results models.Records, k string, v interface{}, origin string) ( return nil, fmt.Errorf("parseLeaf: unknown type in level 2: k=%s k2=%s v.2(type)=%T v2=%v", k, k2, v2, v2) } } - // fmt.Printf("parseLeaf: Target=(%v)\n", rTarget) - // fmt.Printf("parseLeaf: len(rTargets)=%d\n", len(rTargets)) - // fmt.Printf("parseLeaf: len(someresults)=%d\n", len(someresults)) + // printer.Printf("parseLeaf: Target=(%v)\n", rTarget) + // printer.Printf("parseLeaf: len(rTargets)=%d\n", len(rTargets)) + // printer.Printf("parseLeaf: len(someresults)=%d\n", len(someresults)) // We've now looped through everything about one label. Make the RecordConfig(s). @@ -216,12 +216,12 @@ func parseLeaf(results models.Records, k string, v interface{}, origin string) ( } } else if rTarget != "" && len(rTargets) == 0 { // The file used "value". Generate a single RecordConfig - //fmt.Printf("parseLeaf: 1-newRecordConfig(%v, %v, %v, %v, %v)\n", k, rType, rTarget, rTTL, origin) + //printer.Printf("parseLeaf: 1-newRecordConfig(%v, %v, %v, %v, %v)\n", k, rType, rTarget, rTTL, origin) results = append(results, newRecordConfig(k, rType, rTarget, rTTL, origin)) } else { // The file used "values" so now we must generate a RecordConfig for each value. for _, target := range rTargets { - //fmt.Printf("parseLeaf: 3-newRecordConfig(%v, %v, %v, %v, %v)\n", k, rType, target, rTTL, origin) + //printer.Printf("parseLeaf: 3-newRecordConfig(%v, %v, %v, %v, %v)\n", k, rType, target, rTTL, origin) results = append(results, newRecordConfig(k, rType, target, rTTL, origin)) } } diff --git a/providers/octodns/octoyaml/write.go b/providers/octodns/octoyaml/write.go index 75bf02887..f2e83ff34 100644 --- a/providers/octodns/octoyaml/write.go +++ b/providers/octodns/octoyaml/write.go @@ -168,9 +168,9 @@ func oneLabel(records models.Records) yaml.MapItem { if v.Type == "TXT" { v.Value = strings.Replace(models.StripQuotes(v.Value), `;`, `\;`, -1) } - //fmt.Printf("yamlwrite:oneLabel: simple ttl=%d\n", v.TTL) + //printer.Printf("yamlwrite:oneLabel: simple ttl=%d\n", v.TTL) item.Value = v - //fmt.Printf("yamlwrite:oneLabel: SIMPLE=%v\n", item) + //printer.Printf("yamlwrite:oneLabel: SIMPLE=%v\n", item) return item case "MX", "SRV": // Always processed as a complex{} @@ -191,7 +191,7 @@ func oneLabel(records models.Records) yaml.MapItem { v.Values = append(v.Values, rec.GetTargetField()) } item.Value = v - //fmt.Printf("SIMPLE=%v\n", item) + //printer.Printf("SIMPLE=%v\n", item) return item case "MX", "SRV": // Always processed as a complex{} @@ -207,14 +207,14 @@ func oneLabel(records models.Records) yaml.MapItem { var last = records[0].Type for i := range records { if records[i].Type != last { - //fmt.Printf("yamlwrite:oneLabel: Calling oneType( [%d:%d] ) last=%s type=%s\n", low, i, last, records[0].Type) + //printer.Printf("yamlwrite:oneLabel: Calling oneType( [%d:%d] ) last=%s type=%s\n", low, i, last, records[0].Type) lst = append(lst, oneType(records[low:i])) low = i // Current is the first of a run. last = records[i].Type } if i == (len(records) - 1) { // we are on the last element. - //fmt.Printf("yamlwrite:oneLabel: Calling oneType( [%d:%d] ) last=%s type=%s\n", low, i+1, last, records[0].Type) + //printer.Printf("yamlwrite:oneLabel: Calling oneType( [%d:%d] ) last=%s type=%s\n", low, i+1, last, records[0].Type) lst = append(lst, oneType(records[low:i+1])) } } @@ -226,7 +226,7 @@ func oneLabel(records models.Records) yaml.MapItem { // oneType returns interfaces that will MarshalYAML properly for a label with // one or more records, all the same rtype. func oneType(records models.Records) interface{} { - //fmt.Printf("yamlwrite:oneType len=%d type=%s\n", len(records), records[0].Type) + //printer.Printf("yamlwrite:oneType len=%d type=%s\n", len(records), records[0].Type) rtype := records[0].Type switch rtype { case "A", "AAAA", "NS": diff --git a/providers/route53/route53Provider.go b/providers/route53/route53Provider.go index 971e1c27e..4ef9c6234 100644 --- a/providers/route53/route53Provider.go +++ b/providers/route53/route53Provider.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "log" "sort" "strings" @@ -63,7 +64,7 @@ func newRoute53(m map[string]string, metadata json.RawMessage) (*route53Provider var dls *string if val, ok := m["DelegationSet"]; ok { - fmt.Printf("ROUTE53 DelegationSet %s configured\n", val) + printer.Printf("ROUTE53 DelegationSet %s configured\n", val) dls = aws.String(val) } api := &route53Provider{client: r53.NewFromConfig(config), registrar: r53d.NewFromConfig(config), delegationSet: dls} @@ -111,7 +112,7 @@ func withRetry(f func() error) { if currentRetry >= maxRetries { return } - fmt.Printf("============ Route53 rate limit exceeded. Waiting %s to retry.\n", sleepTime) + printer.Printf("============ Route53 rate limit exceeded. Waiting %s to retry.\n", sleepTime) time.Sleep(sleepTime) } else { return @@ -673,9 +674,9 @@ func (r *route53Provider) EnsureDomainExists(domain string) error { return nil } if r.delegationSet != nil { - fmt.Printf("Adding zone for %s to route 53 account with delegationSet %s\n", domain, *r.delegationSet) + printer.Printf("Adding zone for %s to route 53 account with delegationSet %s\n", domain, *r.delegationSet) } else { - fmt.Printf("Adding zone for %s to route 53 account\n", domain) + printer.Printf("Adding zone for %s to route 53 account\n", domain) } in := &r53.CreateHostedZoneInput{ Name: &domain, diff --git a/providers/softlayer/softlayerProvider.go b/providers/softlayer/softlayerProvider.go index ec237476c..26c0c2748 100644 --- a/providers/softlayer/softlayerProvider.go +++ b/providers/softlayer/softlayerProvider.go @@ -3,6 +3,7 @@ package softlayer import ( "encoding/json" "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/printer" "regexp" "strings" @@ -35,7 +36,7 @@ func init() { } func newReg(conf map[string]string, _ json.RawMessage) (providers.DNSServiceProvider, error) { - fmt.Println("WARNING: THe SOFTLAYER provider is unmaintained: https://github.com/StackExchange/dnscontrol/issues/1079") + printer.Warnf("The SOFTLAYER provider is unmaintained: https://github.com/StackExchange/dnscontrol/issues/1079") s := session.New(conf["username"], conf["api_key"], conf["endpoint_url"], conf["timeout"]) if len(s.UserName) == 0 || len(s.APIKey) == 0 { @@ -380,7 +381,7 @@ func (s *softlayerProvider) updateRecordFunc(existing *datatypes.Dns_Domain_Reso func verifyMinTTL(ttl int) int { const minTTL = 60 if ttl < minTTL { - fmt.Printf("\nMODIFY TTL to Min supported TTL value: (ttl=%d) -> (ttl=%d)\n", ttl, minTTL) + printer.Printf("\nMODIFY TTL to Min supported TTL value: (ttl=%d) -> (ttl=%d)\n", ttl, minTTL) return minTTL } return ttl