chore: go1.16 and linter update

This commit is contained in:
Fernandez Ludovic 2021-03-09 10:48:24 +01:00
parent c1eebcb16e
commit 0c0662615b
13 changed files with 111 additions and 87 deletions

View File

@ -11,7 +11,7 @@ jobs:
strategy: strategy:
matrix: matrix:
go-version: [ 1.14, 1.15, 1.x ] go-version: [ 1.16, 1.x ]
os: [ubuntu-latest, macos-latest, windows-latest] os: [ubuntu-latest, macos-latest, windows-latest]
steps: steps:

View File

@ -14,9 +14,9 @@ jobs:
name: Main Process name: Main Process
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
GO_VERSION: 1.15 GO_VERSION: 1.16
GOLANGCI_LINT_VERSION: v1.33.0 GOLANGCI_LINT_VERSION: v1.38.0
SEIHON_VERSION: v0.5.1 SEIHON_VERSION: v0.8.3
CGO_ENABLED: 0 CGO_ENABLED: 0
steps: steps:
@ -44,10 +44,10 @@ jobs:
- name: Check and get dependencies - name: Check and get dependencies
run: | run: |
go mod download
go mod tidy go mod tidy
git diff --exit-code go.mod git diff --exit-code go.mod
git diff --exit-code go.sum git diff --exit-code go.sum
go mod download
# https://golangci-lint.run/usage/install#other-ci # https://golangci-lint.run/usage/install#other-ci
- name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }} - name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}

View File

@ -1,51 +0,0 @@
[run]
timeout = "5m"
skip-files = []
[linters-settings]
[linters-settings.govet]
check-shadowing = true
[linters-settings.gocyclo]
min-complexity = 12.0
[linters-settings.maligned]
suggest-new = true
[linters-settings.goconst]
min-len = 3.0
min-occurrences = 3.0
[linters-settings.misspell]
locale = "US"
[linters]
enable-all = true
disable = [
"maligned",
"lll",
"gosec",
"dupl",
"prealloc",
"scopelint",
"wsl",
"nlreturn",
"gomnd",
"testpackage",
"paralleltest",
"tparallel",
"goerr113",
"wrapcheck",
"exhaustive",
"exhaustivestruct",
]
[issues]
exclude-use-default = false
max-per-linter = 0
max-same-issues = 0
exclude = ["ST1000: at least one file in a package should have a package comment"]
[[issues.exclude-rules]]
path = "cmd/"
linters = ["gochecknoglobals", "gochecknoinits"]

82
.golangci.yml Normal file
View File

@ -0,0 +1,82 @@
run:
timeout: 5m
skip-files: []
linters-settings:
govet:
check-shadowing: true
gocyclo:
min-complexity: 12
maligned:
suggest-new: true
goconst:
min-len: 3
min-occurrences: 3
misspell:
locale: US
gofumpt:
extra-rules: true
depguard:
list-type: blacklist
include-go-root: false
packages:
- github.com/pkg/errors
godox:
keywords:
- FIXME
gocritic:
enabled-tags:
- diagnostic
- style
- performance
disabled-checks:
- sloppyReassign
- rangeValCopy
- octalLiteral
- paramTypeCombine # already handle by gofumpt.extra-rules
settings:
hugeParam:
sizeThreshold: 100
forbidigo:
forbid:
- '^print(ln)?$'
- '^spew\.Print(f|ln)?$'
- '^spew\.Dump$'
linters:
enable-all: true
disable:
- scopelint # deprecated
- interfacer # deprecated
- maligned # deprecated
- sqlclosecheck # not relevant (SQL)
- rowserrcheck # not relevant (SQL)
- cyclop # duplicate of gocyclo
- lll
- gas
- dupl
- prealloc
- scopelint
- wsl
- nlreturn
- gomnd
- testpackage
- paralleltest
- tparallel
- goerr113
- wrapcheck
- exhaustive
- exhaustivestruct
- ifshort
issues:
exclude-use-default: false
max-per-linter: 0
max-same-issues: 0
exclude:
- 'ST1000: at least one file in a package should have a package comment'
exclude-rules:
- path: cmd/
linters:
- gochecknoglobals
- gochecknoinits

View File

