Skip to content

Commit

Permalink
CHORE: Linting corrections (#3236)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlimoncelli authored Dec 12, 2024
1 parent 9588a91 commit 9df5a25
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 42 deletions.
27 changes: 14 additions & 13 deletions pkg/normalize/validate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package normalize

import (
"errors"
"fmt"
"net"
"sort"
Expand Down Expand Up @@ -118,7 +119,7 @@ func checkLabel(label string, rType string, domain string, meta map[string]strin
}
if label == domain || strings.HasSuffix(label, "."+domain) {
if m := meta["skip_fqdn_check"]; m != "true" {
return fmt.Errorf("%s", errorRepeat(label, domain))
return errors.New(errorRepeat(label, domain))
}
}

Expand Down Expand Up @@ -147,22 +148,22 @@ func checkLabel(label string, rType string, domain string, meta map[string]strin

func checkSoa(expire uint32, minttl uint32, refresh uint32, retry uint32, mbox string) error {
if expire <= 0 {
return fmt.Errorf("SOA Expire must be > 0")
return errors.New("SOA Expire must be > 0")
}
if minttl <= 0 {
return fmt.Errorf("SOA Minimum TTL must be > 0")
return errors.New("SOA Minimum TTL must be > 0")
}
if refresh <= 0 {
return fmt.Errorf("SOA Refresh must be > 0")
return errors.New("SOA Refresh must be > 0")
}
if retry <= 0 {
return fmt.Errorf("SOA Retry must be > 0")
return errors.New("SOA Retry must be > 0")
}
if mbox == "" {
return fmt.Errorf("SOA MBox must be specified")
return errors.New("SOA MBox must be specified")
}
if strings.ContainsRune(mbox, '@') {
return fmt.Errorf("SOA MBox must have '.' instead of '@'")
return errors.New("SOA MBox must have '.' instead of '@'")
}
return nil
}
Expand Down Expand Up @@ -190,12 +191,12 @@ func checkTargets(rec *models.RecordConfig, domain string) (errs []error) {
case "CNAME":
check(checkTarget(target))
if label == "@" {
check(fmt.Errorf("cannot create CNAME record for bare domain"))
check(errors.New("cannot create CNAME record for bare domain"))
}
labelFQDN := dnsutil.AddOrigin(label, domain)
targetFQDN := dnsutil.AddOrigin(target, domain)
if labelFQDN == targetFQDN {
check(fmt.Errorf("CNAME loop (target points at itself)"))
check(errors.New("CNAME loop (target points at itself)"))
}
case "DNAME":
check(checkTarget(target))
Expand All @@ -209,19 +210,19 @@ func checkTargets(rec *models.RecordConfig, domain string) (errs []error) {
case "NS":
check(checkTarget(target))
if label == "@" {
check(fmt.Errorf("cannot create NS record for bare domain. Use NAMESERVER instead"))
check(errors.New("cannot create NS record for bare domain. Use NAMESERVER instead"))
}
case "NS1_URLFWD":
if len(strings.Fields(target)) != 5 {
check(fmt.Errorf("record should follow format: \"from to redirectType pathForwardingMode queryForwarding\""))
check(errors.New("record should follow format: \"from to redirectType pathForwardingMode queryForwarding\""))
}
case "PTR":
check(checkTarget(target))
case "SOA":
check(checkSoa(rec.SoaExpire, rec.SoaMinttl, rec.SoaRefresh, rec.SoaRetry, rec.SoaMbox))
check(checkTarget(target))
if label != "@" {
check(fmt.Errorf("SOA record is only valid for bare domain"))
check(errors.New("SOA record is only valid for bare domain"))
}
case "SRV":
check(checkTarget(target))
Expand Down Expand Up @@ -457,7 +458,7 @@ func ValidateAndNormalizeConfig(config *models.DNSConfig) (errs []error) {
rec.SetLabel(rec.GetLabel(), domain.Name)

if _, ok := rec.Metadata["ignore_name_disable_safety_check"]; ok {
errs = append(errs, fmt.Errorf("IGNORE_NAME_DISABLE_SAFETY_CHECK no longer supported. Please use DISABLE_IGNORE_SAFETY_CHECK for the entire domain"))
errs = append(errs, errors.New("IGNORE_NAME_DISABLE_SAFETY_CHECK no longer supported. Please use DISABLE_IGNORE_SAFETY_CHECK for the entire domain"))
}

}
Expand Down
3 changes: 2 additions & 1 deletion providers/autodns/autoDnsProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package autodns

import (
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -98,7 +99,7 @@ func (api *autoDNSProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, e

err := api.updateZone(domain, resourceRecords, nameServers, zoneTTL)
if err != nil {
return fmt.Errorf("%s", err.Error())
return errors.New(err.Error())
}

return nil
Expand Down
3 changes: 2 additions & 1 deletion providers/cnr/cnrProvider.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Package CNR implements a registrar that uses the CNR api to set name servers. It will self register it's providers when imported.
package cnr

// Package CNR implements a registrar that uses the CNR api to set name servers. It will self register it's providers when imported.

import (
"encoding/json"
"fmt"
Expand Down
29 changes: 15 additions & 14 deletions providers/desec/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package desec
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -114,11 +115,11 @@ func (c *desecProvider) fetchDomainIndex() (map[string]uint32, error) {
for endpoint != "" {
bodyString, resp, err = c.get(endpoint, "GET")
if err != nil {
return nil, fmt.Errorf("failed fetching domains: %s", err)
return nil, fmt.Errorf("failed fetching domains: %w", err)
}
domainIndex, err = appendDomainIndexFromResponse(domainIndex, bodyString)
if err != nil {
return nil, fmt.Errorf("failed fetching domains: %s", err)
return nil, fmt.Errorf("failed fetching domains: %w", err)
}
links = convertLinks(resp.Header.Get("Link"))
endpoint = links["next"]
Expand All @@ -130,7 +131,7 @@ func (c *desecProvider) fetchDomainIndex() (map[string]uint32, error) {

//no pagination required
if err != nil && resp.StatusCode != 400 {
return nil, fmt.Errorf("failed fetching domains: %s", err)
return nil, fmt.Errorf("failed fetching domains: %w", err)
}
domainIndex, err = appendDomainIndexFromResponse(domainIndex, bodyString)
if err != nil {
Expand Down Expand Up @@ -196,11 +197,11 @@ func (c *desecProvider) getRecords(domain string) ([]resourceRecord, error) {
if resp.StatusCode == 404 {
return rrsNew, nil
}
return rrsNew, fmt.Errorf("getRecords: failed fetching rrsets: %s", err)
return rrsNew, fmt.Errorf("getRecords: failed fetching rrsets: %w", err)
}
tmp, err := generateRRSETfromResponse(bodyString)
if err != nil {
return rrsNew, fmt.Errorf("failed fetching records for domain %s (deSEC): %s", domain, err)
return rrsNew, fmt.Errorf("failed fetching records for domain %s (deSEC): %w", domain, err)
}
rrsNew = append(rrsNew, tmp...)
links = convertLinks(resp.Header.Get("Link"))
Expand All @@ -212,7 +213,7 @@ func (c *desecProvider) getRecords(domain string) ([]resourceRecord, error) {
}
//no pagination
if err != nil {
return rrsNew, fmt.Errorf("failed fetching records for domain %s (deSEC): %s", domain, err)
return rrsNew, fmt.Errorf("failed fetching records for domain %s (deSEC): %w", domain, err)
}
tmp, err := generateRRSETfromResponse(bodyString)
if err != nil {
Expand Down Expand Up @@ -252,7 +253,7 @@ func (c *desecProvider) createDomain(domain string) error {
var resp []byte
var err error
if resp, err = c.post(endpoint, "POST", byt); err != nil {
return fmt.Errorf("failed domain create (deSEC): %v", err)
return fmt.Errorf("failed domain create (deSEC): %w", err)
}
dm := domainObject{}
err = json.Unmarshal(resp, &dm)
Expand All @@ -269,7 +270,7 @@ func (c *desecProvider) upsertRR(rr []resourceRecord, domain string) error {
endpoint := fmt.Sprintf("/domains/%s/rrsets/", domain)
byt, _ := json.Marshal(rr)
if _, err := c.post(endpoint, "PUT", byt); err != nil {
return fmt.Errorf("failed create RRset (deSEC): %v", err)
return fmt.Errorf("failed create RRset (deSEC): %w", err)
}
return nil
}
Expand All @@ -279,7 +280,7 @@ func (c *desecProvider) upsertRR(rr []resourceRecord, domain string) error {
//func (c *desecProvider) deleteRR(domain, shortname, t string) error {
// endpoint := fmt.Sprintf("/domains/%s/rrsets/%s/%s/", domain, shortname, t)
// if _, _, err := c.get(endpoint, "DELETE"); err != nil {
// return fmt.Errorf("failed delete RRset (deSEC): %v", err)
// return fmt.Errorf("failed delete RRset (deSEC): %w", err)
// }
// return nil
//}
Expand Down Expand Up @@ -316,7 +317,7 @@ retry:
wait, err := strconv.ParseInt(waitfor, 10, 64)
if err == nil {
if wait > 180 {
return []byte{}, resp, fmt.Errorf("rate limiting exceeded")
return []byte{}, resp, errors.New("rate limiting exceeded")
}
printer.Warnf("Rate limiting.. waiting for %s seconds\n", waitfor)
time.Sleep(time.Duration(wait+1) * time.Second)
Expand All @@ -331,12 +332,12 @@ retry:
var nfieldErrors []nonFieldError
err = json.Unmarshal(bodyString, &errResp)
if err == nil {
return bodyString, resp, fmt.Errorf("%s", errResp.Detail)
return bodyString, resp, errors.New(errResp.Detail)
}
err = json.Unmarshal(bodyString, &nfieldErrors)
if err == nil && len(nfieldErrors) > 0 {
if len(nfieldErrors[0].Errors) > 0 {
return bodyString, resp, fmt.Errorf("%s", nfieldErrors[0].Errors[0])
return bodyString, resp, errors.New(nfieldErrors[0].Errors[0])
}
}
return bodyString, resp, fmt.Errorf("HTTP status %s Body: %s, the API does not provide more information", resp.Status, bodyString)
Expand Down Expand Up @@ -383,7 +384,7 @@ retry:
wait, err := strconv.ParseInt(waitfor, 10, 64)
if err == nil {
if wait > 180 {
return []byte{}, fmt.Errorf("rate limiting exceeded")
return []byte{}, errors.New("rate limiting exceeded")
}
printer.Warnf("Rate limiting.. waiting for %s seconds\n", waitfor)
time.Sleep(time.Duration(wait+1) * time.Second)
Expand All @@ -403,7 +404,7 @@ retry:
err = json.Unmarshal(bodyString, &nfieldErrors)
if err == nil && len(nfieldErrors) > 0 {
if len(nfieldErrors[0].Errors) > 0 {
return bodyString, fmt.Errorf("%s", nfieldErrors[0].Errors[0])
return bodyString, errors.New(nfieldErrors[0].Errors[0])
}
}
return bodyString, fmt.Errorf("HTTP status %s Body: %s, the API does not provide more information", resp.Status, bodyString)
Expand Down
2 changes: 1 addition & 1 deletion providers/dnsimple/dnsimpleProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ func compileAttributeErrors(err *dnsimpleapi.ErrorResponse) error {
e := strings.Join(errors, "& ")
message += fmt.Sprintf(": %s %s", field, e)
}
return fmt.Errorf("%s", message)
return errors.New(message)
}

// Return true if the string ends in one of DNSimple's name server domains
Expand Down
23 changes: 12 additions & 11 deletions providers/hedns/hednsProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package hedns
import (
"crypto/sha1"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/http/cookiejar"
Expand Down Expand Up @@ -120,13 +121,13 @@ func newHEDNSProvider(cfg map[string]string, _ json.RawMessage) (providers.DNSSe
sessionFilePath := cfg["session-file-path"]

if username == "" {
return nil, fmt.Errorf("username must be provided")
return nil, errors.New("username must be provided")
}
if password == "" {
return nil, fmt.Errorf("password must be provided")
return nil, errors.New("password must be provided")
}
if totpSecret != "" && totpValue != "" {
return nil, fmt.Errorf("totp and totp-key must not be specified at the same time")
return nil, errors.New("totp and totp-key must not be specified at the same time")
}

// Perform the initial login
Expand Down Expand Up @@ -282,7 +283,7 @@ func (c *hednsProvider) GetZoneRecords(domain string, meta map[string]string) (m

// Check we can find the zone records
if document.Find("#dns_main_content").Size() == 0 {
return nil, fmt.Errorf("zone records listing failed")
return nil, errors.New("zone records listing failed")
}

// Load all the domain records
Expand Down Expand Up @@ -383,7 +384,7 @@ func (c *hednsProvider) authUsernameAndPassword() (authenticated bool, requiresT
document, err := c.parseResponseForDocumentAndErrors(response)
if err != nil {
if err.Error() == errorInvalidCredentials {
err = fmt.Errorf("authentication failed with incorrect username or password")
err = errors.New("authentication failed with incorrect username or password")
}
if err.Error() == errorTotpTokenRequired {
return false, true, nil
Expand All @@ -401,7 +402,7 @@ func (c *hednsProvider) authUsernameAndPassword() (authenticated bool, requiresT
func (c *hednsProvider) auth2FA() (authenticated bool, err error) {

if c.TfaValue == "" && c.TfaSecret == "" {
return false, fmt.Errorf("account requires two-factor authentication but neither totp or totp-key were provided")
return false, errors.New("account requires two-factor authentication but neither totp or totp-key were provided")
}

if c.TfaValue == "" && c.TfaSecret != "" {
Expand All @@ -425,9 +426,9 @@ func (c *hednsProvider) auth2FA() (authenticated bool, err error) {
if err != nil {
switch err.Error() {
case errorInvalidTotpToken:
err = fmt.Errorf("invalid TOTP token value")
err = errors.New("invalid TOTP token value")
case errorTotpTokenReused:
err = fmt.Errorf("TOTP token was reused within its period (30 seconds)")
err = errors.New("TOTP token was reused within its period (30 seconds)")
}
return false, err
}
Expand Down Expand Up @@ -466,7 +467,7 @@ func (c *hednsProvider) authenticate() error {
}

if !authenticated {
err = fmt.Errorf("unknown authentication failure")
err = errors.New("unknown authentication failure")
} else {
if c.SessionFilePath != "" {
err = c.saveSessionFile()
Expand Down Expand Up @@ -655,7 +656,7 @@ func (c *hednsProvider) loadSessionFile() error {
for i, entry := range strings.Split(string(bytes), "\n") {
if i == 0 {
if entry != c.generateCredentialHash() {
return fmt.Errorf("invalid credential hash in session file")
return errors.New("invalid credential hash in session file")
}
} else {
kv := strings.Split(entry, "=")
Expand Down Expand Up @@ -690,7 +691,7 @@ func (c *hednsProvider) parseResponseForDocumentAndErrors(response *http.Respons
return true
}
}
err = fmt.Errorf("%s", element.Text())
err = errors.New(element.Text())
return false
})

Expand Down
2 changes: 1 addition & 1 deletion providers/porkbun/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ retry:
bodyString, _ := io.ReadAll(resp.Body)

if resp.StatusCode == 202 || resp.StatusCode == 503 {
retrycnt += 1
retrycnt++
if retrycnt == 5 {
return bodyString, fmt.Errorf("rate limiting exceeded")
}
Expand Down

0 comments on commit 9df5a25

Please sign in to comment.