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

Revert "CLEANUP: Fix many golint/staticcheck issues"

This reverts commit de64f90c51.
This commit is contained in:
Tom Limoncelli
2022-01-25 10:35:21 -05:00
parent de64f90c51
commit 360a6266c5
13 changed files with 46 additions and 43 deletions

View File

@ -452,7 +452,6 @@ func (recs Records) FQDNMap() (m map[string]bool) {
return m return m
} }
// GetByType returns the records that match rtype typeName.
func (recs Records) GetByType(typeName string) Records { func (recs Records) GetByType(typeName string) Records {
results := Records{} results := Records{}
for _, rec := range recs { for _, rec := range recs {

View File

@ -181,7 +181,6 @@ func getCertInfo(pemBytes []byte) (names []string, remaining float64, err error)
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
} }
// FIXME(tlim): should use time.Until instead of t.Sub(time.Now()) (S1024)
var daysLeft = float64(cert.NotAfter.Sub(time.Now())) / float64(time.Hour*24) var daysLeft = float64(cert.NotAfter.Sub(time.Now())) / float64(time.Hour*24)
return cert.DNSNames, daysLeft, nil return cert.DNSNames, daysLeft, nil
} }

View File

@ -1,7 +1,7 @@
package js package js
import ( import (
_ "embed" // Used to embed helpers.js in the binary. _ "embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"

View File

@ -497,14 +497,14 @@ func processSplitHorizonDomains(config *models.DNSConfig) error {
return nil return nil
} }
//// parseDomainSpec parses "domain.tld!tag" into its component parts. // parseDomainSpec parses "domain.tld!tag" into its component parts.
//func parseDomainSpec(s string) (domain, tag string) { func parseDomainSpec(s string) (domain, tag string) {
// l := strings.SplitN(s, "!", 2) l := strings.SplitN(s, "!", 2)
// if len(l) == 2 { if len(l) == 2 {
// return l[0], l[1] return l[0], l[1]
// } }
// return l[0], "" return l[0], ""
//} }
func checkAutoDNSSEC(dc *models.DomainConfig) (errs []error) { func checkAutoDNSSEC(dc *models.DomainConfig) (errs []error) {
if dc.AutoDNSSEC != "" && dc.AutoDNSSEC != "on" && dc.AutoDNSSEC != "off" { if dc.AutoDNSSEC != "" && dc.AutoDNSSEC != "on" && dc.AutoDNSSEC != "off" {

View File

@ -601,32 +601,32 @@ func (c cfTarget) FQDN() string {
return strings.TrimRight(string(c), ".") + "." return strings.TrimRight(string(c), ".") + "."
} }
func (c *cloudflareProvider) nativeToRecord(domain string, cr cloudflare.DNSRecord) (*models.RecordConfig, error) { func (cfp *cloudflareProvider) nativeToRecord(domain string, c cloudflare.DNSRecord) (*models.RecordConfig, error) {
// normalize cname,mx,ns records with dots to be consistent with our config format. // normalize cname,mx,ns records with dots to be consistent with our config format.
if cr.Type == "CNAME" || cr.Type == "MX" || cr.Type == "NS" { if c.Type == "CNAME" || c.Type == "MX" || c.Type == "NS" {
if cr.Content != "." { if c.Content != "." {
cr.Content = cr.Content + "." c.Content = c.Content + "."
} }
} }
rc := &models.RecordConfig{ rc := &models.RecordConfig{
TTL: uint32(cr.TTL), TTL: uint32(c.TTL),
Original: cr, Original: c,
} }
rc.SetLabelFromFQDN(cr.Name, domain) rc.SetLabelFromFQDN(c.Name, domain)
// workaround for https://github.com/StackExchange/dnscontrol/issues/446 // workaround for https://github.com/StackExchange/dnscontrol/issues/446
if cr.Type == "SPF" { if c.Type == "SPF" {
cr.Type = "TXT" c.Type = "TXT"
} }
switch rType := cr.Type; rType { // #rtype_variations switch rType := c.Type; rType { // #rtype_variations
case "MX": case "MX":
if err := rc.SetTargetMX(*cr.Priority, cr.Content); err != nil { if err := rc.SetTargetMX(*c.Priority, c.Content); err != nil {
return nil, fmt.Errorf("unparsable MX record received from cloudflare: %w", err) return nil, fmt.Errorf("unparsable MX record received from cloudflare: %w", err)
} }
case "SRV": case "SRV":
data := cr.Data.(map[string]interface{}) data := c.Data.(map[string]interface{})
target := data["target"].(string) target := data["target"].(string)
if target != "." { if target != "." {
target += "." target += "."
@ -636,7 +636,7 @@ func (c *cloudflareProvider) nativeToRecord(domain string, cr cloudflare.DNSReco
return nil, fmt.Errorf("unparsable SRV record received from cloudflare: %w", err) return nil, fmt.Errorf("unparsable SRV record received from cloudflare: %w", err)
} }
default: // "A", "AAAA", "ANAME", "CAA", "CNAME", "NS", "PTR", "TXT" default: // "A", "AAAA", "ANAME", "CAA", "CNAME", "NS", "PTR", "TXT"
if err := rc.PopulateFromString(rType, cr.Content, domain); err != nil { if err := rc.PopulateFromString(rType, c.Content, domain); err != nil {
return nil, fmt.Errorf("unparsable record received from cloudflare: %w", err) return nil, fmt.Errorf("unparsable record received from cloudflare: %w", err)
} }
} }
@ -670,7 +670,7 @@ func (c *cloudflareProvider) EnsureDomainExists(domain string) error {
return err return err
} }
// PrepareCloudflareTestWorkers creates Cloudflare Workers required for CF_WORKER_ROUTE tests. // PrepareCloudflareWorkers creates Cloudflare Workers required for CF_WORKER_ROUTE tests.
func PrepareCloudflareTestWorkers(prv providers.DNSServiceProvider) error { func PrepareCloudflareTestWorkers(prv providers.DNSServiceProvider) error {
cf, ok := prv.(*cloudflareProvider) cf, ok := prv.(*cloudflareProvider)
if ok { if ok {

View File

@ -64,7 +64,9 @@ func (c *cscglobalProvider) getNameservers(domain string) ([]string, error) {
var dr domainRecord var dr domainRecord
json.Unmarshal(bodyString, &dr) json.Unmarshal(bodyString, &dr)
ns := []string{} ns := []string{}
ns = append(ns, dr.Nameserver...) for _, nameserver := range dr.Nameserver {
ns = append(ns, nameserver)
}
sort.Strings(ns) sort.Strings(ns)
return ns, nil return ns, nil
} }

View File

@ -51,7 +51,7 @@ func (c *cscglobalProvider) GetRegistrarCorrections(dc *models.DomainConfig) ([]
if ns.Name[len(ns.Name)-1] == '.' { if ns.Name[len(ns.Name)-1] == '.' {
// When this code was written ns.Name never included a single trailing dot. // When this code was written ns.Name never included a single trailing dot.
// If that changes, the code should change too. // If that changes, the code should change too.
return nil, fmt.Errorf("name server includes a trailing dot, has the API changed?") return nil, fmt.Errorf("Name server includes a trailing dot, has the API changed?")
} }
expected = append(expected, ns.Name) expected = append(expected, ns.Name)
} }

View File

@ -38,7 +38,7 @@ type easynameDomainList struct {
} }
type easynameDomain struct { type easynameDomain struct {
ID int `json:"id"` Id int `json:"id"`
Domain string `json:"domain"` Domain string `json:"domain"`
NameServer1 string `json:"nameserver1"` NameServer1 string `json:"nameserver1"`
NameServer2 string `json:"nameserver2"` NameServer2 string `json:"nameserver2"`

View File

@ -62,7 +62,7 @@ func (c *easynameProvider) GetRegistrarCorrections(dc *models.DomainConfig) ([]*
{ {
Msg: fmt.Sprintf("Update nameservers %s -> %s", foundNameservers, expectedNameservers), Msg: fmt.Sprintf("Update nameservers %s -> %s", foundNameservers, expectedNameservers),
F: func() error { F: func() error {
return c.updateNameservers(expected, domain.ID) return c.updateNameservers(expected, domain.Id)
}, },
}, },
}, nil }, nil

View File

@ -21,9 +21,6 @@ func (n *HXClient) EnsureDomainExists(domain string) error {
} }
} else if code == 531 { } else if code == 531 {
return n.GetHXApiError("Not authorized to manage dnszone", domain, r) return n.GetHXApiError("Not authorized to manage dnszone", domain, r)
// FIXME(tlim) go-staticcheck reports:
// identical expressions on the left and right side of the '||' operator (SA4000)
// Perhaps the right side should be n.IsError() or deleted?
} else if r.IsError() || r.IsError() { } else if r.IsError() || r.IsError() {
return n.GetHXApiError("Error while checking status of dnszone", domain, r) return n.GetHXApiError("Error while checking status of dnszone", domain, r)
} }

View File

@ -13,6 +13,13 @@ import (
opensrs "github.com/philhug/opensrs-go/opensrs" opensrs "github.com/philhug/opensrs-go/opensrs"
) )
var docNotes = providers.DocumentationNotes{
providers.DocCreateDomains: providers.Cannot(),
providers.DocOfficiallySupported: providers.Cannot(),
providers.CanUseTLSA: providers.Cannot(),
providers.CanGetZones: providers.Unimplemented(),
}
func init() { func init() {
providers.RegisterRegistrarType("OPENSRS", newReg) providers.RegisterRegistrarType("OPENSRS", newReg)
} }

View File

@ -29,7 +29,7 @@ type route53Provider struct {
client *r53.Client client *r53.Client
registrar *r53d.Client registrar *r53d.Client
delegationSet *string delegationSet *string
zonesByID map[string]r53Types.HostedZone zonesById map[string]r53Types.HostedZone
zonesByDomain map[string]r53Types.HostedZone zonesByDomain map[string]r53Types.HostedZone
originalRecords []r53Types.ResourceRecordSet originalRecords []r53Types.ResourceRecordSet
} }
@ -132,7 +132,7 @@ func (r *route53Provider) ListZones() ([]string, error) {
func (r *route53Provider) getZones() error { func (r *route53Provider) getZones() error {
var nextMarker *string var nextMarker *string
r.zonesByDomain = make(map[string]r53Types.HostedZone) r.zonesByDomain = make(map[string]r53Types.HostedZone)
r.zonesByID = make(map[string]r53Types.HostedZone) r.zonesById = make(map[string]r53Types.HostedZone)
for { for {
var out *r53.ListHostedZonesOutput var out *r53.ListHostedZonesOutput
var err error var err error
@ -149,7 +149,7 @@ func (r *route53Provider) getZones() error {
for _, z := range out.HostedZones { for _, z := range out.HostedZones {
domain := strings.TrimSuffix(aws.ToString(z.Name), ".") domain := strings.TrimSuffix(aws.ToString(z.Name), ".")
r.zonesByDomain[domain] = z r.zonesByDomain[domain] = z
r.zonesByID[parseZoneID(aws.ToString(z.Id))] = z r.zonesById[parseZoneId(aws.ToString(z.Id))] = z
} }
if out.NextMarker != nil { if out.NextMarker != nil {
nextMarker = out.NextMarker nextMarker = out.NextMarker
@ -165,7 +165,7 @@ type errDomainNoExist struct {
} }
type errZoneNoExist struct { type errZoneNoExist struct {
zoneID string zoneId string
} }
func (e errDomainNoExist) Error() string { func (e errDomainNoExist) Error() string {
@ -173,7 +173,7 @@ func (e errDomainNoExist) Error() string {
} }
func (e errZoneNoExist) Error() string { func (e errZoneNoExist) Error() string {
return fmt.Sprintf("Zone with id %s not found in your route 53 account", e.zoneID) return fmt.Sprintf("Zone with id %s not found in your route 53 account", e.zoneId)
} }
func (r *route53Provider) GetNameservers(domain string) ([]*models.Nameserver, error) { func (r *route53Provider) GetNameservers(domain string) ([]*models.Nameserver, error) {
@ -208,10 +208,10 @@ func (r *route53Provider) GetZoneRecords(domain string) (models.Records, error)
} }
func (r *route53Provider) getZone(dc *models.DomainConfig) (r53Types.HostedZone, error) { func (r *route53Provider) getZone(dc *models.DomainConfig) (r53Types.HostedZone, error) {
if zoneID, ok := dc.Metadata["zone_id"]; ok { if zoneId, ok := dc.Metadata["zone_id"]; ok {
zone, ok := r.zonesByID[zoneID] zone, ok := r.zonesById[zoneId]
if !ok { if !ok {
return r53Types.HostedZone{}, errZoneNoExist{zoneID} return r53Types.HostedZone{}, errZoneNoExist{zoneId}
} }
return zone, nil return zone, nil
} }
@ -516,11 +516,11 @@ func getZoneID(zone r53Types.HostedZone, r *models.RecordConfig) string {
if zoneID == "" { if zoneID == "" {
zoneID = aws.ToString(zone.Id) zoneID = aws.ToString(zone.Id)
} }
return parseZoneID(zoneID) return parseZoneId(zoneID)
} }
/** Removes "/hostedzone/"" prefix from AWS ZoneId */ /** Removes "/hostedzone/"" prefix from AWS ZoneId */
func parseZoneID(zoneID string) string { func parseZoneId(zoneID string) string {
return strings.TrimPrefix(zoneID, "/hostedzone/") return strings.TrimPrefix(zoneID, "/hostedzone/")
} }

View File

@ -42,7 +42,6 @@ var features = providers.DocumentationNotes{
providers.DocOfficiallySupported: providers.Cannot(), providers.DocOfficiallySupported: providers.Cannot(),
} }
// NewTransip creates a new TransIP provider.
func NewTransip(m map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) { func NewTransip(m map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) {
if m["AccessToken"] == "" && m["PrivateKey"] == "" { if m["AccessToken"] == "" && m["PrivateKey"] == "" {