@ -4,7 +4,6 @@ import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"time" "time"
@ -87,7 +86,7 @@ func createTLSConfig(cmd *cobra.Command) (*tls.Config, error) {
privateKey := cmd.Flag("tls.key").Value.String() privateKey := cmd.Flag("tls.key").Value.String()
certContent := cmd.Flag("tls.cert").Value.String() certContent := cmd.Flag("tls.cert").Value.String()
if !insecureSkipVerify && (len(certContent) == 0 || len(privateKey) == 0) { if !insecureSkipVerify && (certContent == "" || privateKey == "") {
return nil, fmt.Errorf("TLS Certificate or Key file must be set when TLS configuration is created") return nil, fmt.Errorf("TLS Certificate or Key file must be set when TLS configuration is created")
} }
@ -122,11 +121,14 @@ func getCertPool(ca string) (*x509.CertPool, error) {
} }
func getCAContent(ca string) ([]byte, error) { func getCAContent(ca string) ([]byte, error) {
if _, errCA := os.Stat(ca); errCA != nil { if _, err := os.Stat(ca); err != nil {
return []byte(ca), nil if os.IsNotExist(err) {
return []byte(ca), nil
}
return nil, err
} }
caContent, err := ioutil.ReadFile(filepath.Clean(ca)) caContent, err := os.ReadFile(filepath.Clean(ca))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -2,14 +2,13 @@ package cmd
import ( import (
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
"github.com/ldez/traefik-certs-dumper/v2/dumper" "github.com/ldez/traefik-certs-dumper/v2/dumper"
homedir "github.com/mitchellh/go-homedir" "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -117,7 +116,7 @@ func tree(root, indent string) error {
return nil return nil
} }
fis, err := ioutil.ReadDir(root) fis, err := os.ReadDir(root)
if err != nil { if err != nil {
return fmt.Errorf("could not read dir %s: %w", root, err) return fmt.Errorf("could not read dir %s: %w", root, err)
} }

View File

@ -1,8 +1,6 @@
package file package file
import ( import (
"io/ioutil"
"os"
"testing" "testing"
"github.com/ldez/traefik-certs-dumper/v2/dumper" "github.com/ldez/traefik-certs-dumper/v2/dumper"
@ -35,9 +33,7 @@ func TestDump(t *testing.T) {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
t.Parallel() t.Parallel()
dir, err := ioutil.TempDir("", "traefik-cert-dumper") dir := t.TempDir()
require.NoError(t, err)
defer func() { _ = os.RemoveAll(dir) }()
cfg := &dumper.BaseConfig{ cfg := &dumper.BaseConfig{
DumpPath: dir, DumpPath: dir,
@ -53,7 +49,7 @@ func TestDump(t *testing.T) {
Version: test.version, Version: test.version,
} }
err = Dump(test.acmeFile, cfg) err := Dump(test.acmeFile, cfg)
require.NoError(t, err) require.NoError(t, err)
}) })
} }

View File

@ -5,7 +5,7 @@ import (
"compress/gzip" "compress/gzip"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"log" "log"
"os" "os"
"strings" "strings"
@ -83,7 +83,7 @@ func getStoredDataFromGzip(pair *store.KVPair) (*v1.StoredData, error) {
return nil, fmt.Errorf("fail to create GZip reader: %w", err) return nil, fmt.Errorf("fail to create GZip reader: %w", err)
} }
acmeData, err := ioutil.ReadAll(reader) acmeData, err := io.ReadAll(reader)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to read the pair content: %w", err) return nil, fmt.Errorf("unable to read the pair content: %w", err)
} }

View File

