Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
fixed linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
koshatul committed Aug 8, 2021
1 parent a7e6c0b commit b55e3af
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
linters:
enable-all: true
disable:
- exhaustivestruct
- interfacer
- golint
- maligned
- paralleltest
- scopelint
46 changes: 5 additions & 41 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
Expand Down Expand Up @@ -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)
21 changes: 15 additions & 6 deletions cmd/traefik-acme/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <domain>",
Short: "Command to extract SSL certificates from traefik acme.json",
Expand All @@ -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)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/traefik-acme/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
16 changes: 8 additions & 8 deletions traefik/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions traefik/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit b55e3af

Please sign in to comment.