chore: update linter. (#1214)

This commit is contained in:
Ludovic Fernandez 2020-07-10 01:48:18 +02:00 committed by GitHub
parent 23328fcdd2
commit 6b00497f34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
56 changed files with 119 additions and 102 deletions

View file

@ -37,6 +37,7 @@
"testpackage", # not relevant
"nestif", # too many false-positive
"goerr113", # not relevant
"noctx",
]
[issues]
@ -49,7 +50,7 @@
]
[[issues.exclude-rules]]
path = "(.+)_test.go"
linters = ["funlen"]
linters = ["funlen", "goconst"]
[[issues.exclude-rules]]
path = "providers/dns/dns_providers.go"
linters = ["gocyclo"]

View file

@ -28,7 +28,7 @@ func (a *AccountService) New(req acme.Account) (acme.ExtendedAccount, error) {
}
// NewEAB Creates a new account with an External Account Binding.
func (a *AccountService) NewEAB(accMsg acme.Account, kid string, hmacEncoded string) (acme.ExtendedAccount, error) {
func (a *AccountService) NewEAB(accMsg acme.Account, kid, hmacEncoded string) (acme.ExtendedAccount, error) {
hmac, err := base64.RawURLEncoding.DecodeString(hmacEncoded)
if err != nil {
return acme.ExtendedAccount{}, fmt.Errorf("acme: could not decode hmac key: %w", err)

View file

@ -35,7 +35,7 @@ type Core struct {
}
// New Creates a new Core.
func New(httpClient *http.Client, userAgent string, caDirURL, kid string, privateKey crypto.PrivateKey) (*Core, error) {
func New(httpClient *http.Client, userAgent, caDirURL, kid string, privateKey crypto.PrivateKey) (*Core, error) {
doer := sender.NewDoer(httpClient, userAgent)
dir, err := getDirectory(doer, caDirURL)

View file

@ -11,7 +11,7 @@ type service struct {
// getLink get a rel into the Link header.
func getLink(header http.Header, rel string) string {
var linkExpr = regexp.MustCompile(`<(.+?)>;\s*rel="(.+?)"`)
linkExpr := regexp.MustCompile(`<(.+?)>;\s*rel="(.+?)"`)
for _, link := range header["Link"] {
for _, m := range linkExpr.FindAllStringSubmatch(link, -1) {

View file

@ -232,7 +232,7 @@ func (c *Certifier) getForOrder(domains []string, order acme.ExtendedOrder, bund
return c.getForCSR(domains, order, bundle, csr, certcrypto.PEMEncode(privateKey))
}
func (c *Certifier) getForCSR(domains []string, order acme.ExtendedOrder, bundle bool, csr []byte, privateKeyPem []byte) (*Resource, error) {
func (c *Certifier) getForCSR(domains []string, order acme.ExtendedOrder, bundle bool, csr, privateKeyPem []byte) (*Resource, error) {
respOrder, err := c.core.Orders.UpdateForCSR(order.Finalize, csr)
if err != nil {
return nil, err

View file

@ -172,7 +172,7 @@ type sequential interface {
}
// GetRecord returns a DNS record which will fulfill the `dns-01` challenge.
func GetRecord(domain, keyAuth string) (fqdn string, value string) {
func GetRecord(domain, keyAuth string) (fqdn, value string) {
keyAuthShaBytes := sha256.Sum256([]byte(keyAuth))
// base64URL encoding without padding
value = base64.RawURLEncoding.EncodeToString(keyAuthShaBytes[:sha256.Size])

View file

@ -169,7 +169,7 @@ func TestFindPrimayNsByFqdnCustom(t *testing.T) {
}
func TestResolveConfServers(t *testing.T) {
var testCases = []struct {
testCases := []struct {
fixture string
expected []string
defaults []string

View file

@ -126,7 +126,7 @@ func TestChallengeWithProxy(t *testing.T) {
nook = "example.com"
)
var testCases = []struct {
testCases := []struct {
name string
header *testProxyHeader
extra *testProxyHeader

View file

@ -16,9 +16,11 @@ type preSolverMock struct {
func (s *preSolverMock) PreSolve(authorization acme.Authorization) error {
return s.preSolve[authorization.Identifier.Value]
}
func (s *preSolverMock) Solve(authorization acme.Authorization) error {
return s.solve[authorization.Identifier.Value]
}
func (s *preSolverMock) CleanUp(authorization acme.Authorization) error {
return s.cleanUp[authorization.Identifier.Value]
}

View file

@ -199,7 +199,7 @@ func needRenewal(x509Cert *x509.Certificate, domain string, days int) bool {
return true
}
func merge(prevDomains []string, nextDomains []string) []string {
func merge(prevDomains, nextDomains []string) []string {
for _, next := range nextDomains {
var found bool
for _, prev := range prevDomains {

View file

@ -13,9 +13,7 @@ import (
"github.com/urfave/cli"
)
var (
version = "dev"
)
var version = "dev"
func main() {
app := cli.NewApp()

View file

@ -16,7 +16,7 @@ import (
"github.com/urfave/cli"
)
const filePerm os.FileMode = 0600
const filePerm os.FileMode = 0o600
func setup(ctx *cli.Context, accountsStorage *AccountsStorage) (*Account, *lego.Client) {
keyType := getKeyType(ctx)
@ -90,7 +90,7 @@ func getEmail(ctx *cli.Context) string {
func createNonExistingFolder(path string) error {
if _, err := os.Stat(path); os.IsNotExist(err) {
return os.MkdirAll(path, 0700)
return os.MkdirAll(path, 0o700)
} else if err != nil {
return err
}

View file

@ -201,7 +201,7 @@ func generateReadMe(models *Providers) error {
return errors.New("missing end tag")
}
return ioutil.WriteFile(readmePath, buffer.Bytes(), 0666)
return ioutil.WriteFile(readmePath, buffer.Bytes(), 0o666)
}
func extractTableData(models *Providers) (int, [][]string) {

View file

@ -166,7 +166,7 @@ func readUserAgentFile(filename string) (map[string]string, error) {
return v.data, nil
}
func writeUserAgentFile(filename string, version string, comment string) error {
func writeUserAgentFile(filename, version, comment string) error {
tmpl, err := template.New("ua").Parse(uaTemplate)
if err != nil {
return err
@ -186,10 +186,10 @@ func writeUserAgentFile(filename string, version string, comment string) error {
return err
}
return ioutil.WriteFile(filename, source, 0644)
return ioutil.WriteFile(filename, source, 0o644)
}
func bumpVersion(userAgent string, mode string) (string, error) {
func bumpVersion(userAgent, mode string) (string, error) {
prevVersion := strings.TrimPrefix(userAgent, "xenolf-acme/")
allString := regexp.MustCompile(`(\d+)\.(\d+)\.(\d+)`).FindStringSubmatch(prevVersion)

View file

@ -118,7 +118,7 @@ func GetOrDefaultSecond(envVar string, defaultValue time.Duration) time.Duration
// GetOrDefaultString returns the given environment variable value as a string.
// Returns the default if the envvar cannot be find.
func GetOrDefaultString(envVar string, defaultValue string) string {
func GetOrDefaultString(envVar, defaultValue string) string {
v := GetOrFile(envVar)
if len(v) == 0 {
return defaultValue

View file

@ -186,7 +186,7 @@ func TestGetOrDefaultSecond(t *testing.T) {
},
}
var key = "LEGO_ENV_TC"
key := "LEGO_ENV_TC"
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
@ -220,7 +220,7 @@ func TestGetOrDefaultString(t *testing.T) {
},
}
var key = "LEGO_ENV_TC"
key := "LEGO_ENV_TC"
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
@ -260,7 +260,7 @@ func TestGetOrDefaultBool(t *testing.T) {
},
}
var key = "LEGO_ENV_TC"
key := "LEGO_ENV_TC"
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
@ -313,7 +313,7 @@ func TestGetOrFile_ReadsFiles(t *testing.T) {
require.NoError(t, err)
defer os.Remove(file.Name())
err = ioutil.WriteFile(file.Name(), []byte("lego_file\n"), 0644)
err = ioutil.WriteFile(file.Name(), []byte("lego_file\n"), 0o644)
require.NoError(t, err)
err = os.Setenv(varEnvFileName, file.Name())
@ -340,7 +340,7 @@ func TestGetOrFile_PrefersEnvVars(t *testing.T) {
require.NoError(t, err)
defer os.Remove(file.Name())
err = ioutil.WriteFile(file.Name(), []byte("lego_file"), 0644)
err = ioutil.WriteFile(file.Name(), []byte("lego_file"), 0o644)
require.NoError(t, err)
err = os.Setenv(varEnvFileName, file.Name())

View file

@ -49,7 +49,7 @@ func NewDNSProvider() (*DNSProvider, error) {
}
client := goacmedns.NewClient(values[EnvAPIBase])
storage := goacmedns.NewFileStorage(values[EnvStoragePath], 0600)
storage := goacmedns.NewFileStorage(values[EnvStoragePath], 0o600)
return NewDNSProviderClient(client, storage)
}

View file

@ -235,6 +235,7 @@ func (m *MockHTTPClientAPI) Post(url string, data []byte) (*http.Response, []byt
func (m *MockHTTPClientAPI) Get(url string) (*http.Response, []byte, error) {
return &http.Response{StatusCode: m.Status}, m.Data, m.Error
}
func (m *MockHTTPClientAPI) Delete(url string) (*http.Response, []byte, error) {
return &http.Response{StatusCode: m.Status}, m.Data, m.Error
}

View file

@ -29,7 +29,7 @@ type Client struct {
}
// NewClient returns a Client instance configured to handle CloudDNS API communication.
func NewClient(clientID string, email string, password string, ttl int) *Client {
func NewClient(clientID, email, password string, ttl int) *Client {
return &Client{
ClientID: clientID,
Email: email,

View file

@ -41,7 +41,7 @@ type TXTRecord struct {
type TXTRecords map[string]TXTRecord
// NewClient creates a ClouDNS client.
func NewClient(authID string, subAuthID string, authPassword string) (*Client, error) {
func NewClient(authID, subAuthID, authPassword string) (*Client, error) {
if authID == "" && subAuthID == "" {
return nil, errors.New("credentials missing: authID or subAuthID")
}
@ -147,7 +147,7 @@ func (c *Client) FindTxtRecord(zoneName, fqdn string) (*TXTRecord, error) {
}
// AddTxtRecord add a TXT record.
func (c *Client) AddTxtRecord(zoneName string, fqdn, value string, ttl int) error {
func (c *Client) AddTxtRecord(zoneName, fqdn, value string, ttl int) error {
host := dns01.UnFqdn(strings.TrimSuffix(dns01.UnFqdn(fqdn), zoneName))
reqURL := *c.BaseURL

View file

@ -44,7 +44,7 @@ type TXTRecord struct {
}
// NewClient creates a CloudXNS client.
func NewClient(apiKey string, secretKey string) (*Client, error) {
func NewClient(apiKey, secretKey string) (*Client, error) {
if apiKey == "" {
return nil, errors.New("CloudXNS: credentials missing: apiKey")
}

View file

@ -188,7 +188,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
return nil
}
func (d *DNSProvider) createRecord(dom internal.Domain, fqdn string, recordName string, value string) error {
func (d *DNSProvider) createRecord(dom internal.Domain, fqdn, recordName, value string) error {
request := internal.RecordRequest{
Name: recordName,
TTL: d.config.TTL,

View file

@ -31,7 +31,7 @@ func NewClient(token string) *Client {
// GetTxtRRSet gets a RRSet.
// https://desec.readthedocs.io/en/latest/dns/rrsets.html#retrieving-a-specific-rrset
func (c *Client) GetTxtRRSet(domainName string, subName string) (*RRSet, error) {
func (c *Client) GetTxtRRSet(domainName, subName string) (*RRSet, error) {
if subName == "" {
subName = "@"
}
@ -128,7 +128,7 @@ func (c *Client) AddTxtRRSet(rrSet RRSet) (*RRSet, error) {
// UpdateTxtRRSet updates RRSet records.
// https://desec.readthedocs.io/en/latest/dns/rrsets.html#modifying-an-rrset
func (c *Client) UpdateTxtRRSet(domainName string, subName string, records []string) (*RRSet, error) {
func (c *Client) UpdateTxtRRSet(domainName, subName string, records []string) (*RRSet, error) {
if subName == "" {
subName = "@"
}
@ -181,7 +181,7 @@ func (c *Client) UpdateTxtRRSet(domainName string, subName string, records []str
// DeleteTxtRRSet deletes a RRset.
// https://desec.readthedocs.io/en/latest/dns/rrsets.html#deleting-an-rrset
func (c *Client) DeleteTxtRRSet(domainName string, subName string) error {
func (c *Client) DeleteTxtRRSet(domainName, subName string) error {
if subName == "" {
subName = "@"
}

View file

@ -247,7 +247,7 @@ func (d *DNSProvider) getZoneID(wanted string) (string, error) {
return "", fmt.Errorf("zone id not found for %s", wanted)
}
func (d *DNSProvider) getRecord(zoneID string, wanted string) (*recordsets.RecordSet, error) {
func (d *DNSProvider) getRecord(zoneID, wanted string) (*recordsets.RecordSet, error) {
allPages, err := recordsets.ListByZone(d.client, zoneID, nil).AllPages()
if err != nil {
return nil, err

View file

@ -42,7 +42,7 @@ type Client struct {
}
// NewClient creates a DNSMadeEasy client.
func NewClient(apiKey string, apiSecret string) (*Client, error) {
func NewClient(apiKey, apiSecret string) (*Client, error) {
if apiKey == "" {
return nil, errors.New("credentials missing: API key")
}
@ -163,7 +163,7 @@ func (c *Client) sendRequest(method, resource string, payload interface{}) (*htt
return resp, nil
}
func computeHMAC(message string, secret string) (string, error) {
func computeHMAC(message, secret string) (string, error) {
key := []byte(secret)
h := hmac.New(sha1.New, key)
_, err := h.Write([]byte(message))

View file

@ -33,7 +33,7 @@ func NewClient() *Client {
}
// GetRecords Get DNS records based on a hostname and resource record type.
func (c Client) GetRecords(hostname string, recordType string) ([]DNSRecord, error) {
func (c Client) GetRecords(hostname, recordType string) ([]DNSRecord, error) {
endpoint, err := c.createEndpoint("dns", "record", hostname)
if err != nil {
return nil, err
@ -82,7 +82,7 @@ func (c Client) AddNewRecord(domainID int64, record DNSRecord) error {
}
// DeleteRecord Remove a DNS record from DNS service.
func (c Client) DeleteRecord(domainID int64, recordID int64) error {
func (c Client) DeleteRecord(domainID, recordID int64) error {
endpoint, err := c.createEndpoint("dns", strconv.FormatInt(domainID, 10), "record", strconv.FormatInt(recordID, 10))
if err != nil {
return err

View file

@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"
)
func setupTest(method string, pattern string, status int, file string) *Client {
func setupTest(method, pattern string, status int, file string) *Client {
mux := http.NewServeMux()
server := httptest.NewServer(mux)
@ -126,7 +126,8 @@ func TestGetRecords(t *testing.T) {
status: http.StatusOK,
file: "./fixtures/get_records.json",
expected: expected{
records: []DNSRecord{{
records: []DNSRecord{
{
ID: 6041417,
Type: "TXT",
DomainID: 9007481,

View file

@ -28,14 +28,17 @@ type paramInt struct {
type structMember interface {
structMember()
}
type structMemberString struct {
Name string `xml:"name"`
Value string `xml:"value>string"`
}
type structMemberInt struct {
Name string `xml:"name"`
Value int `xml:"value>int"`
}
type paramStruct struct {
XMLName xml.Name `xml:"param"`
StructMembers []structMember `xml:"value>struct>member"`
@ -120,7 +123,8 @@ func (d *DNSProvider) rpcCall(call *methodCall, resp response) error {
}
if resp.faultCode() != 0 {
return rpcError{
faultCode: resp.faultCode(), faultString: resp.faultString()}
faultCode: resp.faultCode(), faultString: resp.faultString(),
}
}
return nil
}
@ -166,7 +170,8 @@ func (d *DNSProvider) cloneZone(zoneID int, name string) (int, error) {
structMemberString{
Name: "name",
Value: name,
}},
},
},
},
},
}, resp)
@ -206,7 +211,7 @@ func (d *DNSProvider) newZoneVersion(zoneID int) (int, error) {
return resp.Value, nil
}
func (d *DNSProvider) addTXTRecord(zoneID int, version int, name string, value string, ttl int) error {
func (d *DNSProvider) addTXTRecord(zoneID, version int, name, value string, ttl int) error {
resp := &responseStruct{}
err := d.rpcCall(&methodCall{
MethodName: "domain.zone.record.add",
@ -228,14 +233,15 @@ func (d *DNSProvider) addTXTRecord(zoneID int, version int, name string, value s
}, structMemberInt{
Name: "ttl",
Value: ttl,
}},
},
},
},
},
}, resp)
return err
}
func (d *DNSProvider) setZoneVersion(zoneID int, version int) error {
func (d *DNSProvider) setZoneVersion(zoneID, version int) error {
resp := &responseBool{}
err := d.rpcCall(&methodCall{
MethodName: "domain.zone.version.set",
@ -301,7 +307,7 @@ func (d *DNSProvider) deleteZone(zoneID int) error {
return nil
}
func (d *DNSProvider) httpPost(url string, bodyType string, body io.Reader) ([]byte, error) {
func (d *DNSProvider) httpPost(url, bodyType string, body io.Reader) ([]byte, error) {
resp, err := d.config.HTTPClient.Post(url, bodyType, body)
if err != nil {
return nil, fmt.Errorf("HTTP Post Error: %w", err)

View file

@ -101,7 +101,7 @@ func TestDNSProvider(t *testing.T) {
// fake RPC server. It was generated by recording a real RPC session
// which resulted in the successful issue of a cert, and then
// anonymizing the RPC data.
var serverResponses = map[string]string{
serverResponses := map[string]string{
// Present Request->Response 1 (getZoneID)
presentGetZoneIDRequestMock: presentGetZoneIDResponseMock,
// Present Request->Response 2 (cloneZone)

View file

@ -27,7 +27,7 @@ type Record struct {
RRSetType string `json:"rrset_type,omitempty"`
}
func (d *DNSProvider) addTXTRecord(domain string, name string, value string, ttl int) error {
func (d *DNSProvider) addTXTRecord(domain, name, value string, ttl int) error {
// Get exiting values for the TXT records
// Needed to create challenges for both wildcard and base name domains
txtRecord, err := d.getTXTRecord(domain, name)
@ -80,7 +80,7 @@ func (d *DNSProvider) getTXTRecord(domain, name string) (*Record, error) {
return txtRecord, nil
}
func (d *DNSProvider) deleteTXTRecord(domain string, name string) error {
func (d *DNSProvider) deleteTXTRecord(domain, name string) error {
target := fmt.Sprintf("domains/%s/records/%s/TXT", domain, name)
req, err := d.newRequest(http.MethodDelete, target, nil)

View file

@ -97,7 +97,7 @@ func TestNewDNSProviderConfig(t *testing.T) {
func TestDNSProvider(t *testing.T) {
// serverResponses is the JSON Request->Response map used by the
// fake JSON server.
var serverResponses = map[string]map[string]string{
serverResponses := map[string]map[string]string{
http.MethodGet: {
``: `{"rrset_ttl":300,"rrset_values":[],"rrset_name":"_acme-challenge.abc.def","rrset_type":"TXT"}`,
},

View file

@ -32,7 +32,7 @@ type responseStruct struct {
} `json:"response"`
}
func (d *DNSProvider) addTXTRecord(fqdn string, domain string, name string, value string, ttl int) (int, error) {
func (d *DNSProvider) addTXTRecord(fqdn, domain, name, value string, ttl int) (int, error) {
response, err := d.sendRequest(http.MethodPost, "addrecord", addRecordRequest{
DomainName: domain,
Host: name,
@ -58,7 +58,7 @@ func (d *DNSProvider) deleteTXTRecord(fqdn string, recordid int) error {
return err
}
func (d *DNSProvider) sendRequest(method string, resource string, payload interface{}) (*responseStruct, error) {
func (d *DNSProvider) sendRequest(method, resource string, payload interface{}) (*responseStruct, error) {
url := fmt.Sprintf("%s/%s", defaultBaseURL, resource)
body, err := json.Marshal(payload)

View file

@ -19,7 +19,7 @@ type DNSRecord struct {
TTL int `json:"ttl,omitempty"`
}
func (d *DNSProvider) getRecords(domainZone string, rType string, recordName string) ([]DNSRecord, error) {
func (d *DNSProvider) getRecords(domainZone, rType, recordName string) ([]DNSRecord, error) {
resource := path.Clean(fmt.Sprintf("/v1/domains/%s/records/%s/%s", domainZone, rType, recordName))
resp, err := d.makeRequest(http.MethodGet, resource, nil)
@ -44,7 +44,7 @@ func (d *DNSProvider) getRecords(domainZone string, rType string, recordName str
return records, nil
}
func (d *DNSProvider) updateTxtRecords(records []DNSRecord, domainZone string, recordName string) error {
func (d *DNSProvider) updateTxtRecords(records []DNSRecord, domainZone, recordName string) error {
body, err := json.Marshal(records)
if err != nil {
return err

View file

@ -91,7 +91,7 @@ func (d *DNSProvider) getZone(findRequest ZoneConfigsFindRequest) (*ZoneConfig,
return zoneConfig, nil
}
func (d *DNSProvider) post(uri string, request interface{}, response interface{}) ([]byte, error) {
func (d *DNSProvider) post(uri string, request, response interface{}) ([]byte, error) {
body, err := json.Marshal(request)
if err != nil {
return nil, err

View file

@ -105,7 +105,7 @@ func (c Client) toMultiParameters(params []ActionParameter) multiActionParameter
return multi
}
func (c Client) do(params interface{}, data interface{}) error {
func (c Client) do(params, data interface{}) error {
baseURL, err := url.Parse(c.BaseURL)
if err != nil {
return err
@ -157,7 +157,7 @@ func (c Client) do(params interface{}, data interface{}) error {
}
// AddRecord helper to create an action to add a TXT record.
func AddRecord(domain string, content string, ttl int) ActionParameter {
func AddRecord(domain, content string, ttl int) ActionParameter {
return ActionParameter{
Action: SetAction,
Name: domain,
@ -168,7 +168,7 @@ func AddRecord(domain string, content string, ttl int) ActionParameter {
}
// DeleteRecord helper to create an action to delete a TXT record.
func DeleteRecord(domain string, content string) ActionParameter {
func DeleteRecord(domain, content string) ActionParameter {
return ActionParameter{
Action: DeleteAction,
Name: domain,

View file

@ -144,7 +144,8 @@ func TestClient_DoActions(t *testing.T) {
TTL: "3600 seconds",
Priority: "0",
}},
}},
},
},
},
},
},
@ -182,7 +183,9 @@ func TestClient_DoActions(t *testing.T) {
Priority: "0",
},
},
}}},
},
},
},
},
},
{
@ -214,7 +217,9 @@ func TestClient_DoActions(t *testing.T) {
Host: "example.org",
Type: "TXT",
Records: nil,
}}},
},
},
},
},
},
{
@ -241,7 +246,9 @@ func TestClient_DoActions(t *testing.T) {
TTL: "3600 seconds",
Priority: "0",
}},
}}},
},
},
},
},
},
}

View file

@ -116,7 +116,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
return fmt.Errorf("inwx: %w", err)
}
var request = &goinwx.NameserverRecordRequest{
request := &goinwx.NameserverRecordRequest{
Domain: dns01.UnFqdn(authZone),
Name: dns01.UnFqdn(fqdn),
Type: "TXT",

View file

@ -255,7 +255,7 @@ func TestDNSProvider_logout(t *testing.T) {
}
func TestDNSProvider_getZone(t *testing.T) {
var testZone = "@ A 0 192.0.2.2 3600"
testZone := "@ A 0 192.0.2.2 3600"
testCases := []struct {
desc string

View file

@ -150,7 +150,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
return d.config.PropagationTimeout, d.config.PollingInterval
}
func (d *DNSProvider) newTxtRecord(fqdn string, value string) error {
func (d *DNSProvider) newTxtRecord(fqdn, value string) error {
params := &lightsail.CreateDomainEntryInput{
DomainName: aws.String(d.config.DNSZone),
DomainEntry: &lightsail.DomainEntry{

View file

@ -8,7 +8,7 @@ import (
"strings"
)
func (d *DNSProvider) doRequest(domain, value string, cmd string) error {
func (d *DNSProvider) doRequest(domain, value, cmd string) error {
req, err := d.buildRequest(domain, value, cmd)
if err != nil {
return err
@ -34,7 +34,7 @@ func (d *DNSProvider) doRequest(domain, value string, cmd string) error {
return nil
}
func (d *DNSProvider) buildRequest(domain, value string, cmd string) (*http.Request, error) {
func (d *DNSProvider) buildRequest(domain, value, cmd string) (*http.Request, error) {
params := url.Values{}
params.Set("CERTBOT_DOMAIN", domain)
params.Set("CERTBOT_VALIDATION", value)

View file

@ -120,7 +120,7 @@ func (d *DNSProvider) login() error {
}
// https://www.mythic-beasts.com/support/api/dnsv2#ep-get-zoneszonerecords
func (d *DNSProvider) createTXTRecord(zone string, leaf string, value string) error {
func (d *DNSProvider) createTXTRecord(zone, leaf, value string) error {
if d.token == "" {
return fmt.Errorf("createTXTRecord: not logged in")
}
@ -183,7 +183,7 @@ func (d *DNSProvider) createTXTRecord(zone string, leaf string, value string) er
}
// https://www.mythic-beasts.com/support/api/dnsv2#ep-delete-zoneszonerecords
func (d *DNSProvider) removeTXTRecord(zone string, leaf string, value string) error {
func (d *DNSProvider) removeTXTRecord(zone, leaf, value string) error {
if d.token == "" {
return fmt.Errorf("removeTXTRecord: not logged in")
}

View file

@ -122,7 +122,7 @@ type Client struct {
}
// NewClient creates a netcup DNS client.
func NewClient(customerNumber string, apiKey string, apiPassword string) (*Client, error) {
func NewClient(customerNumber, apiKey, apiPassword string) (*Client, error) {
if customerNumber == "" || apiKey == "" || apiPassword == "" {
return nil, errors.New("credentials missing")
}
@ -231,7 +231,7 @@ func (c *Client) GetDNSRecords(hostname, apiSessionID string) ([]DNSRecord, erro
// doRequest marshals given body to JSON, send the request to netcup API
// and returns body of response.
func (c *Client) doRequest(payload interface{}, responseData interface{}) error {
func (c *Client) doRequest(payload, responseData interface{}) error {
body, err := json.Marshal(payload)
if err != nil {
return err

View file

@ -116,7 +116,7 @@ func (c *Client) CreateRecord(zoneID string, record DNSRecord) (*DNSRecord, erro
}
// RemoveRecord removes a DNS records.
func (c *Client) RemoveRecord(zoneID string, recordID string) error {
func (c *Client) RemoveRecord(zoneID, recordID string) error {
endpoint, err := c.createEndpoint("dns_zones", zoneID, "dns_records", recordID)
if err != nil {
return fmt.Errorf("failed to parse endpoint: %w", err)

View file

@ -88,7 +88,7 @@ type ChangeInfo struct {
}
// NewClient Creates a new client of NIFCLOUD DNS.
func NewClient(accessKey string, secretKey string) (*Client, error) {
func NewClient(accessKey, secretKey string) (*Client, error) {
if len(accessKey) == 0 || len(secretKey) == 0 {
return nil, errors.New("credentials missing")
}

View file

@ -193,7 +193,7 @@ func (d *DNSProvider) getZoneID(zone string) (string, error) {
return zonesRes.Zones[0].ID, nil
}
func (d *DNSProvider) getRecordSetID(zoneID string, fqdn string) (string, error) {
func (d *DNSProvider) getRecordSetID(zoneID, fqdn string) (string, error) {
resource := fmt.Sprintf("zones/%s/recordsets?type=TXT&name=%s", zoneID, fqdn)
resp, err := d.sendRequest(http.MethodGet, resource, nil)
if err != nil {

View file

@ -195,7 +195,7 @@ func (d *DNSProvider) sendRequest(method, uri string, body io.Reader) (json.RawM
}
func (d *DNSProvider) makeRequest(method, uri string, body io.Reader) (*http.Request, error) {
var path = ""
path := ""
if d.config.Host.Path != "/" {
path = d.config.Host.Path
}

View file

@ -21,7 +21,7 @@ type Client struct {
}
// NewClient Creates a reg.ru client.
func NewClient(username string, password string) *Client {
func NewClient(username, password string) *Client {
return &Client{
username: username,
password: password,
@ -32,7 +32,7 @@ func NewClient(username string, password string) *Client {
// RemoveTxtRecord removes a TXT record.
// https://www.reg.ru/support/help/api2#zone_remove_record
func (c Client) RemoveTxtRecord(domain, subDomain string, content string) error {
func (c Client) RemoveTxtRecord(domain, subDomain, content string) error {
request := RemoveRecordRequest{
Username: c.username,
Password: c.password,
@ -55,7 +55,7 @@ func (c Client) RemoveTxtRecord(domain, subDomain string, content string) error
// AddTXTRecord adds a TXT record.
// https://www.reg.ru/support/help/api2#zone_add_txt
func (c Client) AddTXTRecord(domain, subDomain string, content string) error {
func (c Client) AddTXTRecord(domain, subDomain, content string) error {
request := AddTxtRequest{
Username: c.username,
Password: c.password,

View file

@ -111,7 +111,7 @@ func TestTsigClient(t *testing.T) {
}
func TestValidUpdatePacket(t *testing.T) {
var reqChan = make(chan *dns.Msg, 10)
reqChan := make(chan *dns.Msg, 10)
dns01.ClearFqdnCache()
dns.HandleFunc(fakeZone, serverHandlerPassBackRequest(reqChan))
@ -170,7 +170,8 @@ func runLocalDNSTestServer(tsig bool) (*dns.Server, string, error) {
MsgAcceptFunc: func(dh dns.Header) dns.MsgAcceptAction {
// bypass defaultMsgAcceptFunc to allow dynamic update (https://github.com/miekg/dns/pull/830)
return dns.MsgAccept
}}
},
}
if tsig {
server.TsigSecret = map[string]string{fakeTsigKey: fakeTsigSecret}

View file

@ -231,7 +231,7 @@ func (d *DNSProvider) changeRecord(action, hostedZoneID string, recordSet *route
})
}
func (d *DNSProvider) getExistingRecordSets(hostedZoneID string, fqdn string) ([]*route53.ResourceRecord, error) {
func (d *DNSProvider) getExistingRecordSets(hostedZoneID, fqdn string) ([]*route53.ResourceRecord, error) {
listInput := &route53.ListResourceRecordSetsInput{
HostedZoneId: aws.String(hostedZoneID),
StartRecordName: aws.String(fqdn),

View file

@ -13,7 +13,7 @@ import (
const cleanUpDelay = 2 * time.Second
func TestNewDNSProvider(t *testing.T) {
var envTest = tester.NewEnvTest(EnvAPIToken, EnvTTL)
envTest := tester.NewEnvTest(EnvAPIToken, EnvTTL)
testCases := []struct {
desc string
@ -97,7 +97,7 @@ func TestNewDNSProviderConfig(t *testing.T) {
}
func TestLivePresent(t *testing.T) {
var envTest = tester.NewEnvTest(EnvAPIToken, EnvTTL)
envTest := tester.NewEnvTest(EnvAPIToken, EnvTTL)
if !envTest.IsLiveTest() {
t.Skip("skipping live test")
@ -112,7 +112,7 @@ func TestLivePresent(t *testing.T) {
}
func TestLiveCleanUp(t *testing.T) {
var envTest = tester.NewEnvTest(EnvAPIToken, EnvTTL)
envTest := tester.NewEnvTest(EnvAPIToken, EnvTTL)
if !envTest.IsLiveTest() {
t.Skip("skipping live test")

View file

@ -178,7 +178,7 @@ func TestDNSProvider_concurrentGetDNSEntries(t *testing.T) {
var wg sync.WaitGroup
wg.Add(2)
solve := func(domain1 string, suffix string, timeoutPresent time.Duration, timeoutSolve time.Duration, timeoutCleanup time.Duration) error {
solve := func(domain1, suffix string, timeoutPresent, timeoutSolve, timeoutCleanup time.Duration) error {
time.Sleep(timeoutPresent)
err := p.Present(domain1, "", "")
@ -234,7 +234,7 @@ func TestDNSProvider_concurrentAddDNSEntry(t *testing.T) {
var wg sync.WaitGroup
wg.Add(2)
solve := func(domain1 string, timeoutPresent time.Duration, timeoutCleanup time.Duration) error {
solve := func(domain1 string, timeoutPresent, timeoutCleanup time.Duration) error {
time.Sleep(timeoutPresent)
err := p.Present(domain1, "", "")
if err != nil {

View file

@ -68,7 +68,7 @@ func (d *DNSProvider) getDNSRecords(domain string) (*dnsRecordsResponse, error)
return respData, nil
}
func (d *DNSProvider) makeRequest(method string, uri string, body io.Reader) (*http.Request, error) {
func (d *DNSProvider) makeRequest(method, uri string, body io.Reader) (*http.Request, error) {
endpoint, err := d.config.BaseURL.Parse(path.Join(d.config.BaseURL.EscapedPath(), uri))
if err != nil {
return nil, err

View file

@ -81,7 +81,6 @@ func (c *Client) GetRecords(domain string) ([]Record, error) {
resp, err := c.get("/list", struct {
Domain string `url:"domain"`
}{Domain: domain})
if err != nil {
return nil, err
}

View file

@ -130,6 +130,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
var record *internal.Record
for _, rcd := range records {
rcd := rcd
if rcd.Type == "TXT" && rcd.SubDomain == subDomain && rcd.Content == value {
record = &rcd
break

View file

@ -30,12 +30,12 @@ func (w *HTTPProvider) Present(domain, token, keyAuth string) error {
var err error
challengeFilePath := filepath.Join(w.path, http01.ChallengePath(token))
err = os.MkdirAll(filepath.Dir(challengeFilePath), 0755)
err = os.MkdirAll(filepath.Dir(challengeFilePath), 0o755)
if err != nil {
return fmt.Errorf("could not create required directories in webroot for HTTP challenge: %w", err)
}
err = ioutil.WriteFile(challengeFilePath, []byte(keyAuth), 0644)
err = ioutil.WriteFile(challengeFilePath, []byte(keyAuth), 0o644)
if err != nil {
return fmt.Errorf("could not write file in webroot for HTTP challenge: %w", err)
}

View file

@ -16,7 +16,7 @@ func TestHTTPProvider(t *testing.T) {
keyAuth := "keyAuth"
challengeFilePath := webroot + "/.well-known/acme-challenge/" + token
require.NoError(t, os.MkdirAll(webroot+"/.well-known/acme-challenge", 0777))
require.NoError(t, os.MkdirAll(webroot+"/.well-known/acme-challenge", 0o777))
defer os.RemoveAll(webroot)
provider, err := NewHTTPProvider(webroot)