CLEANUP: Fix many golint/staticcheck issues

This commit is contained in:
Tom Limoncelli 2022-01-25 10:33:48 -05:00
parent 1b83c219c5
commit de64f90c51
13 changed files with 43 additions and 46 deletions

View file

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

View file

@ -181,6 +181,7 @@ func getCertInfo(pemBytes []byte) (names []string, remaining float64, err error)
if err != nil {
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)
return cert.DNSNames, daysLeft, nil
}

View file

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

View file

@ -497,14 +497,14 @@ func processSplitHorizonDomains(config *models.DNSConfig) error {
return nil
}
// parseDomainSpec parses "domain.tld!tag" into its component parts.
func parseDomainSpec(s string) (domain, tag string) {
l := strings.SplitN(s, "!", 2)
if len(l) == 2 {
return l[0], l[1]
}
return l[0], ""
}
//// parseDomainSpec parses "domain.tld!tag" into its component parts.
//func parseDomainSpec(s string) (domain, tag string) {
// l := strings.SplitN(s, "!", 2)
// if len(l) == 2 {
// return l[0], l[1]
// }
// return l[0], ""
//}
func checkAutoDNSSEC(dc *models.DomainConfig) (errs []error) {
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), ".") + "."
}
func (cfp *cloudflareProvider) nativeToRecord(domain string, c cloudflare.DNSRecord) (*models.RecordConfig, error) {
func (c *cloudflareProvider) nativeToRecord(domain string, cr cloudflare.DNSRecord) (*models.RecordConfig, error) {
// normalize cname,mx,ns records with dots to be consistent with our config format.
if c.Type == "CNAME" || c.Type == "MX" || c.Type == "NS" {
if c.Content != "." {
c.Content = c.Content + "."
if cr.Type == "CNAME" || cr.Type == "MX" || cr.Type == "NS" {
if cr.Content != "." {
cr.Content = cr.Content + "."
}
}
rc := &models.RecordConfig{
TTL: uint32(c.TTL),
Original: c,
TTL: uint32(cr.TTL),
Original: cr,
}
rc.SetLabelFromFQDN(c.Name, domain)
rc.SetLabelFromFQDN(cr.Name, domain)
// workaround for https://github.com/StackExchange/dnscontrol/issues/446
if c.Type == "SPF" {
c.Type = "TXT"
if cr.Type == "SPF" {
cr.Type = "TXT"
}
switch rType := c.Type; rType { // #rtype_variations
switch rType := cr.Type; rType { // #rtype_variations
case "MX":
if err := rc.SetTargetMX(*c.Priority, c.Content); err != nil {
if err := rc.SetTargetMX(*cr.Priority, cr.Content); err != nil {
return nil, fmt.Errorf("unparsable MX record received from cloudflare: %w", err)
}
case "SRV":
data := c.Data.(map[string]interface{})
data := cr.Data.(map[string]interface{})
target := data["target"].(string)
if target != "." {
target += "."
@ -636,7 +636,7 @@ func (cfp *cloudflareProvider) nativeToRecord(domain string, c cloudflare.DNSRec
return nil, fmt.Errorf("unparsable SRV record received from cloudflare: %w", err)
}
default: // "A", "AAAA", "ANAME", "CAA", "CNAME", "NS", "PTR", "TXT"
if err := rc.PopulateFromString(rType, c.Content, domain); err != nil {
if err := rc.PopulateFromString(rType, cr.Content, domain); err != nil {
return nil, fmt.Errorf("unparsable record received from cloudflare: %w", err)
}
}
@ -670,7 +670,7 @@ func (c *cloudflareProvider) EnsureDomainExists(domain string) error {
return err
}
// PrepareCloudflareWorkers creates Cloudflare Workers required for CF_WORKER_ROUTE tests.
// PrepareCloudflareTestWorkers creates Cloudflare Workers required for CF_WORKER_ROUTE tests.
func PrepareCloudflareTestWorkers(prv providers.DNSServiceProvider) error {
cf, ok := prv.(*cloudflareProvider)
if ok {

View file

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

View file

@ -51,7 +51,7 @@ func (c *cscglobalProvider) GetRegistrarCorrections(dc *models.DomainConfig) ([]
if ns.Name[len(ns.Name)-1] == '.' {
// When this code was written ns.Name never included a single trailing dot.
// 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)
}

View file

@ -38,7 +38,7 @@ type easynameDomainList struct {
}
type easynameDomain struct {
Id int `json:"id"`
ID int `json:"id"`
Domain string `json:"domain"`
NameServer1 string `json:"nameserver1"`
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),
F: func() error {
return c.updateNameservers(expected, domain.Id)
return c.updateNameservers(expected, domain.ID)
},
},
}, nil

View file

@ -21,6 +21,9 @@ func (n *HXClient) EnsureDomainExists(domain string) error {
}
} else if code == 531 {
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() {
return n.GetHXApiError("Error while checking status of dnszone", domain, r)
}

View file

@ -13,13 +13,6 @@ import (
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() {
providers.RegisterRegistrarType("OPENSRS", newReg)
}

View file

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

View file

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