Skip to content

Commit

Permalink
CHORE: Satisfy Staticcheck and remove unused code (#2331)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemenkov authored May 8, 2023
1 parent f711857 commit 36e3595
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 109 deletions.
6 changes: 3 additions & 3 deletions integrationTest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ func tlsa(name string, usage, selector, matchingtype uint8, target string) *mode
return r
}

func ns1_urlfwd(name, target string) *models.RecordConfig {
func ns1Urlfwd(name, target string) *models.RecordConfig {
return makeRec(name, target, "NS1_URLFWD")
}

Expand Down Expand Up @@ -1700,8 +1700,8 @@ func makeTests(t *testing.T) []*TestGroup {

testgroup("NS1_URLFWD tests",
only("NS1"),
tc("Add a urlfwd", ns1_urlfwd("urlfwd1", "/ http://example.com 302 2 0")),
tc("Update a urlfwd", ns1_urlfwd("urlfwd1", "/ http://example.org 301 2 0")),
tc("Add a urlfwd", ns1Urlfwd("urlfwd1", "/ http://example.com 302 2 0")),
tc("Update a urlfwd", ns1Urlfwd("urlfwd1", "/ http://example.org 301 2 0")),
),

//// IGNORE* features
Expand Down
16 changes: 8 additions & 8 deletions models/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
)

const (
DOMAIN_UNIQUENAME = "dnscontrol_uniquename"
DOMAIN_TAG = "dnscontrol_tag"
DomainUniqueName = "dnscontrol_uniquename"
DomainTag = "dnscontrol_tag"
)

// DomainConfig describes a DNS domain (technically a DNS zone).
Expand All @@ -19,8 +19,8 @@ type DomainConfig struct {
RegistrarName string `json:"registrar"`
DNSProviderNames map[string]int `json:"dnsProviders"`

// Metadata[DOMAIN_UNIQUENAME] // .Name + "!" + .Tag
// Metadata[DOMAIN_TAG] // split horizon tag
// Metadata[DomainUniqueName] // .Name + "!" + .Tag
// Metadata[DomainTag] // split horizon tag
Metadata map[string]string `json:"meta,omitempty"`
Records Records `json:"records"`
Nameservers []*Nameserver `json:"nameservers,omitempty"`
Expand All @@ -46,12 +46,12 @@ type DomainConfig struct {

// GetSplitHorizonNames returns the domain's name, uniquename, and tag.
func (dc *DomainConfig) GetSplitHorizonNames() (name, uniquename, tag string) {
return dc.Name, dc.Metadata[DOMAIN_UNIQUENAME], dc.Metadata[DOMAIN_TAG]
return dc.Name, dc.Metadata[DomainUniqueName], dc.Metadata[DomainTag]
}

// GetUniqueName returns the domain's uniquename.
func (dc *DomainConfig) GetUniqueName() (uniquename string) {
return dc.Metadata[DOMAIN_UNIQUENAME]
return dc.Metadata[DomainUniqueName]
}

// UpdateSplitHorizonNames updates the split horizon fields
Expand All @@ -75,8 +75,8 @@ func (dc *DomainConfig) UpdateSplitHorizonNames() {
if dc.Metadata == nil {
dc.Metadata = map[string]string{}
}
dc.Metadata[DOMAIN_UNIQUENAME] = unique
dc.Metadata[DOMAIN_TAG] = tag
dc.Metadata[DomainUniqueName] = unique
dc.Metadata[DomainTag] = tag
}

// Copy returns a deep copy of the DomainConfig.
Expand Down
12 changes: 0 additions & 12 deletions pkg/diff2/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@ var d11 = makeRec("labg", "NS", "10.10.10.97") // [11']
var d12 = makeRec("labh", "A", "1.2.3.4") // [12']
var testDataApexMX22bbb = makeRec("", "MX", "22 bbb")

func makeChange(v Verb, l, t string, old, new models.Records, msgs []string) Change {
c := Change{
Type: v,
Old: old,
New: new,
Msgs: msgs,
}
c.Key.NameFQDN = l
c.Key.Type = t
return c
}

func compareMsgs(t *testing.T, fnname, testname, testpart string, gotcc ChangeList, wantstring string) {
t.Helper()
gs := strings.TrimSpace(justMsgString(gotcc))
Expand Down
15 changes: 0 additions & 15 deletions pkg/normalize/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,21 +578,6 @@ func checkDuplicates(records []*models.RecordConfig) (errs []error) {
return errs
}

// uniq returns the unique values in a map. The result is sorted lexigraphically.
func uniq(s []string) []string {
seen := make(map[string]struct{})
var result []string

for _, k := range s {
if _, ok := seen[k]; !ok {
seen[k] = struct{}{}
result = append(result, k)
}
}
sort.Strings(result)
return result
}

func checkRecordSetHasMultipleTTLs(records []*models.RecordConfig) (errs []error) {
// The RFCs say that all records at a particular recordset should have
// the same TTL. Most providers don't care, and if they do the
Expand Down
3 changes: 0 additions & 3 deletions pkg/soautil/soautil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import (
)

func Test_RFC5322MailToBind(t *testing.T) {
type args struct {
rfc5322Mail string
}
tests := []struct {
name string
rfc5322Mail string
Expand Down
2 changes: 1 addition & 1 deletion providers/bind/bindProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (c *bindProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, foundR

c.zonefile = filepath.Join(c.directory,
makeFileName(c.filenameformat,
dc.Metadata[models.DOMAIN_UNIQUENAME], dc.Name, dc.Metadata[models.DOMAIN_TAG]),
dc.Metadata[models.DomainUniqueName], dc.Name, dc.Metadata[models.DomainTag]),
)

// We only change the serial number if there is a change.
Expand Down
19 changes: 10 additions & 9 deletions providers/cloudflare/cloudflareProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ type cloudflareProvider struct {
cfClient *cloudflare.API
}

func labelMatches(label string, matches []string) bool {
printer.Debugf("DEBUG: labelMatches(%#v, %#v)\n", label, matches)
for _, tst := range matches {
if label == tst {
return true
}
}
return false
}
// TODO(dlemenkov): remove this function after deleting all commented code referecing it
//func labelMatches(label string, matches []string) bool {
// printer.Debugf("DEBUG: labelMatches(%#v, %#v)\n", label, matches)
// for _, tst := range matches {
// if label == tst {
// return true
// }
// }
// return false
//}

// GetNameservers returns the nameservers for a domain.
func (c *cloudflareProvider) GetNameservers(domain string) ([]*models.Nameserver, error) {
Expand Down
2 changes: 0 additions & 2 deletions providers/cscglobal/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ const apiBase = "https://apis.cscglobal.com/dbs/api/v2"

// Api layer for CSC Global

type requestParams map[string]string

type errorResponse struct {
Code string `json:"code"`
Description string `json:"description"`
Expand Down
16 changes: 9 additions & 7 deletions providers/desec/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,15 @@ func (c *desecProvider) upsertRR(rr []resourceRecord, domain string) error {
return nil
}

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 nil
}
// Uncomment this function in case of using it
// It was commented out to satisfy `staticcheck` warnings about unused code
//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 nil
//}

func (c *desecProvider) get(target, method string) ([]byte, *http.Response, error) {
retrycnt := 0
Expand Down
14 changes: 8 additions & 6 deletions providers/loopia/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ type structMemberInt struct {

func (m structMemberInt) structMember() {}

type structMemberBool struct {
Name string `xml:"name"`
Value bool `xml:"value>boolean"`
}

func (m structMemberBool) structMember() {}
// Uncomment this code in case of using it
// It was commented out to satisfy `staticcheck` warnings about unused code
//type structMemberBool struct {
// Name string `xml:"name"`
// Value bool `xml:"value>boolean"`
//}
//
//func (m structMemberBool) structMember() {}

type methodCall struct {
XMLName xml.Name `xml:"methodCall"`
Expand Down
7 changes: 0 additions & 7 deletions providers/namedotcom/records.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ import (
"github.com/namedotcom/go/namecom"
)

var defaultNameservers = []*models.Nameserver{
{Name: "ns1.name.com"},
{Name: "ns2.name.com"},
{Name: "ns3.name.com"},
{Name: "ns4.name.com"},
}

// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
func (n *namedotcomProvider) GetZoneRecords(domain string, meta map[string]string) (models.Records, error) {
records, err := n.getRecords(domain)
Expand Down
20 changes: 3 additions & 17 deletions providers/netcup/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const (
)

type netcupProvider struct {
domainIndex map[string]string
nameserversNames []string
credentials struct {
//domainIndex map[string]string
//nameserversNames []string
credentials struct {
apikey string
customernumber string
sessionID string
Expand Down Expand Up @@ -112,20 +112,6 @@ func (api *netcupProvider) login(apikey, password, customernumber string) error
return nil
}

func (api *netcupProvider) logout() error {
data := paramLogout{
Key: api.credentials.apikey,
SessionID: api.credentials.sessionID,
CustomerNumber: api.credentials.customernumber,
}
_, err := api.get("logout", data)
if err != nil {
return fmt.Errorf("failed to logout from netcup: %s", err)
}
api.credentials.apikey, api.credentials.sessionID, api.credentials.customernumber = "", "", ""
return nil
}

func (api *netcupProvider) get(action string, params interface{}) (json.RawMessage, error) {
reqParam := request{
Action: action,
Expand Down
6 changes: 0 additions & 6 deletions providers/netcup/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ type paramLogin struct {
CustomerNumber string `json:"customernumber"`
}

type paramLogout struct {
Key string `json:"apikey"`
SessionID string `json:"apisessionid"`
CustomerNumber string `json:"customernumber"`
}

type paramGetRecords struct {
Key string `json:"apikey"`
SessionID string `json:"apisessionid"`
Expand Down
4 changes: 0 additions & 4 deletions providers/ovh/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ type Record struct {
SubDomain string `json:"subDomain,omitempty"`
}

type records struct {
recordsID []int
}

func (c *ovhProvider) fetchRecords(fqdn string) ([]*Record, error) {
var recordIds []int

Expand Down
2 changes: 0 additions & 2 deletions providers/rwth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"github.com/StackExchange/dnscontrol/v3/models"
"github.com/StackExchange/dnscontrol/v3/pkg/printer"
"github.com/miekg/dns"
)

const (
Expand All @@ -31,7 +30,6 @@ type RecordReply struct {
Status string `json:"status"`
UpdatedAt time.Time `json:"updated_at"`
Editable bool `json:"editable"`
rec dns.RR // Store miekg/dns
}

type zone struct {
Expand Down
4 changes: 0 additions & 4 deletions providers/vultr/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,3 @@ func TestConversion(t *testing.T) {
}
}
}

func intPtr(v int) *int {
return &v
}
4 changes: 1 addition & 3 deletions staticcheck.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
checks = ["all", "-ST1000", "-U1000"]
# U1000 is disabled due to https://github.com/dominikh/go-tools/issues/810
# TODO(tlim): When #810 is fixed, we should enable U1000.
checks = ["all", "-ST1000"]

0 comments on commit 36e3595

Please sign in to comment.