chore: minor changes (#2108)

This commit is contained in:
Ludovic Fernandez 2024-02-09 21:55:43 +01:00 committed by GitHub
parent b9b0412f7c
commit 7fe1796157
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 25 additions and 36 deletions

View file

@ -7,8 +7,6 @@ linters-settings:
check-shadowing: true check-shadowing: true
gocyclo: gocyclo:
min-complexity: 12 min-complexity: 12
maligned:
suggest-new: true
goconst: goconst:
min-len: 3 min-len: 3
min-occurrences: 3 min-occurrences: 3

View file

@ -39,14 +39,14 @@ func TestGenerateCSR(t *testing.T) {
expected expected expected expected
}{ }{
{ {
desc: "without SAN", desc: "without SAN (nil)",
privateKey: privateKey, privateKey: privateKey,
domain: "lego.acme", domain: "lego.acme",
mustStaple: true, mustStaple: true,
expected: expected{len: 245}, expected: expected{len: 245},
}, },
{ {
desc: "without SAN", desc: "without SAN (empty)",
privateKey: privateKey, privateKey: privateKey,
domain: "lego.acme", domain: "lego.acme",
san: []string{}, san: []string{},

View file

@ -12,6 +12,7 @@ const (
// limited on the "new-reg", "new-authz" and "new-cert" endpoints. // limited on the "new-reg", "new-authz" and "new-cert" endpoints.
// From the documentation the limitation is 20 requests per second, // From the documentation the limitation is 20 requests per second,
// but using 20 as value doesn't work but 18 do. // but using 20 as value doesn't work but 18 do.
// https://letsencrypt.org/docs/rate-limits/
overallRequestLimit = 18 overallRequestLimit = 18
) )

View file

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"net" "net"
"os" "os"
"slices"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@ -216,12 +217,10 @@ func fetchSoaByFqdn(fqdn string, nameservers []string) (*soaCacheEntry, error) {
// dnsMsgContainsCNAME checks for a CNAME answer in msg. // dnsMsgContainsCNAME checks for a CNAME answer in msg.
func dnsMsgContainsCNAME(msg *dns.Msg) bool { func dnsMsgContainsCNAME(msg *dns.Msg) bool {
for _, ans := range msg.Answer { return slices.ContainsFunc(msg.Answer, func(rr dns.RR) bool {
if _, ok := ans.(*dns.CNAME); ok { _, ok := rr.(*dns.CNAME)
return true return ok
} })
}
return false
} }
func dnsQuery(fqdn string, rtype uint16, nameservers []string, recursive bool) (*dns.Msg, error) { func dnsQuery(fqdn string, rtype uint16, nameservers []string, recursive bool) (*dns.Msg, error) {

View file

@ -1,6 +1,6 @@
.PHONY: default clean hugo hugo-build .PHONY: default clean hugo hugo-build
default: hugo default: clean hugo
clean: clean:
rm -rf public/ rm -rf public/

View file

@ -3,6 +3,7 @@ package tester
import ( import (
"fmt" "fmt"
"os" "os"
"slices"
) )
// EnvTest Environment variables manager for tests. // 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 { func (e *EnvTest) isManagedKey(varName string) bool {
for _, key := range e.keys { return slices.Contains(e.keys, varName)
if key == varName {
return true
}
}
return false
} }

View file

@ -60,7 +60,7 @@ func (c *Client) GetDomainInformation(ctx context.Context, fqdn string) (*Data,
authZone, err := dns01.FindZoneByFqdn(fqdn) authZone, err := dns01.FindZoneByFqdn(fqdn)
if err != nil { 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 var domains []Data

View file

@ -6,6 +6,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"net/http" "net/http"
"slices"
"strconv" "strconv"
"time" "time"
@ -272,13 +273,11 @@ func containsValue(record *internal.Record, value string) bool {
return false return false
} }
for _, val := range record.Value { qValue := fmt.Sprintf(`%q`, value)
if val.Value == fmt.Sprintf(`%q`, value) {
return true
}
}
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 { func backoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {

View file

@ -4,6 +4,7 @@ package edgedns
import ( import (
"errors" "errors"
"fmt" "fmt"
"slices"
"strings" "strings"
"time" "time"
@ -224,13 +225,9 @@ func getZone(domain string) (string, error) {
} }
func containsValue(values []string, value string) bool { func containsValue(values []string, value string) bool {
for _, val := range values { return slices.ContainsFunc(values, func(val string) bool {
if strings.Trim(val, `"`) == value { return strings.Trim(val, `"`) == value
return true })
}
}
return false
} }
func isNotFound(err error) bool { func isNotFound(err error) bool {

View file

@ -28,7 +28,7 @@ func (p *configProvider) PrivateRSAKey() (*rsa.PrivateKey, error) {
return nil, err return nil, err
} }
return common.PrivateKeyFromBytes(privateKey, common.String(p.privateKeyPassphrase)) return common.PrivateKeyFromBytesWithPassword(privateKey, []byte(p.privateKeyPassphrase))
} }
func (p *configProvider) KeyID() (string, error) { func (p *configProvider) KeyID() (string, error) {

View file

@ -7,6 +7,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"slices"
"strings" "strings"
"time" "time"
@ -309,11 +310,9 @@ func decodeCredentials(accountB64 string) (ycsdk.Credentials, error) {
} }
func appendRecordSetData(record *ycdns.RecordSet, value string) bool { func appendRecordSetData(record *ycdns.RecordSet, value string) bool {
for _, data := range record.GetData() { if slices.Contains(record.GetData(), value) {
if data == value {
return false return false
} }
}
record.SetData(append(record.GetData(), value)) record.SetData(append(record.GetData(), value))