From 14e48b9b0786c692f15b0917d1cd8382e0a9805b Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Tue, 10 Mar 2020 16:53:17 -0400 Subject: [PATCH] linting (#693) Co-authored-by: Tom Limoncelli --- commands/getCerts.go | 2 +- commands/previewPush.go | 2 +- commands/printIR.go | 2 +- integrationTest/integration_test.go | 2 +- models/tdwarn.go | 1 + pkg/acme/acme.go | 8 +++++++- pkg/nameservers/nameservers.go | 2 +- pkg/normalize/importTransform_test.go | 2 +- pkg/normalize/validate.go | 4 ++-- pkg/normalize/validate_test.go | 4 ++-- pkg/prettyzone/prettyzone.go | 7 ++++--- pkg/prettyzone/sorting.go | 9 +++++---- providers/capabilities.go | 2 +- providers/providers.go | 4 ++-- 14 files changed, 30 insertions(+), 21 deletions(-) diff --git a/commands/getCerts.go b/commands/getCerts.go index f77482b0a..33648d0af 100644 --- a/commands/getCerts.go +++ b/commands/getCerts.go @@ -137,7 +137,7 @@ func GetCerts(args GetCertsArgs) error { if err != nil { return err } - errs := normalize.NormalizeAndValidateConfig(cfg) + errs := normalize.ValidateAndNormalizeConfig(cfg) if PrintValidationErrors(errs) { return fmt.Errorf("Exiting due to validation errors") } diff --git a/commands/previewPush.go b/commands/previewPush.go index 695e7b93b..a7ba214d7 100644 --- a/commands/previewPush.go +++ b/commands/previewPush.go @@ -99,7 +99,7 @@ func run(args PreviewArgs, push bool, interactive bool, out printer.CLI) error { if err != nil { return err } - errs := normalize.NormalizeAndValidateConfig(cfg) + errs := normalize.ValidateAndNormalizeConfig(cfg) if PrintValidationErrors(errs) { return fmt.Errorf("Exiting due to validation errors") } diff --git a/commands/printIR.go b/commands/printIR.go index c3dc069a3..8e730c1de 100644 --- a/commands/printIR.go +++ b/commands/printIR.go @@ -70,7 +70,7 @@ func PrintIR(args PrintIRArgs) error { return err } if !args.Raw { - errs := normalize.NormalizeAndValidateConfig(cfg) + errs := normalize.ValidateAndNormalizeConfig(cfg) if PrintValidationErrors(errs) { return fmt.Errorf("Exiting due to validation errors") } diff --git a/integrationTest/integration_test.go b/integrationTest/integration_test.go index 250256f3e..dfa7637c1 100644 --- a/integrationTest/integration_test.go +++ b/integrationTest/integration_test.go @@ -222,7 +222,7 @@ func runTests(t *testing.T, prv providers.DNSServiceProvider, domainName string, for gIdx, group := range testGroups { // Abide by -start -end flags - curGroup += 1 + curGroup++ if curGroup < firstGroup || curGroup > lastGroup { continue } diff --git a/models/tdwarn.go b/models/tdwarn.go index ca2860b94..97c9429b3 100644 --- a/models/tdwarn.go +++ b/models/tdwarn.go @@ -4,6 +4,7 @@ import "fmt" var dotwarned = map[string]bool{} +// WarnNameserverDot prints a warning about issue 491 never more than once. func WarnNameserverDot(p, w string) { if dotwarned[p] { return diff --git a/pkg/acme/acme.go b/pkg/acme/acme.go index 1763138dc..c8c13aa66 100644 --- a/pkg/acme/acme.go +++ b/pkg/acme/acme.go @@ -23,6 +23,7 @@ import ( acmelog "github.com/go-acme/lego/log" ) +// CertConfig describes a certificate's configuration. type CertConfig struct { CertName string `json:"cert_name"` Names []string `json:"names"` @@ -30,6 +31,7 @@ type CertConfig struct { MustStaple bool `json:"must_staple"` } +// Client is an interface for systems that issue or renew certs. type Client interface { IssueOrRenewCert(config *CertConfig, renewUnder int, verbose bool) (bool, error) } @@ -51,10 +53,13 @@ type certManager struct { } const ( - LetsEncryptLive = "https://acme-v02.api.letsencrypt.org/directory" + // LetsEncryptLive is the endpoint for updates (production). + LetsEncryptLive = "https://acme-v02.api.letsencrypt.org/directory" + // LetsEncryptStage is the endpoint for the staging area. LetsEncryptStage = "https://acme-staging-v02.api.letsencrypt.org/directory" ) +// New is a factory for acme clients. func New(cfg *models.DNSConfig, directory string, email string, server string, notify notifications.Notifier) (Client, error) { return commonNew(cfg, directoryStorage(directory), email, server, notify) } @@ -82,6 +87,7 @@ func commonNew(cfg *models.DNSConfig, storage Storage, email string, server stri return c, nil } +// NewVault is a factory for new vaunt clients. func NewVault(cfg *models.DNSConfig, vaultPath string, email string, server string, notify notifications.Notifier) (Client, error) { storage, err := makeVaultStorage(vaultPath) if err != nil { diff --git a/pkg/nameservers/nameservers.go b/pkg/nameservers/nameservers.go index e74d082ba..f85d7bbc1 100644 --- a/pkg/nameservers/nameservers.go +++ b/pkg/nameservers/nameservers.go @@ -29,7 +29,7 @@ func DetermineNameservers(dc *models.DomainConfig) ([]*models.Nameserver, error) // Clean up the nameservers due to // https://github.com/StackExchange/dnscontrol/issues/491 // In the far future, this warning will become a fatal error. - for i, _ := range nss { + for i := range nss { if strings.HasSuffix(nss[i].Name, ".") { models.WarnNameserverDot(dnsProvider.Name, fmt.Sprintf("DetermineNameservers (%s) (%s)", dc.Name, nss[i].Name)) nss[i].Name = strings.TrimSuffix(nss[i].Name, ".") diff --git a/pkg/normalize/importTransform_test.go b/pkg/normalize/importTransform_test.go index 53c543c2c..8b4a099ca 100644 --- a/pkg/normalize/importTransform_test.go +++ b/pkg/normalize/importTransform_test.go @@ -33,7 +33,7 @@ func TestImportTransform(t *testing.T) { cfg := &models.DNSConfig{ Domains: []*models.DomainConfig{src, dst}, } - if errs := NormalizeAndValidateConfig(cfg); len(errs) != 0 { + if errs := ValidateAndNormalizeConfig(cfg); len(errs) != 0 { for _, err := range errs { t.Error(err) } diff --git a/pkg/normalize/validate.go b/pkg/normalize/validate.go index fe81d66ac..880164639 100644 --- a/pkg/normalize/validate.go +++ b/pkg/normalize/validate.go @@ -268,8 +268,8 @@ type Warning struct { error } -// NormalizeAndValidateConfig performs and normalization and/or validation of the IR. -func NormalizeAndValidateConfig(config *models.DNSConfig) (errs []error) { +// ValidateAndNormalizeConfig performs and normalization and/or validation of the IR. +func ValidateAndNormalizeConfig(config *models.DNSConfig) (errs []error) { for _, domain := range config.Domains { pTypes := []string{} txtMultiDissenters := []string{} diff --git a/pkg/normalize/validate_test.go b/pkg/normalize/validate_test.go index a18e66294..a59719646 100644 --- a/pkg/normalize/validate_test.go +++ b/pkg/normalize/validate_test.go @@ -210,7 +210,7 @@ func TestCAAValidation(t *testing.T) { }, }, } - errs := NormalizeAndValidateConfig(config) + errs := ValidateAndNormalizeConfig(config) if len(errs) != 1 { t.Error("Expect error on invalid CAA but got none") } @@ -277,7 +277,7 @@ func TestTLSAValidation(t *testing.T) { }, }, } - errs := NormalizeAndValidateConfig(config) + errs := ValidateAndNormalizeConfig(config) if len(errs) != 1 { t.Error("Expect error on invalid TLSA but got none") } diff --git a/pkg/prettyzone/prettyzone.go b/pkg/prettyzone/prettyzone.go index 4470fa9db..854c48f88 100644 --- a/pkg/prettyzone/prettyzone.go +++ b/pkg/prettyzone/prettyzone.go @@ -70,11 +70,12 @@ func WriteZoneFileRC(w io.Writer, records models.Records, origin string, default return z.generateZoneFileHelper(w) } -func PrettySort(records models.Records, origin string, defaultTTL uint32, comments []string) *zoneGenData { +// PrettySort sorts the records in a pretty order. +func PrettySort(records models.Records, origin string, defaultTTL uint32, comments []string) *ZoneGenData { if defaultTTL == 0 { defaultTTL = MostCommonTTL(records) } - z := &zoneGenData{ + z := &ZoneGenData{ Origin: origin + ".", DefaultTTL: defaultTTL, Comments: comments, @@ -90,7 +91,7 @@ func PrettySort(records models.Records, origin string, defaultTTL uint32, commen } // generateZoneFileHelper creates a pretty zonefile. -func (z *zoneGenData) generateZoneFileHelper(w io.Writer) error { +func (z *ZoneGenData) generateZoneFileHelper(w io.Writer) error { nameShortPrevious := "" diff --git a/pkg/prettyzone/sorting.go b/pkg/prettyzone/sorting.go index ca7c88fb9..0c1df7197 100644 --- a/pkg/prettyzone/sorting.go +++ b/pkg/prettyzone/sorting.go @@ -12,16 +12,17 @@ import ( "github.com/StackExchange/dnscontrol/v2/models" ) -type zoneGenData struct { +// ZoneGenData is the configuration description for the zone generator. +type ZoneGenData struct { Origin string DefaultTTL uint32 Records models.Records Comments []string } -func (z *zoneGenData) Len() int { return len(z.Records) } -func (z *zoneGenData) Swap(i, j int) { z.Records[i], z.Records[j] = z.Records[j], z.Records[i] } -func (z *zoneGenData) Less(i, j int) bool { +func (z *ZoneGenData) Len() int { return len(z.Records) } +func (z *ZoneGenData) Swap(i, j int) { z.Records[i], z.Records[j] = z.Records[j], z.Records[i] } +func (z *ZoneGenData) Less(i, j int) bool { a, b := z.Records[i], z.Records[j] // Sort by name. diff --git a/providers/capabilities.go b/providers/capabilities.go index 8746098d6..58fa6ef17 100644 --- a/providers/capabilities.go +++ b/providers/capabilities.go @@ -56,7 +56,7 @@ const ( // CanUseRoute53Alias indicates the provider support the specific R53_ALIAS records that only the Route53 provider supports CanUseRoute53Alias - // CanGetZoe indicates the provider supports the get-zones subcommand. + // CanGetZones indicates the provider supports the get-zones subcommand. CanGetZones // CanUseAzureAlias indicates the provider support the specific Azure_ALIAS records that only the Azure provider supports diff --git a/providers/providers.go b/providers/providers.go index 7b83a9a6a..d450dd4c2 100644 --- a/providers/providers.go +++ b/providers/providers.go @@ -24,7 +24,7 @@ type DomainCreator interface { EnsureDomainExists(domain string) error } -// DomainLister should be implemented by providers that have the +// ZoneLister should be implemented by providers that have the // ability to list the zones they manage. This facilitates using the // "get-zones" command for "all" zones. type ZoneLister interface { @@ -93,7 +93,7 @@ func (n None) GetNameservers(string) ([]*models.Nameserver, error) { } // GetZoneRecords gets the records of a zone and returns them in RecordConfig format. -func (client None) GetZoneRecords(domain string) (models.Records, error) { +func (n None) GetZoneRecords(domain string) (models.Records, error) { return nil, fmt.Errorf("not implemented") // This enables the get-zones subcommand. // Implement this by extracting the code from GetDomainCorrections into