Skip to content

Commit

Permalink
chore: minor changes (#2108)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Feb 9, 2024
1 parent b9b0412 commit 7fe1796
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 36 deletions.
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ linters-settings:
check-shadowing: true
gocyclo:
min-complexity: 12
maligned:
suggest-new: true
goconst:
min-len: 3
min-occurrences: 3
Expand Down
4 changes: 2 additions & 2 deletions certcrypto/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
1 change: 1 addition & 0 deletions certificate/authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
11 changes: 5 additions & 6 deletions challenge/dns01/nameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net"
"os"
"slices"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: default clean hugo hugo-build

default: hugo
default: clean hugo

clean:
rm -rf public/
Expand Down
8 changes: 2 additions & 6 deletions platform/tester/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tester
import (
"fmt"
"os"
"slices"
)

// EnvTest Environment variables manager for tests.
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion providers/dns/cloudxns/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions providers/dns/constellix/constellix.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"net/http"
"slices"
"strconv"
"time"

Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 4 additions & 7 deletions providers/dns/edgedns/edgedns.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package edgedns
import (
"errors"
"fmt"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/oraclecloud/configprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 3 additions & 4 deletions providers/dns/yandexcloud/yandexcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 7fe1796

Please sign in to comment.