@ -3,7 +3,6 @@ package v1
import ( import (
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -52,7 +51,7 @@ func Dump(data *StoredData, baseConfig *dumper.BaseConfig) error {
} }
privateKeyPem := extractPEMPrivateKey(data.Account) privateKeyPem := extractPEMPrivateKey(data.Account)
return ioutil.WriteFile(filepath.Join(baseConfig.DumpPath, keysSubDir, "letsencrypt"+baseConfig.KeyInfo.Ext), privateKeyPem, 0600) return os.WriteFile(filepath.Join(baseConfig.DumpPath, keysSubDir, "letsencrypt"+baseConfig.KeyInfo.Ext), privateKeyPem, 0600)
} }
func writeCert(dumpPath string, cert *Certificate, info dumper.FileInfo, domainSubDir bool) error { func writeCert(dumpPath string, cert *Certificate, info dumper.FileInfo, domainSubDir bool) error {
@ -64,7 +63,7 @@ func writeCert(dumpPath string, cert *Certificate, info dumper.FileInfo, domainS
} }
} }
return ioutil.WriteFile(certPath, cert.Certificate, 0666) return os.WriteFile(certPath, cert.Certificate, 0666)
} }
func writeKey(dumpPath string, cert *Certificate, info dumper.FileInfo, domainSubDir bool) error { func writeKey(dumpPath string, cert *Certificate, info dumper.FileInfo, domainSubDir bool) error {
@ -76,7 +75,7 @@ func writeKey(dumpPath string, cert *Certificate, info dumper.FileInfo, domainSu
} }
} }
return ioutil.WriteFile(keyPath, cert.Key, 0600) return os.WriteFile(keyPath, cert.Key, 0600)
} }
func extractPEMPrivateKey(account *Account) []byte { func extractPEMPrivateKey(account *Account) []byte {
@ -109,7 +108,7 @@ func cleanDir(dumpPath string) error {
return errExists return errExists
} }
dir, err := ioutil.ReadDir(dumpPath) dir, err := os.ReadDir(dumpPath)
if err != nil { if err != nil {
return err return err
} }

View File

@ -3,7 +3,6 @@ package v2
import ( import (
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -55,7 +54,7 @@ func Dump(data map[string]*acme.StoredData, baseConfig *dumper.BaseConfig) error
privateKeyPem := extractPEMPrivateKey(store.Account) privateKeyPem := extractPEMPrivateKey(store.Account)
err := ioutil.WriteFile(filepath.Join(baseConfig.DumpPath, keysSubDir, "letsencrypt"+baseConfig.KeyInfo.Ext), privateKeyPem, 0600) err := os.WriteFile(filepath.Join(baseConfig.DumpPath, keysSubDir, "letsencrypt"+baseConfig.KeyInfo.Ext), privateKeyPem, 0600)
if err != nil { if err != nil {
return fmt.Errorf("failed to write private key: %w", err) return fmt.Errorf("failed to write private key: %w", err)
} }
@ -73,7 +72,7 @@ func writeCert(dumpPath string, cert acme.Certificate, info dumper.FileInfo, dom
} }
} }
return ioutil.WriteFile(certPath, cert.Certificate, 0666) return os.WriteFile(certPath, cert.Certificate, 0666)
} }
func writeKey(dumpPath string, cert acme.Certificate, info dumper.FileInfo, domainSubDir bool) error { func writeKey(dumpPath string, cert acme.Certificate, info dumper.FileInfo, domainSubDir bool) error {
@ -85,7 +84,7 @@ func writeKey(dumpPath string, cert acme.Certificate, info dumper.FileInfo, doma
} }
} }
return ioutil.WriteFile(keyPath, cert.Key, 0600) return os.WriteFile(keyPath, cert.Key, 0600)
} }
func extractPEMPrivateKey(account *acme.Account) []byte { func extractPEMPrivateKey(account *acme.Account) []byte {
@ -118,7 +117,7 @@ func cleanDir(dumpPath string) error {
return errExists return errExists
} }
dir, err := ioutil.ReadDir(dumpPath) dir, err := os.ReadDir(dumpPath)
if err != nil { if err != nil {
return err return err
} }

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/ldez/traefik-certs-dumper/v2 module github.com/ldez/traefik-certs-dumper/v2
go 1.14 go 1.16
require ( require (
github.com/abronan/valkeyrie v0.1.0 github.com/abronan/valkeyrie v0.1.0

2
go.sum
View File

@ -85,7 +85,6 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdko
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/sarama v1.23.1/go.mod h1:XLH1GYJnLVE0XCr6KdJGVJRTwY30moWNJ4sERjXX6fs= github.com/Shopify/sarama v1.23.1/go.mod h1:XLH1GYJnLVE0XCr6KdJGVJRTwY30moWNJ4sERjXX6fs=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE=
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
github.com/abronan/valkeyrie v0.0.0-20200127174252-ef4277a138cd/go.mod h1:2RUNONRAQ8bS1QcVJF3dYO/faiEro6NAAIQ6CqBkpD0= github.com/abronan/valkeyrie v0.0.0-20200127174252-ef4277a138cd/go.mod h1:2RUNONRAQ8bS1QcVJF3dYO/faiEro6NAAIQ6CqBkpD0=
github.com/abronan/valkeyrie v0.1.0 h1:xhyFvo2Gh+P8KPauMERFDOcVVB0LKU1UgXrVB0jwjH4= github.com/abronan/valkeyrie v0.1.0 h1:xhyFvo2Gh+P8KPauMERFDOcVVB0LKU1UgXrVB0jwjH4=
@ -599,7 +598,6 @@ github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzE
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
github.com/nrdcg/auroradns v1.0.1 h1:m/kBq83Xvy3cU261MOknd8BdnOk12q4lAWM+kOdsC2Y= github.com/nrdcg/auroradns v1.0.1 h1:m/kBq83Xvy3cU261MOknd8BdnOk12q4lAWM+kOdsC2Y=
github.com/nrdcg/auroradns v1.0.1/go.mod h1:y4pc0i9QXYlFCWrhWrUSIETnZgrf4KuwjDIWmmXo3JI= github.com/nrdcg/auroradns v1.0.1/go.mod h1:y4pc0i9QXYlFCWrhWrUSIETnZgrf4KuwjDIWmmXo3JI=

View File

@ -3,8 +3,8 @@ package main
import ( import (
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"io/ioutil"
"log" "log"
"os"
"path/filepath" "path/filepath"
"time" "time"
@ -92,7 +92,7 @@ func putData(backend store.Backend, addrs []string, content []byte) error {
} }
func readFile(source string) ([]byte, error) { func readFile(source string) ([]byte, error) {
content, err := ioutil.ReadFile(filepath.Clean(source)) content, err := os.ReadFile(filepath.Clean(source))
if err != nil { if err != nil {
return nil, err return nil, err
} }