From b55e3af06c9eb52157b636b867af8994185068bb Mon Sep 17 00:00:00 2001 From: Kosh Date: Mon, 9 Aug 2021 09:49:39 +1000 Subject: [PATCH] fixed linter warnings --- .github/workflows/ci.yml | 2 +- .golangci.yml | 9 ++++++++ Makefile | 46 ++++--------------------------------- cmd/traefik-acme/main.go | 21 ++++++++++++----- cmd/traefik-acme/version.go | 2 +- go.mod | 1 + go.sum | 2 ++ traefik/resource_test.go | 16 ++++++------- traefik/store.go | 1 + 9 files changed, 43 insertions(+), 57 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c5b4864..01ea30c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v2.5.2 with: - version: v1.33 + version: v1.41 - name: unit-test run: make test - name: ci diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..bbcc622 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,9 @@ +linters: + enable-all: true + disable: + - exhaustivestruct + - interfacer + - golint + - maligned + - paralleltest + - scopelint diff --git a/Makefile b/Makefile index a5af214..903c7b7 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,11 @@ endif -include .makefiles/Makefile -include .makefiles/pkg/go/v1/Makefile -include .makefiles/pkg/docker/v1/Makefile +-include .makefiles/ext/na4ma4/lib/golangci-lint/v1/Makefile +-include .makefiles/ext/na4ma4/lib/goreleaser/v1/Makefile + +.makefiles/ext/na4ma4/%: .makefiles/Makefile + @curl -sfL https://raw.githubusercontent.com/na4ma4/makefiles-ext/main/v1/install | bash /dev/stdin "$@" .makefiles/%: @curl -sfL https://makefiles.dev/v1 | bash /dev/stdin "$@" @@ -100,45 +105,4 @@ ci:: $(REGRESSION_TESTS) # Linting ###################### -MISSPELL := artifacts/bin/misspell -$(MISSPELL): - -@mkdir -p "$(MF_PROJECT_ROOT)/$(@D)" - GOBIN="$(MF_PROJECT_ROOT)/$(@D)" go get $(_MODFILEARG) github.com/client9/misspell/cmd/misspell - -GOLINT := artifacts/bin/golint -$(GOLINT): - -@mkdir -p "$(MF_PROJECT_ROOT)/$(@D)" - GOBIN="$(MF_PROJECT_ROOT)/$(@D)" go get $(_MODFILEARG) golang.org/x/lint/golint - -GOLANGCILINT := artifacts/bin/golangci-lint -$(GOLANGCILINT): - -@mkdir -p "$(MF_PROJECT_ROOT)/$(@D)" - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$(MF_PROJECT_ROOT)/$(@D)" v1.33.0 - -STATICCHECK := artifacts/bin/staticcheck -$(STATICCHECK): - -@mkdir -p "$(MF_PROJECT_ROOT)/$(@D)" - GOBIN="$(MF_PROJECT_ROOT)/$(@D)" go get $(_MODFILEARG) honnef.co/go/tools/cmd/staticcheck - -artifacts/cover/staticheck/unused-graph.txt: $(STATICCHECK) $(GO_SOURCE_FILES) - -@mkdir -p "$(MF_PROJECT_ROOT)/$(@D)" - $(STATICCHECK) -debug.unused-graph "$(@)" ./... - # cat "$(@)" - -.PHONY: lint -lint:: $(GOLINT) $(MISSPELL) $(GOLANGCILINT) $(STATICCHECK) artifacts/cover/staticheck/unused-graph.txt - go vet ./... - $(GOLINT) -set_exit_status ./... - $(MISSPELL) -w -error -locale UK ./... - $(GOLANGCILINT) run --enable-all --disable 'exhaustivestruct,paralleltest' ./... - $(STATICCHECK) -fail "all,-U1001" ./... - ci:: lint - - -###################### -# Preload Tools -###################### - -.PHONY: tools -tools: $(MISSPELL) $(GOLINT) $(GOLANGCILINT) $(STATICCHECK) diff --git a/cmd/traefik-acme/main.go b/cmd/traefik-acme/main.go index ee39588..40c52ef 100644 --- a/cmd/traefik-acme/main.go +++ b/cmd/traefik-acme/main.go @@ -7,12 +7,13 @@ import ( "os" "github.com/koshatul/traefik-acme/traefik" + "github.com/na4ma4/permbits" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) -// nolint: gochecknoglobals // cobra uses globals in main +//nolint:gochecknoglobals // cobra uses globals in main var rootCmd = &cobra.Command{ Use: "traefik-acme ", Short: "Command to extract SSL certificates from traefik acme.json", @@ -25,7 +26,7 @@ const ( exitCodeUpdated = 99 ) -// nolint:gochecknoinits // init is used in main for cobra +//nolint:gochecknoinits // init is used in main for cobra func init() { cobra.OnInitialize(configInit) @@ -62,7 +63,7 @@ func main() { _ = rootCmd.Execute() } -//nolint: gocritic,nestif // ifElseChain doesn't seem to be idiomatic here. +//nolint:gocritic,nestif // ifElseChain doesn't seem to be idiomatic here. func writeFile(filename string, data []byte, perm os.FileMode) (bool, error) { if _, err := os.Stat(filename); os.IsNotExist(err) { // File does not exist, just write it. @@ -105,7 +106,7 @@ func writeFile(filename string, data []byte, perm os.FileMode) (bool, error) { } } -//nolint: nestif // mainCommand can stand a little complexity. +//nolint:nestif // mainCommand can stand a little complexity. func mainCommand(cmd *cobra.Command, args []string) { domain := args[0] updated := false @@ -117,13 +118,21 @@ func mainCommand(cmd *cobra.Command, args []string) { } if cert := store.GetCertificateByName(domain); cert != nil { - certUpdated, err := writeFile(viper.GetString("cert"), cert.Certificate, 0644) + certUpdated, err := writeFile( + viper.GetString("cert"), + cert.Certificate, + permbits.UserRead+permbits.UserWrite+permbits.GroupRead+permbits.OtherRead, + ) if err != nil { logrus.Errorf("unable to write certificate: %s", err.Error()) os.Exit(exitCodeError) } - keyUpdated, err := writeFile(viper.GetString("key"), cert.Key, 0600) + keyUpdated, err := writeFile( + viper.GetString("key"), + cert.Key, + permbits.UserRead+permbits.UserWrite, + ) if err != nil { logrus.Errorf("unable to write key: %s", err.Error()) os.Exit(exitCodeError) diff --git a/cmd/traefik-acme/version.go b/cmd/traefik-acme/version.go index 6fe096e..65fcd33 100644 --- a/cmd/traefik-acme/version.go +++ b/cmd/traefik-acme/version.go @@ -4,7 +4,7 @@ import ( "fmt" ) -//nolint: gochecknoglobals // these have to be variables for the linker to change the values +//nolint:gochecknoglobals // these have to be variables for the linker to change the values var ( version = "dev" date = "notset" diff --git a/go.mod b/go.mod index 8504f32..3c9f999 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/cenkalti/backoff v2.2.1+incompatible // indirect github.com/go-acme/lego v2.7.2+incompatible github.com/hashicorp/hcl v1.0.1-0.20180906183839-65a6292f0157 // indirect + github.com/na4ma4/permbits v0.1.0 // indirect github.com/onsi/ginkgo v1.16.4 github.com/onsi/gomega v1.14.0 github.com/sirupsen/logrus v1.8.1 diff --git a/go.sum b/go.sum index a976818..f7beddf 100644 --- a/go.sum +++ b/go.sum @@ -204,6 +204,8 @@ github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/na4ma4/permbits v0.1.0 h1:DjpgC1JyYFqxOnkCrCWcBBAA1jt6IWl/Xk98wRDyFp8= +github.com/na4ma4/permbits v0.1.0/go.mod h1:vS1uN9OXc9jrt2uHmMD3bd09VoN7z/5AulfYIE22PT0= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= diff --git a/traefik/resource_test.go b/traefik/resource_test.go index 13e2658..1b031be 100644 --- a/traefik/resource_test.go +++ b/traefik/resource_test.go @@ -16,20 +16,20 @@ import ( . "github.com/onsi/gomega" ) -// nolint: gochecknoglobals // acmeDatav1 is a test variable +//nolint:gochecknoglobals // acmeDatav1 is a test variable var acmeDatav1 []byte -// nolint: gochecknoglobals // acmeDatav2 is a test variable +//nolint:gochecknoglobals // acmeDatav2 is a test variable var acmeDatav2 []byte -// nolint: gochecknoglobals,lll // acmeDatav3 is a test variable -var acmeDatav3 []byte = []byte(`{"acme":{"Account":{"Email":"koshatul@noreply.users.github.com","Registration":{"body":{"status":"valid","contact":["mailto:koshatul@noreply.users.github.com"]},"uri":"https://acme-v02.api.letsencrypt.org/acme/acct/123456789"},"PrivateKey":"c2VjcmV0LXByaXZhdGUta2V5LWZvci0xMjM0NTY3ODkK","KeyType":"4096"},"Certificates":[{"domain":{"main":"example.com","sans":["*.example.com"]},"certificate":"Y2VydGlmaWNhdGUtZm9yLWV4YW1wbGUuY29tCg==","key":"a2V5LWZvci1leGFtcGxlLmNvbQo=","Store":"default"}]}}`) +//nolint:gochecknoglobals,lll // acmeDatav3 is a test variable +var acmeDatav3 = []byte(`{"acme":{"Account":{"Email":"koshatul@noreply.users.github.com","Registration":{"body":{"status":"valid","contact":["mailto:koshatul@noreply.users.github.com"]},"uri":"https://acme-v02.api.letsencrypt.org/acme/acct/123456789"},"PrivateKey":"c2VjcmV0LXByaXZhdGUta2V5LWZvci0xMjM0NTY3ODkK","KeyType":"4096"},"Certificates":[{"domain":{"main":"example.com","sans":["*.example.com"]},"certificate":"Y2VydGlmaWNhdGUtZm9yLWV4YW1wbGUuY29tCg==","key":"a2V5LWZvci1leGFtcGxlLmNvbQo=","Store":"default"}]}}`) -// nolint: gochecknoglobals,lll // acmeDatav4 is a test variable -var acmeDatav4 []byte = []byte(`{"acme":{"Account":{"Email":"koshatul@noreply.users.github.com","Registration":{"body":{"status":"valid","contact":["mailto:koshatul@noreply.users.github.com"]},"uri":"https://acme-v02.api.letsencrypt.org/acme/acct/123456789"},"PrivateKey":"c2VjcmV0LXByaXZhdGUta2V5LWZvci0xMjM0NTY3ODkK","KeyType":"4096"},"Certificates":[{"domain":{"main":"*.example.com"},"certificate":"Y2VydGlmaWNhdGUtZm9yLWV4YW1wbGUuY29tCg==","key":"a2V5LWZvci1leGFtcGxlLmNvbQo=","Store":"default"}]}}`) +//nolint:gochecknoglobals,lll // acmeDatav4 is a test variable +var acmeDatav4 = []byte(`{"acme":{"Account":{"Email":"koshatul@noreply.users.github.com","Registration":{"body":{"status":"valid","contact":["mailto:koshatul@noreply.users.github.com"]},"uri":"https://acme-v02.api.letsencrypt.org/acme/acct/123456789"},"PrivateKey":"c2VjcmV0LXByaXZhdGUta2V5LWZvci0xMjM0NTY3ODkK","KeyType":"4096"},"Certificates":[{"domain":{"main":"*.example.com"},"certificate":"Y2VydGlmaWNhdGUtZm9yLWV4YW1wbGUuY29tCg==","key":"a2V5LWZvci1leGFtcGxlLmNvbQo=","Store":"default"}]}}`) -// nolint: gochecknoglobals,lll // acmeDatav5 is a test variable -var acmeDatav5 []byte = []byte(`{"acme-different":{"Account":{"Email":"koshatul@noreply.users.github.com","Registration":{"body":{"status":"valid","contact":["mailto:koshatul@noreply.users.github.com"]},"uri":"https://acme-v02.api.letsencrypt.org/acme/acct/123456789"},"PrivateKey":"c2VjcmV0LXByaXZhdGUta2V5LWZvci0xMjM0NTY3ODkK","KeyType":"4096"},"Certificates":[{"domain":{"main":"example.com","sans":["*.example.com"]},"certificate":"Y2VydGlmaWNhdGUtZm9yLWV4YW1wbGUuY29tCg==","key":"a2V5LWZvci1leGFtcGxlLmNvbQo=","Store":"default"}]}}`) +//nolint:gochecknoglobals,lll // acmeDatav5 is a test variable +var acmeDatav5 = []byte(`{"acme-different":{"Account":{"Email":"koshatul@noreply.users.github.com","Registration":{"body":{"status":"valid","contact":["mailto:koshatul@noreply.users.github.com"]},"uri":"https://acme-v02.api.letsencrypt.org/acme/acct/123456789"},"PrivateKey":"c2VjcmV0LXByaXZhdGUta2V5LWZvci0xMjM0NTY3ODkK","KeyType":"4096"},"Certificates":[{"domain":{"main":"example.com","sans":["*.example.com"]},"certificate":"Y2VydGlmaWNhdGUtZm9yLWV4YW1wbGUuY29tCg==","key":"a2V5LWZvci1leGFtcGxlLmNvbQo=","Store":"default"}]}}`) var _ = BeforeSuite(func() { priv, err := rsa.GenerateKey(rand.Reader, 2048) diff --git a/traefik/store.go b/traefik/store.go index 5559ee0..5fe5e58 100644 --- a/traefik/store.go +++ b/traefik/store.go @@ -12,6 +12,7 @@ import ( type LocalStore map[string]*LocalNamedStore // LocalNamedStore represents the data managed by the Store. +//nolint:tagliatelle // importing definition from traefik. type LocalNamedStore struct { // Acme *LocalStore `json:"acme"` Account *Account `json:"Account"`