1
0
mirror of https://github.com/go-acme/lego.git synced 2024-12-23 01:07:23 +02:00

chore: update linter (#1708)

This commit is contained in:
Ludovic Fernandez 2022-09-02 09:05:52 +02:00 committed by GitHub
parent be0c6c743d
commit d99c75a08d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 33 additions and 37 deletions

View File

@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
GO_VERSION: 1.19 GO_VERSION: 1.19
GOLANGCI_LINT_VERSION: v1.48.0 GOLANGCI_LINT_VERSION: v1.49.0
HUGO_VERSION: 0.54.0 HUGO_VERSION: 0.54.0
CGO_ENABLED: 0 CGO_ENABLED: 0
LEGO_E2E_TESTS: CI LEGO_E2E_TESTS: CI

View File

@ -1,5 +1,5 @@
[run] [run]
deadline = "5m" timeout = "5m"
skip-files = [] skip-files = []
[linters-settings] [linters-settings]
@ -53,13 +53,16 @@
[linters] [linters]
enable-all = true enable-all = true
disable = [ disable = [
"deadcode", # deprecated
"exhaustivestruct", # deprecated
"golint", # deprecated
"ifshort", # deprecated
"interfacer", # deprecated "interfacer", # deprecated
"maligned", # deprecated "maligned", # deprecated
"scopelint", # deprecated
"golint", # deprecated
"nosnakecase", # deprecated "nosnakecase", # deprecated
"ifshort", # deprecated "scopelint", # deprecated
"exhaustivestruct", # deprecated "structcheck", # deprecated
"varcheck", # deprecated
"cyclop", # duplicate of gocyclo "cyclop", # duplicate of gocyclo
"sqlclosecheck", # not relevant (SQL) "sqlclosecheck", # not relevant (SQL)
"rowserrcheck", # not relevant (SQL) "rowserrcheck", # not relevant (SQL)
@ -102,7 +105,8 @@
exclude = [ exclude = [
"Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked", "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", "exported (type|method|function) (.+) should have comment or be unexported",
"ST1000: at least one file in a package should have a package comment" "ST1000: at least one file in a package should have a package comment",
"package-comments: should have a package comment",
] ]
[[issues.exclude-rules]] [[issues.exclude-rules]]
path = "(.+)_test.go" path = "(.+)_test.go"
@ -197,12 +201,3 @@
[[issues.exclude-rules]] [[issues.exclude-rules]]
path = "providers/dns/sakuracloud/client.go" path = "providers/dns/sakuracloud/client.go"
text = "mu is a global variable" text = "mu is a global variable"
[[issues.exclude-rules]]
path = "providers/dns/tencentcloud/client.go"
text = "RESOURCENOTFOUND_NODATAOFRECORD contains underscore."
[[issues.exclude-rules]]
path = "providers/dns/ibmcloud/internal/wrapper.go"
text = "Dns_Domain(_ResourceRecord)? contains underscore."
[[issues.exclude-rules]]
path = "providers/dns/rfc2136/"
text = "RR_Header contains underscore."

View File

@ -230,7 +230,7 @@ func (c *Client) doRequest(req *http.Request) ([]byte, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode >= 400 { if resp.StatusCode >= http.StatusBadRequest {
return nil, readError(req, resp) return nil, readError(req, resp)
} }

View File

@ -283,7 +283,7 @@ func (c *Client) doRequest(method string, uri *url.URL) (json.RawMessage, error)
return nil, errors.New(toUnreadableBodyMessage(req, content)) return nil, errors.New(toUnreadableBodyMessage(req, content))
} }
if resp.StatusCode != 200 { if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("invalid code (%d), error: %s", resp.StatusCode, content) return nil, fmt.Errorf("invalid code (%d), error: %s", resp.StatusCode, content)
} }

View File

@ -49,7 +49,7 @@ func (d *DNSProvider) removeTxtRecord(domain string, recordID int) error {
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode >= 400 { if resp.StatusCode >= http.StatusBadRequest {
return readError(req, resp) return readError(req, resp)
} }
@ -80,7 +80,7 @@ func (d *DNSProvider) addTxtRecord(fqdn, value string) (*txtRecordResponse, erro
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode >= 400 { if resp.StatusCode >= http.StatusBadRequest {
return nil, readError(req, resp) return nil, readError(req, resp)
} }

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"net/http"
"net/url" "net/url"
"github.com/go-acme/lego/v4/log" "github.com/go-acme/lego/v4/log"
@ -49,7 +50,7 @@ func (d *DNSProvider) updateTxtRecord(u fmt.Stringer) error {
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != 200 { if resp.StatusCode != http.StatusOK {
return fmt.Errorf("request failed with HTTP status code %d", resp.StatusCode) return fmt.Errorf("request failed with HTTP status code %d", resp.StatusCode)
} }

View File

@ -121,7 +121,7 @@ func (d *DNSProvider) sendRequest(method, resource string, payload interface{})
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode >= 500 { if resp.StatusCode >= http.StatusInternalServerError {
return nil, fmt.Errorf("API request failed with HTTP status code %d", resp.StatusCode) return nil, fmt.Errorf("API request failed with HTTP status code %d", resp.StatusCode)
} }
@ -131,9 +131,9 @@ func (d *DNSProvider) sendRequest(method, resource string, payload interface{})
return nil, err return nil, err
} }
if resp.StatusCode >= 400 { if resp.StatusCode >= http.StatusBadRequest {
return nil, fmt.Errorf("API request failed with HTTP status code %d: %s", resp.StatusCode, dynRes.Messages) return nil, fmt.Errorf("API request failed with HTTP status code %d: %s", resp.StatusCode, dynRes.Messages)
} else if resp.StatusCode == 307 { } else if resp.StatusCode == http.StatusTemporaryRedirect {
// TODO add support for HTTP 307 response and long running jobs // TODO add support for HTTP 307 response and long running jobs
return nil, errors.New("API request returned HTTP 307. This is currently unsupported") return nil, errors.New("API request returned HTTP 307. This is currently unsupported")
} }

View File

@ -163,11 +163,11 @@ func (d *DNSProvider) do(req *http.Request, v interface{}) error {
} }
func checkResponse(resp *http.Response) error { func checkResponse(resp *http.Response) error {
if resp.StatusCode == 404 && resp.Request.Method == http.MethodGet { if resp.StatusCode == http.StatusNotFound && resp.Request.Method == http.MethodGet {
return nil return nil
} }
if resp.StatusCode >= 400 { if resp.StatusCode >= http.StatusBadRequest {
data, err := readBody(resp) data, err := readBody(resp)
if err != nil { if err != nil {
return fmt.Errorf("%d [%s] request failed: %w", resp.StatusCode, http.StatusText(resp.StatusCode), err) return fmt.Errorf("%d [%s] request failed: %w", resp.StatusCode, http.StatusText(resp.StatusCode), err)

View File

@ -80,7 +80,7 @@ func (d *DNSProvider) sendRequest(method, resource string, payload interface{})
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode >= 400 { if resp.StatusCode >= http.StatusBadRequest {
return nil, fmt.Errorf("request failed with HTTP status code %d", resp.StatusCode) return nil, fmt.Errorf("request failed with HTTP status code %d", resp.StatusCode)
} }

View File

@ -154,7 +154,7 @@ func (c *Client) postRequest(cmd string, data url.Values) (*Response, error) {
return nil, err return nil, err
} }
if resp.StatusCode != 200 { if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("HTTP error %d [%s]: %v", resp.StatusCode, http.StatusText(resp.StatusCode), string(body)) return nil, fmt.Errorf("HTTP error %d [%s]: %v", resp.StatusCode, http.StatusText(resp.StatusCode), string(body))
} }

View File

@ -21,7 +21,7 @@ func (d *DNSProvider) doRequest(domain, value, cmd string) error {
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode >= 400 { if resp.StatusCode >= http.StatusBadRequest {
var content []byte var content []byte
content, err = io.ReadAll(resp.Body) content, err = io.ReadAll(resp.Body)
if err != nil { if err != nil {

View File

@ -169,7 +169,7 @@ func (d *DNSProvider) createTXTRecord(zone, leaf, value string) error {
return fmt.Errorf("createTXTRecord: %w", err) return fmt.Errorf("createTXTRecord: %w", err)
} }
if resp.StatusCode != 200 { if resp.StatusCode != http.StatusOK {
return fmt.Errorf("createTXTRecord: error in API: %d", resp.StatusCode) return fmt.Errorf("createTXTRecord: error in API: %d", resp.StatusCode)
} }
@ -221,7 +221,7 @@ func (d *DNSProvider) removeTXTRecord(zone, leaf, value string) error {
return fmt.Errorf("removeTXTRecord: %w", err) return fmt.Errorf("removeTXTRecord: %w", err)
} }
if resp.StatusCode != 200 { if resp.StatusCode != http.StatusOK {
return fmt.Errorf("removeTXTRecord: error in API: %d", resp.StatusCode) return fmt.Errorf("removeTXTRecord: error in API: %d", resp.StatusCode)
} }

View File

@ -110,7 +110,7 @@ func (d *DNSProvider) do(req *http.Request, out interface{}) error {
return err return err
} }
if resp.StatusCode >= 400 { if resp.StatusCode >= http.StatusBadRequest {
var body []byte var body []byte
body, err = readBody(resp) body, err = readBody(resp)
if err != nil { if err != nil {

View File

@ -132,7 +132,7 @@ func (d *DNSProvider) loginRequest() error {
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode >= 400 { if resp.StatusCode >= http.StatusBadRequest {
return fmt.Errorf("OTC API request failed with HTTP status code %d", resp.StatusCode) return fmt.Errorf("OTC API request failed with HTTP status code %d", resp.StatusCode)
} }
@ -253,7 +253,7 @@ func (d *DNSProvider) sendRequest(method, resource string, payload interface{})
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode >= 400 { if resp.StatusCode >= http.StatusBadRequest {
return nil, fmt.Errorf("OTC API request %s failed with HTTP status code %d", url, resp.StatusCode) return nil, fmt.Errorf("OTC API request %s failed with HTTP status code %d", url, resp.StatusCode)
} }

View File

@ -94,7 +94,7 @@ func (c *Client) RemoveRecord(zone string, recordID int) error {
} }
defer func() { _ = resp.Body.Close() }() defer func() { _ = resp.Body.Close() }()
if resp.StatusCode >= 400 { if resp.StatusCode >= http.StatusBadRequest {
return readError(req, resp) return readError(req, resp)
} }

View File

@ -60,7 +60,7 @@ func (c *Client) CreateRecord(zone string, record Record) (*CreateRecordResponse
} }
defer func() { _ = resp.Body.Close() }() defer func() { _ = resp.Body.Close() }()
if resp.StatusCode >= 400 { if resp.StatusCode >= http.StatusBadRequest {
return nil, readError(req, resp) return nil, readError(req, resp)
} }
@ -98,7 +98,7 @@ func (c *Client) DeleteRecord(zone string, recordID string) error {
} }
defer func() { _ = resp.Body.Close() }() defer func() { _ = resp.Body.Close() }()
if resp.StatusCode >= 400 { if resp.StatusCode >= http.StatusBadRequest {
return readError(req, resp) return readError(req, resp)
} }