1
0
mirror of https://github.com/go-acme/lego.git synced 2024-11-28 17:41:10 +02:00

chore: update linter. (#997)

This commit is contained in:
Ludovic Fernandez 2019-10-25 01:27:40 +02:00 committed by GitHub
parent 8afde164a1
commit 635b9ac93d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 23 additions and 44 deletions

View File

@ -29,7 +29,10 @@
"dupl",
"prealloc",
"scopelint",
"bodyclose", # https://github.com/timakin/bodyclose/pull/14
"bodyclose",
"wsl",
"stylecheck",
"godox",
]
[issues]
@ -112,3 +115,6 @@
[[issues.exclude-rules]]
path = "providers/dns/gandi/gandi.go"
text = "Function 'Present' is too long"
[[issues.exclude-rules]]
path = "cmd/zz_gen_cmd_dnshelp.go"
linters = ["gocyclo", "funlen"]

View File

@ -88,3 +88,5 @@ deploy:
local_dir: docs/public
skip_cleanup: true
github_token: ${GITHUB_TOKEN}
on:
condition: $STABLE = true

View File

@ -120,7 +120,6 @@ func (d *Doer) formatUserAgent() string {
func checkError(req *http.Request, resp *http.Response) error {
if resp.StatusCode >= http.StatusBadRequest {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("%d :: %s :: %s :: %v", resp.StatusCode, req.Method, req.URL, err)

View File

@ -44,7 +44,6 @@ func TestDo_UserAgentOnAllHTTPMethod(t *testing.T) {
for _, test := range testCases {
t.Run(test.method, func(t *testing.T) {
_, err := test.call(ts.URL)
require.NoError(t, err)

View File

@ -93,7 +93,6 @@ func TestChallenge_PreSolve(t *testing.T) {
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
chlg := NewChallenge(core, test.validate, test.provider, WrapPreCheck(test.preCheck))
authz := acme.Authorization{
@ -178,7 +177,6 @@ func TestChallenge_Solve(t *testing.T) {
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
var options []ChallengeOption
if test.preCheck != nil {
options = append(options, WrapPreCheck(test.preCheck))
@ -266,7 +264,6 @@ func TestChallenge_CleanUp(t *testing.T) {
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
chlg := NewChallenge(core, test.validate, test.provider, WrapPreCheck(test.preCheck))
authz := acme.Authorization{

View File

@ -188,7 +188,6 @@ func TestResolveConfServers(t *testing.T) {
for _, test := range testCases {
t.Run(test.fixture, func(t *testing.T) {
result := getNameservers(test.fixture, test.defaults)
sort.Strings(result)

View File

@ -78,8 +78,8 @@ func (m *forwardedMatcher) matches(r *http.Request, domain string) bool {
if err != nil {
return false
}
if len(fwds) == 0 {
if len(fwds) == 0 {
return false
}

View File

@ -110,7 +110,6 @@ func Test_needRenewal(t *testing.T) {
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
actual := needRenewal(test.x509Cert, "foo.com", test.days)
assert.Equal(t, test.expected, actual)

View File

@ -84,7 +84,6 @@ func displayDNSHelp(name string) error {
ew := &errWriter{w: w}
switch name {
case "acme-dns":
// generated from: providers/dns/acmedns/acmedns.toml
ew.writeln(`Configuration for Joohoi's ACME-DNS.`)

View File

@ -27,7 +27,7 @@ func displayDNSHelp(name string) error {
ew := &errWriter{w: w}
switch name {
{{ range $provider := .Providers }}
{{- range $provider := .Providers }}
case "{{ $provider.Code }}":
// generated from: {{ .GeneratedFrom }}
ew.writeln(`Configuration for {{ $provider.Name }}.`)

View File

@ -304,7 +304,6 @@ func TestGetOrFile_ReadsFiles(t *testing.T) {
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
err := os.Unsetenv(varEnvFileName)
require.NoError(t, err)
err = os.Unsetenv(varEnvName)

View File

@ -95,7 +95,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
_, zoneName, err := d.getHostedZone(domain)
zoneName, err := d.getHostedZone(domain)
if err != nil {
return fmt.Errorf("alicloud: %v", err)
}
@ -118,7 +118,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
return fmt.Errorf("alicloud: %v", err)
}
_, _, err = d.getHostedZone(domain)
_, err = d.getHostedZone(domain)
if err != nil {
return fmt.Errorf("alicloud: %v", err)
}
@ -134,7 +134,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
return nil
}
func (d *DNSProvider) getHostedZone(domain string) (string, string, error) {
func (d *DNSProvider) getHostedZone(domain string) (string, error) {
request := alidns.CreateDescribeDomainsRequest()
var domains []alidns.Domain
@ -145,7 +145,7 @@ func (d *DNSProvider) getHostedZone(domain string) (string, string, error) {
response, err := d.client.DescribeDomains(request)
if err != nil {
return "", "", fmt.Errorf("API call failed: %v", err)
return "", fmt.Errorf("API call failed: %v", err)
}
domains = append(domains, response.Domains.Domain...)
@ -159,7 +159,7 @@ func (d *DNSProvider) getHostedZone(domain string) (string, string, error) {
authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
if err != nil {
return "", "", err
return "", err
}
var hostedZone alidns.Domain
@ -170,9 +170,10 @@ func (d *DNSProvider) getHostedZone(domain string) (string, string, error) {
}
if hostedZone.DomainId == "" {
return "", "", fmt.Errorf("zone %s not found in AliDNS for domain %s", authZone, domain)
return "", fmt.Errorf("zone %s not found in AliDNS for domain %s", authZone, domain)
}
return fmt.Sprintf("%v", hostedZone.DomainId), hostedZone.DomainName, nil
return hostedZone.DomainName, nil
}
func (d *DNSProvider) newTxtRecord(zone, fqdn, value string) *alidns.AddDomainRecordRequest {
@ -186,7 +187,7 @@ func (d *DNSProvider) newTxtRecord(zone, fqdn, value string) *alidns.AddDomainRe
}
func (d *DNSProvider) findTxtRecords(domain, fqdn string) ([]alidns.Record, error) {
_, zoneName, err := d.getHostedZone(domain)
zoneName, err := d.getHostedZone(domain)
if err != nil {
return nil, err
}

View File

@ -106,7 +106,6 @@ func TestClientGetDomainInformation(t *testing.T) {
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
server := httptest.NewServer(handlerMock(http.MethodGet, test.response, test.data))
client, _ := NewClient("myKey", "mySecret")
@ -210,7 +209,6 @@ func TestClientFindTxtRecord(t *testing.T) {
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
server := httptest.NewServer(handlerMock(http.MethodGet, test.response, test.txtRecords))
client, _ := NewClient("myKey", "mySecret")

View File

@ -136,7 +136,6 @@ func TestClient_GetDomainID(t *testing.T) {
}
})
}
}
func TestClient_CreateRecord(t *testing.T) {
@ -203,8 +202,6 @@ func TestClient_CreateRecord(t *testing.T) {
} else {
require.NoError(t, err)
}
})
}
}

View File

@ -112,7 +112,6 @@ func TestNewDNSProviderConfig(t *testing.T) {
if test.baseURL != "" {
assert.Equal(t, test.baseURL, p.client.BaseURL)
}
} else {
require.EqualError(t, err, test.expected)
}

View File

@ -237,7 +237,7 @@ func TestDNSProvider_Cleanup_WhenHttpError_ReturnsError(t *testing.T) {
assert.Equal(t, "Basic VE9LRU46U0VDUkVU", r.Header.Get("Authorization"), "Authorization")
w.WriteHeader(http.StatusNotAcceptable)
_, err := fmt.Fprintf(w, errorMessage)
_, err := fmt.Fprint(w, errorMessage)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}

View File

@ -199,7 +199,6 @@ func TestSplitDomain(t *testing.T) {
assert.Equal(t, test.expectedZone, zone)
})
}
}
func TestLivePresent(t *testing.T) {

View File

@ -485,7 +485,6 @@ func Test_addTxtEntryToZone(t *testing.T) {
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
zone := addTxtEntryToZone(test.input, "_acme-challenge", "test", 120)
assert.Equal(t, zone, test.expected)
})
@ -527,7 +526,6 @@ func Test_fixTxtLines(t *testing.T) {
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
line := fixTxtLines(test.input)
assert.Equal(t, line, test.expected)
})

View File

@ -209,7 +209,6 @@ func TestDNSProvider_Present(t *testing.T) {
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
server := newMockServer(test.mockResponses)
defer server.Close()

View File

@ -226,7 +226,6 @@ func (c *Client) GetDNSRecords(hostname, apiSessionID string) ([]DNSRecord, erro
}
return responseData.DNSRecords, nil
}
// doRequest marshals given body to JSON, send the request to netcup API

View File

@ -515,7 +515,6 @@ func TestLiveClientAuth(t *testing.T) {
require.NoError(t, err)
})
}
}
func TestLiveClientGetDnsRecords(t *testing.T) {

View File

@ -81,7 +81,6 @@ func TestChangeResourceRecordSetsErrors(t *testing.T) {
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
server := runTestServer(test.responseBody, test.statusCode)
defer server.Close()
@ -161,7 +160,6 @@ func TestGetChangeErrors(t *testing.T) {
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
server := runTestServer(test.responseBody, test.statusCode)
defer server.Close()
@ -175,5 +173,4 @@ func TestGetChangeErrors(t *testing.T) {
assert.EqualError(t, err, test.expected)
})
}
}

View File

@ -79,7 +79,6 @@ func (m *DNSServerMock) HandleListZonesSuccessfully() {
"id":"123123"
}]}
`)
})
}

View File

@ -98,7 +98,6 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
token: identity.Access.Token.ID,
cloudDNSEndpoint: dnsEndpoint,
}, nil
}
// Present creates a TXT record to fulfill the dns-01 challenge

View File

@ -180,9 +180,7 @@ func (c *Client) do(req *http.Request, to interface{}) (*http.Response, error) {
}
func checkResponse(resp *http.Response) error {
if resp.StatusCode >= http.StatusBadRequest &&
resp.StatusCode <= http.StatusNetworkAuthenticationRequired {
if resp.StatusCode >= http.StatusBadRequest && resp.StatusCode <= http.StatusNetworkAuthenticationRequired {
if resp.Body == nil {
return fmt.Errorf("request failed with status code %d and empty body", resp.StatusCode)
}

View File

@ -180,9 +180,7 @@ func (c *Client) do(req *http.Request, to interface{}) (*http.Response, error) {
}
func checkResponse(resp *http.Response) error {
if resp.StatusCode >= http.StatusBadRequest &&
resp.StatusCode <= http.StatusNetworkAuthenticationRequired {
if resp.StatusCode >= http.StatusBadRequest && resp.StatusCode <= http.StatusNetworkAuthenticationRequired {
if resp.Body == nil {
return fmt.Errorf("request failed with status code %d and empty body", resp.StatusCode)
}