From 23824af555b9369c71c20f745980739215a376da Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Thu, 8 Feb 2024 03:16:48 +0100 Subject: [PATCH] chore: update to go1.21 (#2103) --- .github/workflows/pr.yml | 2 +- .golangci.yml | 18 +++++------------- acme/api/account.go | 2 +- certcrypto/crypto.go | 14 +++----------- cmd/cmd_renew.go | 2 +- cmd/cmd_run.go | 2 +- go.mod | 2 +- go.sum | 14 ++++++++++++++ platform/config/env/env_test.go | 2 +- providers/dns/alidns/alidns.go | 2 +- providers/dns/azuredns/oidc.go | 9 +++++---- providers/dns/checkdomain/checkdomain.go | 1 - providers/dns/cloudru/internal/client.go | 3 ++- providers/dns/cpanel/cpanel.go | 14 +++----------- providers/dns/designate/designate.go | 14 +++----------- providers/dns/edgedns/edgedns.go | 6 +++--- providers/dns/googledomains/googledomains.go | 5 +++-- providers/dns/iij/iij.go | 12 ++---------- providers/dns/loopia/loopia_mock_test.go | 5 ++--- providers/dns/mythicbeasts/internal/client.go | 3 ++- providers/dns/nicmanager/nicmanager.go | 2 +- providers/dns/servercow/servercow.go | 15 +++------------ providers/dns/transip/fakeclient_test.go | 9 +++++---- providers/dns/vkcloud/vkcloud.go | 2 +- providers/dns/yandex/yandex.go | 2 +- providers/dns/yandexcloud/yandexcloud.go | 4 ++-- providers/http/memcached/memcached_test.go | 2 +- providers/http/s3/s3.go | 3 ++- 28 files changed, 70 insertions(+), 101 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 53256110..fdc9e133 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest env: GO_VERSION: stable - GOLANGCI_LINT_VERSION: v1.55.2 + GOLANGCI_LINT_VERSION: v1.56.0 HUGO_VERSION: '0.117.0' CGO_ENABLED: 0 LEGO_E2E_TESTS: CI diff --git a/.golangci.yml b/.golangci.yml index e079c976..9b41f168 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -89,18 +89,9 @@ linters-settings: - name: unreachable-code - name: redefines-builtin-id testifylint: - enable: - - bool-compare - - compares - - empty - - error-is-as - - error-nil - - expected-actual - - float-compare - - len - - suite-dont-use-pkg - - suite-extra-assert-call - - suite-thelper + disable: + - require-error + - go-require linters: enable-all: true @@ -153,12 +144,13 @@ linters: issues: exclude-use-default: false - max-per-linter: 0 + max-issues-per-linter: 0 max-same-issues: 0 exclude: - 'Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked' - 'exported (type|method|function) (.+) should have comment or be unexported' - 'ST1000: at least one file in a package should have a package comment' + - 'fmt.Sprintf can be replaced with string addition' exclude-rules: - path: (.+)_test.go linters: diff --git a/acme/api/account.go b/acme/api/account.go index d1cd72d9..85de84ef 100644 --- a/acme/api/account.go +++ b/acme/api/account.go @@ -16,7 +16,7 @@ func (a *AccountService) New(req acme.Account) (acme.ExtendedAccount, error) { resp, err := a.core.post(a.core.GetDirectory().NewAccountURL, req, &account) location := getLocation(resp) - if len(location) > 0 { + if location != "" { a.core.jws.SetKid(location) } diff --git a/certcrypto/crypto.go b/certcrypto/crypto.go index 4f5e17c5..43fa774a 100644 --- a/certcrypto/crypto.go +++ b/certcrypto/crypto.go @@ -15,6 +15,7 @@ import ( "fmt" "math/big" "net" + "slices" "strings" "time" @@ -88,7 +89,7 @@ func ParsePEMBundle(bundle []byte) ([]*x509.Certificate, error) { func ParsePEMPrivateKey(key []byte) (crypto.PrivateKey, error) { keyBlockDER, _ := pem.Decode(key) if keyBlockDER == nil { - return nil, fmt.Errorf("invalid PEM block") + return nil, errors.New("invalid PEM block") } if keyBlockDER.Type != "PRIVATE KEY" && !strings.HasSuffix(keyBlockDER.Type, " PRIVATE KEY") { @@ -268,7 +269,7 @@ func ExtractDomainsCSR(csr *x509.CertificateRequest) []string { // loop over the SubjectAltName DNS names for _, sanName := range csr.DNSNames { - if containsSAN(domains, sanName) { + if slices.Contains(domains, sanName) { // Duplicate; skip this name continue } @@ -287,15 +288,6 @@ func ExtractDomainsCSR(csr *x509.CertificateRequest) []string { return domains } -func containsSAN(domains []string, sanName string) bool { - for _, existingName := range domains { - if existingName == sanName { - return true - } - } - return false -} - func GeneratePemCert(privateKey *rsa.PrivateKey, domain string, extensions []pkix.Extension) ([]byte, error) { derBytes, err := generateDerCert(privateKey, time.Time{}, domain, extensions) if err != nil { diff --git a/cmd/cmd_renew.go b/cmd/cmd_renew.go index 70376def..0940f580 100644 --- a/cmd/cmd_renew.go +++ b/cmd/cmd_renew.go @@ -34,7 +34,7 @@ func createRenew() *cli.Command { Before: func(ctx *cli.Context) error { // we require either domains or csr, but not both hasDomains := len(ctx.StringSlice("domains")) > 0 - hasCsr := len(ctx.String("csr")) > 0 + hasCsr := ctx.String("csr") != "" if hasDomains && hasCsr { log.Fatal("Please specify either --domains/-d or --csr/-c, but not both") } diff --git a/cmd/cmd_run.go b/cmd/cmd_run.go index 38df4bc5..10bd0cbc 100644 --- a/cmd/cmd_run.go +++ b/cmd/cmd_run.go @@ -21,7 +21,7 @@ func createRun() *cli.Command { Before: func(ctx *cli.Context) error { // we require either domains or csr, but not both hasDomains := len(ctx.StringSlice("domains")) > 0 - hasCsr := len(ctx.String("csr")) > 0 + hasCsr := ctx.String("csr") != "" if hasDomains && hasCsr { log.Fatal("Please specify either --domains/-d or --csr/-c, but not both") } diff --git a/go.mod b/go.mod index 6867a771..ae3090e1 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/go-acme/lego/v4 -go 1.20 +go 1.21 // github.com/exoscale/egoscale v1.19.0 => It is an error, please don't use it. diff --git a/go.sum b/go.sum index a2590ba4..59e026ab 100644 --- a/go.sum +++ b/go.sum @@ -28,9 +28,11 @@ github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aov github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dns/armdns v1.1.0 h1:8iR6OLffWWorFdzL2JFCab5xpD8VKEE2DUBBl+HNTDY= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dns/armdns v1.1.0/go.mod h1:copqlcjMWc/wgQ1N2fzsJFQxDdqKGg1EQt8T5wJMOGE= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 h1:mLY+pNLjCUeKhgnAJWAKhEUQM+RJQo2H1fuGSw1Ky1E= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2/go.mod h1:FbdwsQ2EzwvXxOPcMFYO8ogEc9uMMIj3YkmCdXdAFmk= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/privatedns/armprivatedns v1.1.0 h1:rR8ZW79lE/ppfXTfiYSnMFv5EzmVuY4pfZWIkscIJ64= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/privatedns/armprivatedns v1.1.0/go.mod h1:y2zXtLSMM/X5Mfawq0lOftpWn3f4V6OCsRdINsvWBPI= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 h1:ECsQtyERDVz3NP3kvDOTLvbQhqWp/x9EsGKtb4ogUr8= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0/go.mod h1:s1tW/At+xHqjNFvWU4G0c0Qv33KOhvbGNj0RCTQDV8s= github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs= github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= github.com/Azure/go-autorest/autorest v0.11.24/go.mod h1:G6kyRlFnTuSbEYkQGawPfsCswgme4iYf6rfSKUDzbCc= @@ -168,6 +170,7 @@ github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8 github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi/U= github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE= github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= +github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= github.com/dnsimple/dnsimple-go v1.2.0 h1:ddTGyLVKly5HKb5L65AkLqFqwZlWo3WnR0BlFZlIddM= github.com/dnsimple/dnsimple-go v1.2.0/go.mod h1:z/cs26v/eiRvUyXsHQBLd8lWF8+cD6GbmkPH84plM4U= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -181,6 +184,7 @@ github.com/exoscale/egoscale v0.102.3 h1:DYqN2ipoLKpiFoprRGQkp2av/Ze7sUYYlGhi1N6 github.com/exoscale/egoscale v0.102.3/go.mod h1:RPf2Gah6up+6kAEayHTQwqapzXlm93f0VQas/UEGU5c= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -219,6 +223,7 @@ github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg78 github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 h1:TQcrn6Wq+sKGkpyPvppOz99zsMBaUOKXq6HSv655U1c= github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/gobs/pretty v0.0.0-20180724170744-09732c25a95b h1:/vQ+oYKu+JoyaMPDsv5FzwuL2wwWBgBbtj/YLCi4LuA= +github.com/gobs/pretty v0.0.0-20180724170744-09732c25a95b/go.mod h1:Xo4aNUOrJnVruqWQJBtW6+bTBDTniY8yZum5rF3b5jw= github.com/goccy/go-json v0.7.8/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= @@ -270,6 +275,7 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= @@ -317,6 +323,7 @@ github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9n github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= github.com/hashicorp/go-hclog v1.2.0 h1:La19f8d7WIlm4ogzNHB0JGqs5AUDAZ2UfCY4sJXcJdM= +github.com/hashicorp/go-hclog v1.2.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= @@ -347,6 +354,7 @@ github.com/infobloxopen/infoblox-go-client v1.1.1 h1:728A6LbLjptj/7kZjHyIxQnm768 github.com/infobloxopen/infoblox-go-client v1.1.1/go.mod h1:BXiw7S2b9qJoM8MS40vfgCNB2NLHGusk1DtO16BD9zI= github.com/jarcoal/httpmock v1.0.8/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik= github.com/jarcoal/httpmock v1.3.0 h1:2RJ8GP0IIaWwcC9Fp2BmVi8Kog3v2Hn7VXM3fTd+nuc= +github.com/jarcoal/httpmock v1.3.0/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= @@ -414,6 +422,7 @@ github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= +github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= @@ -426,6 +435,7 @@ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/maxatome/go-testdeep v1.12.0 h1:Ql7Go8Tg0C1D/uMMX59LAoYK7LffeJQ6X2T04nTH68g= +github.com/maxatome/go-testdeep v1.12.0/go.mod h1:lPZc/HAcJMP92l7yI6TRz1aZN5URwUBUAfUNvrclaNM= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.47/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME= github.com/miekg/dns v1.1.58 h1:ca2Hdkz+cDg/7eNF6V56jjzuZ4aCAE+DbVkILdQWG/4= @@ -540,6 +550,7 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg= +github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -567,6 +578,7 @@ github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9 h1:hp2CY github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/gunit v1.0.4 h1:tpTjnuH7MLlqhoD21vRoMZbMIi5GmBsAJDFyF67GhZA= +github.com/smartystreets/gunit v1.0.4/go.mod h1:EH5qMBab2UclzXUcpR8b93eHsIlp9u+pDQIRp5DZNzQ= github.com/softlayer/softlayer-go v1.1.3 h1:dfFzt5eOKIAyB/b78fHMyDu5ICx0ZtxL9NRhBlf831A= github.com/softlayer/softlayer-go v1.1.3/go.mod h1:Pc7F57OgUKaAam7TtpqkUeqL7QyKknfiUI4R49h41/U= github.com/softlayer/xmlrpc v0.0.0-20200409220501-5f089df7cb7e h1:3OgWYFw7jxCZPcvAg+4R8A50GZ+CCkARF10lxu2qDsQ= @@ -750,6 +762,7 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -809,6 +822,7 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE= +golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= diff --git a/platform/config/env/env_test.go b/platform/config/env/env_test.go index dc022b3c..3de55b5c 100644 --- a/platform/config/env/env_test.go +++ b/platform/config/env/env_test.go @@ -98,7 +98,7 @@ func TestGetWithFallback(t *testing.T) { t.Parallel() value, err := GetWithFallback(test.groups...) - if len(test.expected.error) > 0 { + if test.expected.error != "" { assert.EqualError(t, err, test.expected.error) } else { require.NoError(t, err) diff --git a/providers/dns/alidns/alidns.go b/providers/dns/alidns/alidns.go index 23320b23..39625451 100644 --- a/providers/dns/alidns/alidns.go +++ b/providers/dns/alidns/alidns.go @@ -108,7 +108,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { case config.APIKey != "" && config.SecretKey != "": credential = credentials.NewAccessKeyCredential(config.APIKey, config.SecretKey) default: - return nil, fmt.Errorf("alicloud: ram role or credentials missing") + return nil, errors.New("alicloud: ram role or credentials missing") } conf := sdk.NewConfig().WithTimeout(config.HTTPTimeout) diff --git a/providers/dns/azuredns/oidc.go b/providers/dns/azuredns/oidc.go index 9124941b..aa98d55e 100644 --- a/providers/dns/azuredns/oidc.go +++ b/providers/dns/azuredns/oidc.go @@ -3,6 +3,7 @@ package azuredns import ( "context" "encoding/json" + "errors" "fmt" "io" "net/http" @@ -13,15 +14,15 @@ import ( func checkOIDCConfig(config *Config) error { if config.TenantID == "" { - return fmt.Errorf("azuredns: TenantID is missing") + return errors.New("azuredns: TenantID is missing") } if config.ClientID == "" { - return fmt.Errorf("azuredns: ClientID is missing") + return errors.New("azuredns: ClientID is missing") } if config.OIDCToken == "" && config.OIDCTokenFilePath == "" && (config.OIDCRequestURL == "" || config.OIDCRequestToken == "") { - return fmt.Errorf("azuredns: OIDCToken, OIDCTokenFilePath or OIDCRequestURL and OIDCRequestToken must be set") + return errors.New("azuredns: OIDCToken, OIDCTokenFilePath or OIDCRequestURL and OIDCRequestToken must be set") } return nil @@ -64,7 +65,7 @@ func getOIDCToken(config *Config) (string, error) { query, err := url.ParseQuery(req.URL.RawQuery) if err != nil { - return "", fmt.Errorf("azuredns: cannot parse OIDC request URL query") + return "", errors.New("azuredns: cannot parse OIDC request URL query") } if query.Get("audience") == "" { diff --git a/providers/dns/checkdomain/checkdomain.go b/providers/dns/checkdomain/checkdomain.go index 7228fe29..4f1e7c13 100644 --- a/providers/dns/checkdomain/checkdomain.go +++ b/providers/dns/checkdomain/checkdomain.go @@ -115,7 +115,6 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { Type: "TXT", Value: info.Value, }) - if err != nil { return fmt.Errorf("checkdomain: %w", err) } diff --git a/providers/dns/cloudru/internal/client.go b/providers/dns/cloudru/internal/client.go index 63d4b30c..cb62c5bc 100644 --- a/providers/dns/cloudru/internal/client.go +++ b/providers/dns/cloudru/internal/client.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" "io" "net/http" @@ -118,7 +119,7 @@ func (c *Client) do(req *http.Request, result any) error { if tok != nil { req.Header.Set("Authorization", "Bearer "+tok.AccessToken) } else { - return fmt.Errorf("not logged in") + return errors.New("not logged in") } resp, err := c.HTTPClient.Do(req) diff --git a/providers/dns/cpanel/cpanel.go b/providers/dns/cpanel/cpanel.go index 333bc689..c0573df3 100644 --- a/providers/dns/cpanel/cpanel.go +++ b/providers/dns/cpanel/cpanel.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "net/http" + "slices" "strings" "time" @@ -145,7 +146,7 @@ func (d *DNSProvider) Present(domain, _, keyAuth string) error { var found bool var existingRecord shared.ZoneRecord for _, record := range zoneInfo { - if contains(record.DataB64, valueB64) { + if slices.Contains(record.DataB64, valueB64) { existingRecord = record found = true break @@ -219,7 +220,7 @@ func (d *DNSProvider) CleanUp(domain, _, keyAuth string) error { var found bool var existingRecord shared.ZoneRecord for _, record := range zoneInfo { - if contains(record.DataB64, valueB64) { + if slices.Contains(record.DataB64, valueB64) { existingRecord = record found = true break @@ -328,12 +329,3 @@ func createClient(config *Config) (apiClient, error) { return nil, fmt.Errorf("unsupported mode: %q", config.Mode) } } - -func contains(values []string, value string) bool { - for _, v := range values { - if v == value { - return true - } - } - return false -} diff --git a/providers/dns/designate/designate.go b/providers/dns/designate/designate.go index da3b6f78..8447a31f 100644 --- a/providers/dns/designate/designate.go +++ b/providers/dns/designate/designate.go @@ -6,6 +6,7 @@ import ( "fmt" "log" "os" + "slices" "sync" "time" @@ -146,7 +147,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { } if existingRecord != nil { - if contains(existingRecord.Records, info.Value) { + if slices.Contains(existingRecord.Records, info.Value) { log.Printf("designate: the record already exists: %s", info.Value) return nil } @@ -197,15 +198,6 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { return nil } -func contains(values []string, value string) bool { - for _, v := range values { - if v == value { - return true - } - } - return false -} - func (d *DNSProvider) createRecord(zoneID, fqdn, value string) error { createOpts := recordsets.CreateOpts{ Name: fqdn, @@ -228,7 +220,7 @@ func (d *DNSProvider) createRecord(zoneID, fqdn, value string) error { } func (d *DNSProvider) updateRecord(record *recordsets.RecordSet, value string) error { - if contains(record.Records, value) { + if slices.Contains(record.Records, value) { log.Printf("skip: the record already exists: %s", value) return nil } diff --git a/providers/dns/edgedns/edgedns.go b/providers/dns/edgedns/edgedns.go index 1dcb4865..cc6ac83d 100644 --- a/providers/dns/edgedns/edgedns.go +++ b/providers/dns/edgedns/edgedns.go @@ -120,7 +120,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { } if err == nil && record == nil { - return fmt.Errorf("edgedns: unknown error") + return errors.New("edgedns: unknown error") } if record != nil { @@ -175,11 +175,11 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { } if existingRec == nil { - return fmt.Errorf("edgedns: unknown failure") + return errors.New("edgedns: unknown failure") } if len(existingRec.Target) == 0 { - return fmt.Errorf("edgedns: TXT record is invalid") + return errors.New("edgedns: TXT record is invalid") } if !containsValue(existingRec.Target, info.Value) { diff --git a/providers/dns/googledomains/googledomains.go b/providers/dns/googledomains/googledomains.go index 254fd655..b8206dbf 100644 --- a/providers/dns/googledomains/googledomains.go +++ b/providers/dns/googledomains/googledomains.go @@ -3,6 +3,7 @@ package googledomains import ( "context" + "errors" "fmt" "net/http" "time" @@ -62,11 +63,11 @@ func NewDNSProvider() (*DNSProvider, error) { // NewDNSProviderConfig returns the Google Domains DNS provider with the provided config. func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { if config == nil { - return nil, fmt.Errorf("googledomains: the configuration of the DNS provider is nil") + return nil, errors.New("googledomains: the configuration of the DNS provider is nil") } if config.AccessToken == "" { - return nil, fmt.Errorf("googledomains: access token is missing") + return nil, errors.New("googledomains: access token is missing") } service, err := acmedns.NewService(context.Background(), option.WithHTTPClient(config.HTTPClient)) diff --git a/providers/dns/iij/iij.go b/providers/dns/iij/iij.go index ed5b8770..ed092932 100644 --- a/providers/dns/iij/iij.go +++ b/providers/dns/iij/iij.go @@ -4,6 +4,7 @@ package iij import ( "errors" "fmt" + "slices" "strconv" "strings" "time" @@ -229,7 +230,7 @@ func splitDomain(domain string, zones []string) (string, string, error) { for i := 0; i < len(parts)-1; i++ { zone = strings.Join(parts[i:], ".") - if zoneContains(zone, zones) { + if slices.Contains(zones, zone) { baseOwner := strings.Join(parts[0:i], ".") if baseOwner != "" { baseOwner = "." + baseOwner @@ -245,12 +246,3 @@ func splitDomain(domain string, zones []string) (string, string, error) { return owner, zone, nil } - -func zoneContains(zone string, zones []string) bool { - for _, z := range zones { - if zone == z { - return true - } - } - return false -} diff --git a/providers/dns/loopia/loopia_mock_test.go b/providers/dns/loopia/loopia_mock_test.go index 6416bb99..93f26af0 100644 --- a/providers/dns/loopia/loopia_mock_test.go +++ b/providers/dns/loopia/loopia_mock_test.go @@ -3,7 +3,6 @@ package loopia import ( "context" "errors" - "fmt" "testing" "github.com/go-acme/lego/v4/providers/dns/loopia/internal" @@ -47,7 +46,7 @@ func TestDNSProvider_Present(t *testing.T) { { desc: "AddTXTRecord fails", - addTXTRecordError: fmt.Errorf("unknown error: 'ADDTXT'"), + addTXTRecordError: errors.New("unknown error: 'ADDTXT'"), callAddTXTRecord: true, expectedError: "loopia: failed to add TXT record: unknown error: 'ADDTXT'", @@ -55,7 +54,7 @@ func TestDNSProvider_Present(t *testing.T) { { desc: "GetTXTRecords fails", - getTXTRecordsError: fmt.Errorf("unknown error: 'GETTXT'"), + getTXTRecordsError: errors.New("unknown error: 'GETTXT'"), callAddTXTRecord: true, callGetTXTRecords: true, diff --git a/providers/dns/mythicbeasts/internal/client.go b/providers/dns/mythicbeasts/internal/client.go index 59d3bf90..91fbbaf5 100644 --- a/providers/dns/mythicbeasts/internal/client.go +++ b/providers/dns/mythicbeasts/internal/client.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" "io" "net/http" @@ -134,7 +135,7 @@ func (c *Client) do(req *http.Request, result any) error { if tok != nil { req.Header.Set("Authorization", "Bearer "+tok.Token) } else { - return fmt.Errorf("not logged in") + return errors.New("not logged in") } resp, err := c.HTTPClient.Do(req) diff --git a/providers/dns/nicmanager/nicmanager.go b/providers/dns/nicmanager/nicmanager.go index e5054ef0..5e8ff24f 100644 --- a/providers/dns/nicmanager/nicmanager.go +++ b/providers/dns/nicmanager/nicmanager.go @@ -201,5 +201,5 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { } } - return fmt.Errorf("nicmanager: no record found to clean up") + return errors.New("nicmanager: no record found to clean up") } diff --git a/providers/dns/servercow/servercow.go b/providers/dns/servercow/servercow.go index 324fa660..e43a225c 100644 --- a/providers/dns/servercow/servercow.go +++ b/providers/dns/servercow/servercow.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "net/http" + "slices" "time" "github.com/go-acme/lego/v4/challenge/dns01" @@ -118,7 +119,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { // TXT record entry already existing if record != nil { - if containsValue(record, info.Value) { + if slices.Contains(record.Content, info.Value) { return nil } @@ -177,7 +178,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { return nil } - if !containsValue(record, info.Value) { + if !slices.Contains(record.Content, info.Value) { return nil } @@ -229,13 +230,3 @@ func findRecords(records []internal.Record, name string) *internal.Record { return nil } - -func containsValue(record *internal.Record, value string) bool { - for _, val := range record.Content { - if val == value { - return true - } - } - - return false -} diff --git a/providers/dns/transip/fakeclient_test.go b/providers/dns/transip/fakeclient_test.go index 7696c22b..b1ee0434 100644 --- a/providers/dns/transip/fakeclient_test.go +++ b/providers/dns/transip/fakeclient_test.go @@ -2,6 +2,7 @@ package transip import ( "encoding/json" + "errors" "fmt" "time" @@ -79,12 +80,12 @@ func (f *fakeClient) Post(request rest.Request) error { body, err := request.GetJSONBody() if err != nil { - return fmt.Errorf("unable get request body") + return errors.New("unable get request body") } var entry dnsEntryWrapper if err := json.Unmarshal(body, &entry); err != nil { - return fmt.Errorf("unable to decode request body") + return errors.New("unable to decode request body") } f.dnsEntries = append(f.dnsEntries, entry.DNSEntry) @@ -103,12 +104,12 @@ func (f *fakeClient) Delete(request rest.Request) error { body, err := request.GetJSONBody() if err != nil { - return fmt.Errorf("unable get request body") + return errors.New("unable get request body") } var entry dnsEntryWrapper if err := json.Unmarshal(body, &entry); err != nil { - return fmt.Errorf("unable to decode request body") + return errors.New("unable to decode request body") } cp := make([]domain.DNSEntry, 0) diff --git a/providers/dns/vkcloud/vkcloud.go b/providers/dns/vkcloud/vkcloud.go index 775f4005..49acfc08 100644 --- a/providers/dns/vkcloud/vkcloud.go +++ b/providers/dns/vkcloud/vkcloud.go @@ -93,7 +93,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { } if config.DNSEndpoint == "" { - return nil, fmt.Errorf("vkcloud: DNS endpoint is missing in config") + return nil, errors.New("vkcloud: DNS endpoint is missing in config") } authOpts := gophercloud.AuthOptions{ diff --git a/providers/dns/yandex/yandex.go b/providers/dns/yandex/yandex.go index 5bbac230..126aa2f9 100644 --- a/providers/dns/yandex/yandex.go +++ b/providers/dns/yandex/yandex.go @@ -73,7 +73,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { } if config.PddToken == "" { - return nil, fmt.Errorf("yandex: credentials missing") + return nil, errors.New("yandex: credentials missing") } client, err := internal.NewClient(config.PddToken) diff --git a/providers/dns/yandexcloud/yandexcloud.go b/providers/dns/yandexcloud/yandexcloud.go index 97c003af..ee45ec43 100644 --- a/providers/dns/yandexcloud/yandexcloud.go +++ b/providers/dns/yandexcloud/yandexcloud.go @@ -75,11 +75,11 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { } if config.IamToken == "" { - return nil, fmt.Errorf("yandexcloud: some credentials information are missing IAM token") + return nil, errors.New("yandexcloud: some credentials information are missing IAM token") } if config.FolderID == "" { - return nil, fmt.Errorf("yandexcloud: some credentials information are missing folder id") + return nil, errors.New("yandexcloud: some credentials information are missing folder id") } creds, err := decodeCredentials(config.IamToken) diff --git a/providers/http/memcached/memcached_test.go b/providers/http/memcached/memcached_test.go index 3e687235..fb450f98 100644 --- a/providers/http/memcached/memcached_test.go +++ b/providers/http/memcached/memcached_test.go @@ -22,7 +22,7 @@ var memcachedHosts = loadMemcachedHosts() func loadMemcachedHosts() []string { memcachedHostsStr := os.Getenv("MEMCACHED_HOSTS") - if len(memcachedHostsStr) > 0 { + if memcachedHostsStr != "" { return strings.Split(memcachedHostsStr, ",") } return nil diff --git a/providers/http/s3/s3.go b/providers/http/s3/s3.go index d8fc4246..07e1eed6 100644 --- a/providers/http/s3/s3.go +++ b/providers/http/s3/s3.go @@ -4,6 +4,7 @@ package s3 import ( "bytes" "context" + "errors" "fmt" "strings" @@ -23,7 +24,7 @@ type HTTPProvider struct { // Credentials must be passed in the environment variables. func NewHTTPProvider(bucket string) (*HTTPProvider, error) { if bucket == "" { - return nil, fmt.Errorf("s3: bucket name missing") + return nil, errors.New("s3: bucket name missing") } ctx := context.Background()