From 9e5f98a4137cc823d801c9e9df0769ad495befee Mon Sep 17 00:00:00 2001 From: "Stanislav N. aka pztrn" Date: Wed, 29 Jun 2022 15:04:57 +0500 Subject: [PATCH] Move to mirrorred images for Drone and Dockerfile, linting fixes. --- .drone.yml | 12 ++++++------ .golangci.yml | 2 ++ Dockerfile | 4 ++-- domains/client/v1/packages.go | 2 +- domains/server/v1/configapi.go | 6 +++--- domains/server/v1/goimports.go | 6 +++--- domains/server/v1/packagesapi.go | 20 ++++++++++---------- internal/configuration/exported.go | 4 ++-- internal/httpserver/checkallowedips.go | 4 ++-- internal/httpserver/exported.go | 2 +- internal/logger/exported.go | 20 ++++++++++---------- internal/requester/exported.go | 1 + internal/requester/httpclient.go | 1 + 13 files changed, 44 insertions(+), 40 deletions(-) diff --git a/.drone.yml b/.drone.yml index 41802fc..1a960b8 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,7 +5,7 @@ name: build steps: - name: lint - image: golangci/golangci-lint:v1.43.0 + image: code.pztrn.name/containers/mirror/golangci/golangci-lint:v1.46.2 environment: CGO_ENABLED: 0 commands: @@ -19,15 +19,15 @@ steps: - go test ./... - name: docker - image: plugins/docker + image: code.pztrn.name/containers/mirror/plugins/docker:20.13.0 when: branch: ["master"] settings: - username: - from_secret: dockerhub_user + registry: code.pztrn.name + username: drone password: - from_secret: dockerhub_password - repo: pztrn/giredore + from_secret: drone_secret + repo: code.pztrn.name/apps/giredore auto_tag: true depends_on: - lint diff --git a/.golangci.yml b/.golangci.yml index b0c6e37..530f380 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -12,6 +12,8 @@ linters: - funlen # Magic numbers might be everywhere. Disabled for now. - gomnd + # Deprecated. + - exhaustivestruct linters-settings: lll: line-length: 420 diff --git a/Dockerfile b/Dockerfile index b2a7557..e0c7c39 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.17.3-alpine AS build +FROM code.pztrn.name/containers/mirror/golang:1.18.3-alpine AS build WORKDIR /go/src/sources.dev.pztrn.name/pztrn/giredore COPY . . @@ -6,7 +6,7 @@ COPY . . ENV CGO_ENABLED=0 RUN cd /go/src/sources.dev.pztrn.name/pztrn/giredore/cmd/giredored && go build -tags netgo -ldflags '-w -extldflags "-static"' && cd ../giredorectl && go build -tags netgo -ldflags '-w -extldflags "-static"' -FROM alpine:latest +FROM code.pztrn.name/containers/mirror/alpine:3.16.0 LABEL maintainer "Stanislav N. " COPY --from=build /go/src/sources.dev.pztrn.name/pztrn/giredore/cmd/giredored/giredored /usr/local/bin/giredored diff --git a/domains/client/v1/packages.go b/domains/client/v1/packages.go index 9826a0d..b5b3a0b 100644 --- a/domains/client/v1/packages.go +++ b/domains/client/v1/packages.go @@ -27,7 +27,7 @@ func DeletePackage(args []string, options map[string]string) { func GetPackages(args []string, options map[string]string) { pkgs := strings.Split(args[0], ",") - // nolint:exhaustivestruct + // nolint:exhaustruct req := &structs.PackageGetRequest{} if pkgs[0] == "all" { req.All = true diff --git a/domains/server/v1/configapi.go b/domains/server/v1/configapi.go index 137bc3f..efa137c 100644 --- a/domains/server/v1/configapi.go +++ b/domains/server/v1/configapi.go @@ -15,11 +15,11 @@ func configurationGET(ec echo.Context) error { } func configurationAllowedIPsSET(ectx echo.Context) error { - // nolint:exhaustivestruct + // nolint:exhaustruct req := &structs.AllowedIPsSetRequest{} if err := ectx.Bind(req); err != nil { log.Error().Err(err).Msg("Failed to parse allowed IPs set request") - // nolint:exhaustivestruct,wrapcheck + // nolint:exhaustruct,wrapcheck return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrParsingAllowedIPsSetRequest}}) } @@ -27,6 +27,6 @@ func configurationAllowedIPsSET(ectx echo.Context) error { configuration.Cfg.SetAllowedIPs(req.AllowedIPs) - // nolint:exhaustivestruct,wrapcheck + // nolint:exhaustruct,wrapcheck return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess}) } diff --git a/domains/server/v1/goimports.go b/domains/server/v1/goimports.go index aeba796..a0bf560 100644 --- a/domains/server/v1/goimports.go +++ b/domains/server/v1/goimports.go @@ -20,18 +20,18 @@ func throwGoImports(ectx echo.Context) error { if errs != nil { log.Error().Str("package", packageNameRaw).Msgf("Failed to get package information: %+v", errs) - // nolint:exhaustivestruct,wrapcheck + // nolint:exhaustruct,wrapcheck return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: errs}) } if len(pkgs) == 0 { - // nolint:exhaustivestruct,wrapcheck + // nolint:exhaustruct,wrapcheck return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrNoPackagesFound}}) } pkg, found := pkgs[packageNameRaw] if !found { - // nolint:exhaustivestruct,wrapcheck + // nolint:exhaustruct,wrapcheck return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrNoPackagesFound}}) } diff --git a/domains/server/v1/packagesapi.go b/domains/server/v1/packagesapi.go index d66dd46..8088553 100644 --- a/domains/server/v1/packagesapi.go +++ b/domains/server/v1/packagesapi.go @@ -11,12 +11,12 @@ import ( // This function responsible for getting packages configuration. func packagesGET(ectx echo.Context) error { - // nolint:exhaustivestruct + // nolint:exhaustruct req := &structs.PackageGetRequest{} if err := ectx.Bind(req); err != nil { log.Error().Err(err).Msg("Failed to parse package get request") - // nolint:exhaustivestruct,wrapcheck + // nolint:exhaustruct,wrapcheck return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrParsingPackagesGetRequest}}) } @@ -37,18 +37,18 @@ func packagesGET(ectx echo.Context) error { return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: errors, Data: pkgs}) } - // nolint:exhaustivestruct,wrapcheck + // nolint:exhaustruct,wrapcheck return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess, Data: pkgs}) } // This function responsible for deleting package. func packagesDELETE(ectx echo.Context) error { - // nolint:exhaustivestruct + // nolint:exhaustruct req := &structs.PackageDeleteRequest{} if err := ectx.Bind(req); err != nil { log.Error().Err(err).Msg("Failed to parse package delete request") - // nolint:exhaustivestruct,wrapcheck + // nolint:exhaustruct,wrapcheck return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrParsingDeleteRequest}}) } @@ -57,17 +57,17 @@ func packagesDELETE(ectx echo.Context) error { errs := configuration.Cfg.DeletePackage(req) if len(errs) > 0 { - // nolint:exhaustivestruct,wrapcheck + // nolint:exhaustruct,wrapcheck return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: errs}) } - // nolint:exhaustivestruct,wrapcheck + // nolint:exhaustruct,wrapcheck return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess}) } // This function responsible for setting or updating packages. func packagesSET(ectx echo.Context) error { - // nolint:exhaustivestruct + // nolint:exhaustruct req := &structs.Package{} if err := ectx.Bind(req); err != nil { log.Error().Err(err).Msg("Failed to parse package data") @@ -80,12 +80,12 @@ func packagesSET(ectx echo.Context) error { // Validate passed package data. if !strings.HasPrefix(req.OriginalPath, "/") { - // nolint:exhaustivestruct,wrapcheck + // nolint:exhaustruct,wrapcheck return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrPackageOrigPathShouldStartWithSlash}}) } configuration.Cfg.AddOrUpdatePackage(req) - // nolint:exhaustivestruct,wrapcheck + // nolint:exhaustruct,wrapcheck return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess}) } diff --git a/internal/configuration/exported.go b/internal/configuration/exported.go index 1372755..4272ffb 100644 --- a/internal/configuration/exported.go +++ b/internal/configuration/exported.go @@ -16,11 +16,11 @@ func Initialize() { log = logger.Logger.With().Str("type", "internal").Str("package", "configuration").Logger() log.Info().Msg("Initializing...") - // nolint:exhaustivestruct + // nolint:exhaustruct envCfg = &envConfig{} envCfg.Initialize() - // nolint:exhaustivestruct + // nolint:exhaustruct Cfg = &fileConfig{} Cfg.Initialize() diff --git a/internal/httpserver/checkallowedips.go b/internal/httpserver/checkallowedips.go index bd77d37..d38cfad 100644 --- a/internal/httpserver/checkallowedips.go +++ b/internal/httpserver/checkallowedips.go @@ -35,7 +35,7 @@ func checkAllowedIPs() echo.MiddlewareFunc { if err != nil { log.Error().Err(err).Str("subnet", ipToParse).Msg("Failed to parse CIDR. /_api/ endpoint won't be accessible, this should be fixed manually in configuration file!") - // nolint:exhaustivestruct,wrapcheck + // nolint:exhaustruct,wrapcheck return ectx.JSON(http.StatusInternalServerError, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrInvalidAllowedIPDefined}}) } @@ -60,7 +60,7 @@ func checkAllowedIPs() echo.MiddlewareFunc { return next(ectx) } - // nolint:exhaustivestruct,wrapcheck + // nolint:exhaustruct,wrapcheck return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrIPAddressNotAllowed}}) } } diff --git a/internal/httpserver/exported.go b/internal/httpserver/exported.go index e9e84b0..04b6211 100644 --- a/internal/httpserver/exported.go +++ b/internal/httpserver/exported.go @@ -62,7 +62,7 @@ func Start() { }() // Check that HTTP server was started. - // nolint:exhaustivestruct + // nolint:exhaustruct httpc := &http.Client{Timeout: time.Second * 1} checks := 0 diff --git a/internal/logger/exported.go b/internal/logger/exported.go index 8b26412..503a7c7 100644 --- a/internal/logger/exported.go +++ b/internal/logger/exported.go @@ -44,32 +44,32 @@ func Initialize() { zerolog.SetGlobalLevel(zerolog.InfoLevel) } - // nolint:exhaustivestruct + // nolint:exhaustruct output := zerolog.ConsoleWriter{Out: os.Stdout, NoColor: false, TimeFormat: time.RFC3339} output.FormatLevel = func(lvlRaw interface{}) string { - var v string + var formattedLvl string if lvl, ok := lvlRaw.(string); ok { lvl = strings.ToUpper(lvl) switch lvl { case "DEBUG": - v = fmt.Sprintf("\x1b[30m%-5s\x1b[0m", lvl) + formattedLvl = fmt.Sprintf("\x1b[30m%-5s\x1b[0m", lvl) case "ERROR": - v = fmt.Sprintf("\x1b[31m%-5s\x1b[0m", lvl) + formattedLvl = fmt.Sprintf("\x1b[31m%-5s\x1b[0m", lvl) case "FATAL": - v = fmt.Sprintf("\x1b[35m%-5s\x1b[0m", lvl) + formattedLvl = fmt.Sprintf("\x1b[35m%-5s\x1b[0m", lvl) case "INFO": - v = fmt.Sprintf("\x1b[32m%-5s\x1b[0m", lvl) + formattedLvl = fmt.Sprintf("\x1b[32m%-5s\x1b[0m", lvl) case "PANIC": - v = fmt.Sprintf("\x1b[36m%-5s\x1b[0m", lvl) + formattedLvl = fmt.Sprintf("\x1b[36m%-5s\x1b[0m", lvl) case "WARN": - v = fmt.Sprintf("\x1b[33m%-5s\x1b[0m", lvl) + formattedLvl = fmt.Sprintf("\x1b[33m%-5s\x1b[0m", lvl) default: - v = lvl + formattedLvl = lvl } } - return fmt.Sprintf("| %s |", v) + return fmt.Sprintf("| %s |", formattedLvl) } Logger = zerolog.New(output).With().Timestamp().Logger() diff --git a/internal/requester/exported.go b/internal/requester/exported.go index 4bba245..a8bc4b1 100644 --- a/internal/requester/exported.go +++ b/internal/requester/exported.go @@ -30,6 +30,7 @@ func execRequest(method string, url string, data interface{}) ([]byte, error) { var dataToSend []byte if data != nil { + // nolint:errchkjson dataToSend, _ = json.Marshal(data) } diff --git a/internal/requester/httpclient.go b/internal/requester/httpclient.go index fb42552..5208af6 100644 --- a/internal/requester/httpclient.go +++ b/internal/requester/httpclient.go @@ -8,6 +8,7 @@ import ( // nolint:exhaustivestruct func getHTTPClient() *http.Client { + // nolint:exhaustruct client := &http.Client{ Transport: &http.Transport{ ExpectContinueTimeout: time.Second * 5,