From 7fe1796157440206d7b0dbefed14c2e25c41ad33 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Fri, 9 Feb 2024 21:55:43 +0100 Subject: [PATCH] chore: minor changes (#2108) --- .golangci.yml | 2 -- certcrypto/crypto_test.go | 4 ++-- certificate/authorization.go | 1 + challenge/dns01/nameserver.go | 11 +++++------ docs/Makefile | 2 +- platform/tester/env.go | 8 ++------ providers/dns/cloudxns/internal/client.go | 2 +- providers/dns/constellix/constellix.go | 11 +++++------ providers/dns/edgedns/edgedns.go | 11 ++++------- providers/dns/oraclecloud/configprovider.go | 2 +- providers/dns/yandexcloud/yandexcloud.go | 7 +++---- 11 files changed, 25 insertions(+), 36 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 9b41f168..9571af97 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -7,8 +7,6 @@ linters-settings: check-shadowing: true gocyclo: min-complexity: 12 - maligned: - suggest-new: true goconst: min-len: 3 min-occurrences: 3 diff --git a/certcrypto/crypto_test.go b/certcrypto/crypto_test.go index f2abc04c..39e8304f 100644 --- a/certcrypto/crypto_test.go +++ b/certcrypto/crypto_test.go @@ -39,14 +39,14 @@ func TestGenerateCSR(t *testing.T) { expected expected }{ { - desc: "without SAN", + desc: "without SAN (nil)", privateKey: privateKey, domain: "lego.acme", mustStaple: true, expected: expected{len: 245}, }, { - desc: "without SAN", + desc: "without SAN (empty)", privateKey: privateKey, domain: "lego.acme", san: []string{}, diff --git a/certificate/authorization.go b/certificate/authorization.go index de9988ad..ce76ff8f 100644 --- a/certificate/authorization.go +++ b/certificate/authorization.go @@ -12,6 +12,7 @@ const ( // limited on the "new-reg", "new-authz" and "new-cert" endpoints. // From the documentation the limitation is 20 requests per second, // but using 20 as value doesn't work but 18 do. + // https://letsencrypt.org/docs/rate-limits/ overallRequestLimit = 18 ) diff --git a/challenge/dns01/nameserver.go b/challenge/dns01/nameserver.go index 3e2ba78e..1982852a 100644 --- a/challenge/dns01/nameserver.go +++ b/challenge/dns01/nameserver.go @@ -5,6 +5,7 @@ import ( "fmt" "net" "os" + "slices" "strconv" "strings" "sync" @@ -216,12 +217,10 @@ func fetchSoaByFqdn(fqdn string, nameservers []string) (*soaCacheEntry, error) { // dnsMsgContainsCNAME checks for a CNAME answer in msg. func dnsMsgContainsCNAME(msg *dns.Msg) bool { - for _, ans := range msg.Answer { - if _, ok := ans.(*dns.CNAME); ok { - return true - } - } - return false + return slices.ContainsFunc(msg.Answer, func(rr dns.RR) bool { + _, ok := rr.(*dns.CNAME) + return ok + }) } func dnsQuery(fqdn string, rtype uint16, nameservers []string, recursive bool) (*dns.Msg, error) { diff --git a/docs/Makefile b/docs/Makefile index c17a261e..8e32681d 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,6 +1,6 @@ .PHONY: default clean hugo hugo-build -default: hugo +default: clean hugo clean: rm -rf public/ diff --git a/platform/tester/env.go b/platform/tester/env.go index 42c4c301..26788be3 100644 --- a/platform/tester/env.go +++ b/platform/tester/env.go @@ -3,6 +3,7 @@ package tester import ( "fmt" "os" + "slices" ) // EnvTest Environment variables manager for tests. @@ -143,10 +144,5 @@ func (e *EnvTest) Apply(envVars map[string]string) { } func (e *EnvTest) isManagedKey(varName string) bool { - for _, key := range e.keys { - if key == varName { - return true - } - } - return false + return slices.Contains(e.keys, varName) } diff --git a/providers/dns/cloudxns/internal/client.go b/providers/dns/cloudxns/internal/client.go index 2fc6aab2..39e17d96 100644 --- a/providers/dns/cloudxns/internal/client.go +++ b/providers/dns/cloudxns/internal/client.go @@ -60,7 +60,7 @@ func (c *Client) GetDomainInformation(ctx context.Context, fqdn string) (*Data, authZone, err := dns01.FindZoneByFqdn(fqdn) if err != nil { - return nil, fmt.Errorf("cloudflare: could not find zone for FQDN %q: %w", fqdn, err) + return nil, fmt.Errorf("could not find zone for FQDN %q: %w", fqdn, err) } var domains []Data diff --git a/providers/dns/constellix/constellix.go b/providers/dns/constellix/constellix.go index 195b28ce..20d25ccd 100644 --- a/providers/dns/constellix/constellix.go +++ b/providers/dns/constellix/constellix.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "net/http" + "slices" "strconv" "time" @@ -272,13 +273,11 @@ func containsValue(record *internal.Record, value string) bool { return false } - for _, val := range record.Value { - if val.Value == fmt.Sprintf(`%q`, value) { - return true - } - } + qValue := fmt.Sprintf(`%q`, value) - return false + return slices.ContainsFunc(record.Value, func(val internal.RecordValue) bool { + return val.Value == qValue + }) } func backoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration { diff --git a/providers/dns/edgedns/edgedns.go b/providers/dns/edgedns/edgedns.go index cc6ac83d..263ba0c3 100644 --- a/providers/dns/edgedns/edgedns.go +++ b/providers/dns/edgedns/edgedns.go @@ -4,6 +4,7 @@ package edgedns import ( "errors" "fmt" + "slices" "strings" "time" @@ -224,13 +225,9 @@ func getZone(domain string) (string, error) { } func containsValue(values []string, value string) bool { - for _, val := range values { - if strings.Trim(val, `"`) == value { - return true - } - } - - return false + return slices.ContainsFunc(values, func(val string) bool { + return strings.Trim(val, `"`) == value + }) } func isNotFound(err error) bool { diff --git a/providers/dns/oraclecloud/configprovider.go b/providers/dns/oraclecloud/configprovider.go index e5fa66da..838d78a3 100644 --- a/providers/dns/oraclecloud/configprovider.go +++ b/providers/dns/oraclecloud/configprovider.go @@ -28,7 +28,7 @@ func (p *configProvider) PrivateRSAKey() (*rsa.PrivateKey, error) { return nil, err } - return common.PrivateKeyFromBytes(privateKey, common.String(p.privateKeyPassphrase)) + return common.PrivateKeyFromBytesWithPassword(privateKey, []byte(p.privateKeyPassphrase)) } func (p *configProvider) KeyID() (string, error) { diff --git a/providers/dns/yandexcloud/yandexcloud.go b/providers/dns/yandexcloud/yandexcloud.go index ee45ec43..eb1bb20e 100644 --- a/providers/dns/yandexcloud/yandexcloud.go +++ b/providers/dns/yandexcloud/yandexcloud.go @@ -7,6 +7,7 @@ import ( "encoding/json" "errors" "fmt" + "slices" "strings" "time" @@ -309,10 +310,8 @@ func decodeCredentials(accountB64 string) (ycsdk.Credentials, error) { } func appendRecordSetData(record *ycdns.RecordSet, value string) bool { - for _, data := range record.GetData() { - if data == value { - return false - } + if slices.Contains(record.GetData(), value) { + return false } record.SetData(append(record.GetData(), value))