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

Cleanups: Fix many issues reported by staticcheck.io (#837)

* Lint: Fix ST1005: error strings should not be capitalized

* Cleanup: Fix a lot of staticcheck.io warnings
This commit is contained in:
Tom Limoncelli
2020-08-30 20:38:08 -04:00
committed by GitHub
parent cb9a82717b
commit b6fd4dffd7
17 changed files with 19 additions and 37 deletions

View File

@ -229,9 +229,8 @@ func GetZone(args GetZoneArgs) error {
case "tsv":
for _, rec := range recs {
fmt.Fprintf(w,
fmt.Sprintf("%s\t%s\t%d\tIN\t%s\t%s\n",
rec.NameFQDN, rec.Name, rec.TTL, rec.Type, rec.GetTargetCombined()))
fmt.Fprintf(w, "%s\t%s\t%d\tIN\t%s\t%s\n",
rec.NameFQDN, rec.Name, rec.TTL, rec.Type, rec.GetTargetCombined())
}
default:

View File

@ -65,7 +65,7 @@ func TestDNSProviders(t *testing.T) {
if provider == nil {
return
}
t.Run(fmt.Sprintf("%s", domain), func(t *testing.T) {
t.Run(domain, func(t *testing.T) {
runTests(t, provider, domain, fails, cfg)
})

View File

@ -45,8 +45,7 @@ func (rc *RecordConfig) String() string {
func RRstoRCs(rrs []dns.RR, origin string) Records {
rcs := make(Records, 0, len(rrs))
for _, r := range rrs {
var rc RecordConfig
rc = RRtoRC(r, origin)
rc := RRtoRC(r, origin)
rcs = append(rcs, &rc)
}
return rcs

View File

@ -414,5 +414,4 @@ func downcase(recs []*RecordConfig) {
// TODO: we'd like to panic here, but custom record types complicate things.
}
}
return
}

View File

@ -317,15 +317,15 @@ func ValidateAndNormalizeConfig(config *models.DNSConfig) (errs []error) {
errs = append(errs, fmt.Errorf("CAA tag %s is invalid", rec.CaaTag))
}
} else if rec.Type == "TLSA" {
if rec.TlsaUsage < 0 || rec.TlsaUsage > 3 {
if rec.TlsaUsage > 3 {
errs = append(errs, fmt.Errorf("TLSA Usage %d is invalid in record %s (domain %s)",
rec.TlsaUsage, rec.GetLabel(), domain.Name))
}
if rec.TlsaSelector < 0 || rec.TlsaSelector > 1 {
if rec.TlsaSelector > 1 {
errs = append(errs, fmt.Errorf("TLSA Selector %d is invalid in record %s (domain %s)",
rec.TlsaSelector, rec.GetLabel(), domain.Name))
}
if rec.TlsaMatchingType < 0 || rec.TlsaMatchingType > 2 {
if rec.TlsaMatchingType > 2 {
errs = append(errs, fmt.Errorf("TLSA MatchingType %d is invalid in record %s (domain %s)",
rec.TlsaMatchingType, rec.GetLabel(), domain.Name))
}

View File

@ -84,9 +84,7 @@ func PrettySort(records models.Records, origin string, defaultTTL uint32, commen
z.DefaultTTL = 300
}
z.Records = nil
for _, r := range records {
z.Records = append(z.Records, r)
}
z.Records = append(z.Records, records...)
return z
}

View File

@ -118,9 +118,7 @@ func (s *SPFRecord) Flatten(spec string) *SPFRecord {
// flatten child recursively
flattenedChild := p.IncludeRecord.Flatten(spec)
// include their parts (skipping final all term)
for _, childPart := range flattenedChild.Parts[:len(flattenedChild.Parts)-1] {
newRec.Parts = append(newRec.Parts, childPart)
}
newRec.Parts = append(newRec.Parts, flattenedChild.Parts[:len(flattenedChild.Parts)-1]...)
}
}
return newRec

View File

@ -311,7 +311,7 @@ func (c *adProvider) generatePowerShellModify(domainname, recName, recType, oldC
text += "Set-DnsServerResourceRecord"
text += fmt.Sprintf(` -ComputerName "%s"`, c.adServer)
text += fmt.Sprintf(` -ZoneName "%s"`, domainname)
text += fmt.Sprintf(` -NewInputObject $NewObj -OldInputObject $OldObj`)
text += ` -NewInputObject $NewObj -OldInputObject $OldObj`
text += "\r\n"
return text

View File

@ -173,8 +173,7 @@ func (a *azureDNSProvider) getExistingRecords(domain string) (models.Records, []
if !ok {
return nil, nil, "", errNoExist{domain}
}
var zoneName string
zoneName = *zone.Name
zoneName := *zone.Name
records, err := a.fetchRecordSets(zoneName)
if err != nil {
return nil, nil, "", err

View File

@ -157,6 +157,7 @@ func (c *Bind) GetZoneRecords(domain string) (models.Records, error) {
for rr, ok := zp.Next(); ok; rr, ok = zp.Next() {
rec := models.RRtoRC(rr, domain)
// FIXME(tlim): Empty branch? Is the intention to skip SOAs?
if rec.Type == "SOA" {
}
foundRecords = append(foundRecords, &rec)

View File

@ -447,9 +447,7 @@ func newCloudflare(m map[string]string, metadata json.RawMessage) (providers.DNS
}
api.manageRedirects = parsedMeta.ManageRedirects
// ignored_labels:
for _, l := range parsedMeta.IgnoredLabels {
api.ignoredLabels = append(api.ignoredLabels, l)
}
api.ignoredLabels = append(api.ignoredLabels, parsedMeta.IgnoredLabels...)
if len(api.ignoredLabels) > 0 {
printer.Warnf("Cloudflare 'ignored_labels' configuration is deprecated and might be removed. Please use the IGNORE domain directive to achieve the same effect.\n")
}

View File

@ -38,9 +38,7 @@ func (c *CloudflareAPI) fetchDomainList() error {
}
for _, zone := range zr.Result {
c.domainIndex[zone.Name] = zone.ID
for _, ns := range zone.Nameservers {
c.nameservers[zone.Name] = append(c.nameservers[zone.Name], ns)
}
c.nameservers[zone.Name] = append(c.nameservers[zone.Name], zone.Nameservers...)
}
ri := zr.ResultInfo
if len(zr.Result) == 0 || ri.Page*ri.PerPage >= ri.TotalCount {

View File

@ -204,8 +204,7 @@ func (c *api) GenerateDomainCorrections(dc *models.DomainConfig, existing models
}
}
}
var msg string
msg = fmt.Sprintf("Changes:\n%s", buf)
msg := fmt.Sprintf("Changes:\n%s", buf)
corrections = append(corrections,
&models.Correction{
Msg: msg,

View File

@ -186,9 +186,7 @@ func getRecords(api *DoAPI, name string) ([]godo.DomainRecord, error) {
return nil, err
}
for _, d := range result {
records = append(records, d)
}
records = append(records, result...)
if resp.Links == nil || resp.Links.IsLastPage() {
break

View File

@ -36,9 +36,7 @@ func (c *api) 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...)
return ns, nil
}

View File

@ -9,7 +9,7 @@ func (c *NameCom) ListZones() ([]string, error) {
var names []string
var page int32
for true {
for {
n, err := c.client.ListDomains(&namecom.ListDomainsRequest{Page: page})
if err != nil {
return nil, err

View File

@ -23,9 +23,7 @@ func WriteYaml(w io.Writer, records models.Records, origin string) error {
// Make a copy of the records, since we want to sort and muck with them.
recsCopy := models.Records{}
for _, r := range records {
recsCopy = append(recsCopy, r)
}
recsCopy = append(recsCopy, records...)
for _, r := range recsCopy {
if r.GetLabel() == "@" {
//r.Name = ""