Move to mirrorred images for Drone and Dockerfile, linting fixes.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Stanislav Nikitin 2022-06-29 15:04:57 +05:00
parent 899c406f09
commit 9e5f98a413
Signed by: pztrn
GPG Key ID: 1E944A0F0568B550
13 changed files with 44 additions and 40 deletions

View File

@ -5,7 +5,7 @@ name: build
steps: steps:
- name: lint - name: lint
image: golangci/golangci-lint:v1.43.0 image: code.pztrn.name/containers/mirror/golangci/golangci-lint:v1.46.2
environment: environment:
CGO_ENABLED: 0 CGO_ENABLED: 0
commands: commands:
@ -19,15 +19,15 @@ steps:
- go test ./... - go test ./...
- name: docker - name: docker
image: plugins/docker image: code.pztrn.name/containers/mirror/plugins/docker:20.13.0
when: when:
branch: ["master"] branch: ["master"]
settings: settings:
username: registry: code.pztrn.name
from_secret: dockerhub_user username: drone
password: password:
from_secret: dockerhub_password from_secret: drone_secret
repo: pztrn/giredore repo: code.pztrn.name/apps/giredore
auto_tag: true auto_tag: true
depends_on: depends_on:
- lint - lint

View File

@ -12,6 +12,8 @@ linters:
- funlen - funlen
# Magic numbers might be everywhere. Disabled for now. # Magic numbers might be everywhere. Disabled for now.
- gomnd - gomnd
# Deprecated.
- exhaustivestruct
linters-settings: linters-settings:
lll: lll:
line-length: 420 line-length: 420

View File

@ -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 WORKDIR /go/src/sources.dev.pztrn.name/pztrn/giredore
COPY . . COPY . .
@ -6,7 +6,7 @@ COPY . .
ENV CGO_ENABLED=0 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"' 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. <pztrn@pztrn.name>" LABEL maintainer "Stanislav N. <pztrn@pztrn.name>"
COPY --from=build /go/src/sources.dev.pztrn.name/pztrn/giredore/cmd/giredored/giredored /usr/local/bin/giredored COPY --from=build /go/src/sources.dev.pztrn.name/pztrn/giredore/cmd/giredored/giredored /usr/local/bin/giredored

View File

@ -27,7 +27,7 @@ func DeletePackage(args []string, options map[string]string) {
func GetPackages(args []string, options map[string]string) { func GetPackages(args []string, options map[string]string) {
pkgs := strings.Split(args[0], ",") pkgs := strings.Split(args[0], ",")
// nolint:exhaustivestruct // nolint:exhaustruct
req := &structs.PackageGetRequest{} req := &structs.PackageGetRequest{}
if pkgs[0] == "all" { if pkgs[0] == "all" {
req.All = true req.All = true

View File

@ -15,11 +15,11 @@ func configurationGET(ec echo.Context) error {
} }
func configurationAllowedIPsSET(ectx echo.Context) error { func configurationAllowedIPsSET(ectx echo.Context) error {
// nolint:exhaustivestruct // nolint:exhaustruct
req := &structs.AllowedIPsSetRequest{} req := &structs.AllowedIPsSetRequest{}
if err := ectx.Bind(req); err != nil { if err := ectx.Bind(req); err != nil {
log.Error().Err(err).Msg("Failed to parse allowed IPs set request") 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}}) 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) configuration.Cfg.SetAllowedIPs(req.AllowedIPs)
// nolint:exhaustivestruct,wrapcheck // nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess}) return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess})
} }

View File

@ -20,18 +20,18 @@ func throwGoImports(ectx echo.Context) error {
if errs != nil { if errs != nil {
log.Error().Str("package", packageNameRaw).Msgf("Failed to get package information: %+v", errs) 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}) return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: errs})
} }
if len(pkgs) == 0 { 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}}) return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrNoPackagesFound}})
} }
pkg, found := pkgs[packageNameRaw] pkg, found := pkgs[packageNameRaw]
if !found { if !found {
// nolint:exhaustivestruct,wrapcheck // nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrNoPackagesFound}}) return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrNoPackagesFound}})
} }

View File

@ -11,12 +11,12 @@ import (
// This function responsible for getting packages configuration. // This function responsible for getting packages configuration.
func packagesGET(ectx echo.Context) error { func packagesGET(ectx echo.Context) error {
// nolint:exhaustivestruct // nolint:exhaustruct
req := &structs.PackageGetRequest{} req := &structs.PackageGetRequest{}
if err := ectx.Bind(req); err != nil { if err := ectx.Bind(req); err != nil {
log.Error().Err(err).Msg("Failed to parse package get request") 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}}) 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}) 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}) return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess, Data: pkgs})
} }
// This function responsible for deleting package. // This function responsible for deleting package.
func packagesDELETE(ectx echo.Context) error { func packagesDELETE(ectx echo.Context) error {
// nolint:exhaustivestruct // nolint:exhaustruct
req := &structs.PackageDeleteRequest{} req := &structs.PackageDeleteRequest{}
if err := ectx.Bind(req); err != nil { if err := ectx.Bind(req); err != nil {
log.Error().Err(err).Msg("Failed to parse package delete request") 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}}) 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) errs := configuration.Cfg.DeletePackage(req)
if len(errs) > 0 { if len(errs) > 0 {
// nolint:exhaustivestruct,wrapcheck // nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: errs}) 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}) return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess})
} }
// This function responsible for setting or updating packages. // This function responsible for setting or updating packages.
func packagesSET(ectx echo.Context) error { func packagesSET(ectx echo.Context) error {
// nolint:exhaustivestruct // nolint:exhaustruct
req := &structs.Package{} req := &structs.Package{}
if err := ectx.Bind(req); err != nil { if err := ectx.Bind(req); err != nil {
log.Error().Err(err).Msg("Failed to parse package data") log.Error().Err(err).Msg("Failed to parse package data")
@ -80,12 +80,12 @@ func packagesSET(ectx echo.Context) error {
// Validate passed package data. // Validate passed package data.
if !strings.HasPrefix(req.OriginalPath, "/") { 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}}) return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrPackageOrigPathShouldStartWithSlash}})
} }
configuration.Cfg.AddOrUpdatePackage(req) configuration.Cfg.AddOrUpdatePackage(req)
// nolint:exhaustivestruct,wrapcheck // nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess}) return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess})
} }

View File

@ -16,11 +16,11 @@ func Initialize() {
log = logger.Logger.With().Str("type", "internal").Str("package", "configuration").Logger() log = logger.Logger.With().Str("type", "internal").Str("package", "configuration").Logger()
log.Info().Msg("Initializing...") log.Info().Msg("Initializing...")
// nolint:exhaustivestruct // nolint:exhaustruct
envCfg = &envConfig{} envCfg = &envConfig{}
envCfg.Initialize() envCfg.Initialize()
// nolint:exhaustivestruct // nolint:exhaustruct
Cfg = &fileConfig{} Cfg = &fileConfig{}
Cfg.Initialize() Cfg.Initialize()

View File

@ -35,7 +35,7 @@ func checkAllowedIPs() echo.MiddlewareFunc {
if err != nil { 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!") 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}}) 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) return next(ectx)
} }
// nolint:exhaustivestruct,wrapcheck // nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrIPAddressNotAllowed}}) return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrIPAddressNotAllowed}})
} }
} }

View File

@ -62,7 +62,7 @@ func Start() {
}() }()
// Check that HTTP server was started. // Check that HTTP server was started.
// nolint:exhaustivestruct // nolint:exhaustruct
httpc := &http.Client{Timeout: time.Second * 1} httpc := &http.Client{Timeout: time.Second * 1}
checks := 0 checks := 0

View File

@ -44,32 +44,32 @@ func Initialize() {
zerolog.SetGlobalLevel(zerolog.InfoLevel) zerolog.SetGlobalLevel(zerolog.InfoLevel)
} }
// nolint:exhaustivestruct // nolint:exhaustruct
output := zerolog.ConsoleWriter{Out: os.Stdout, NoColor: false, TimeFormat: time.RFC3339} output := zerolog.ConsoleWriter{Out: os.Stdout, NoColor: false, TimeFormat: time.RFC3339}
output.FormatLevel = func(lvlRaw interface{}) string { output.FormatLevel = func(lvlRaw interface{}) string {
var v string var formattedLvl string
if lvl, ok := lvlRaw.(string); ok { if lvl, ok := lvlRaw.(string); ok {
lvl = strings.ToUpper(lvl) lvl = strings.ToUpper(lvl)
switch lvl { switch lvl {
case "DEBUG": case "DEBUG":
v = fmt.Sprintf("\x1b[30m%-5s\x1b[0m", lvl) formattedLvl = fmt.Sprintf("\x1b[30m%-5s\x1b[0m", lvl)
case "ERROR": case "ERROR":
v = fmt.Sprintf("\x1b[31m%-5s\x1b[0m", lvl) formattedLvl = fmt.Sprintf("\x1b[31m%-5s\x1b[0m", lvl)
case "FATAL": case "FATAL":
v = fmt.Sprintf("\x1b[35m%-5s\x1b[0m", lvl) formattedLvl = fmt.Sprintf("\x1b[35m%-5s\x1b[0m", lvl)
case "INFO": case "INFO":
v = fmt.Sprintf("\x1b[32m%-5s\x1b[0m", lvl) formattedLvl = fmt.Sprintf("\x1b[32m%-5s\x1b[0m", lvl)
case "PANIC": case "PANIC":
v = fmt.Sprintf("\x1b[36m%-5s\x1b[0m", lvl) formattedLvl = fmt.Sprintf("\x1b[36m%-5s\x1b[0m", lvl)
case "WARN": case "WARN":
v = fmt.Sprintf("\x1b[33m%-5s\x1b[0m", lvl) formattedLvl = fmt.Sprintf("\x1b[33m%-5s\x1b[0m", lvl)
default: default:
v = lvl formattedLvl = lvl
} }
} }
return fmt.Sprintf("| %s |", v) return fmt.Sprintf("| %s |", formattedLvl)
} }
Logger = zerolog.New(output).With().Timestamp().Logger() Logger = zerolog.New(output).With().Timestamp().Logger()

View File

@ -30,6 +30,7 @@ func execRequest(method string, url string, data interface{}) ([]byte, error) {
var dataToSend []byte var dataToSend []byte
if data != nil { if data != nil {
// nolint:errchkjson
dataToSend, _ = json.Marshal(data) dataToSend, _ = json.Marshal(data)
} }

View File

@ -8,6 +8,7 @@ import (
// nolint:exhaustivestruct // nolint:exhaustivestruct
func getHTTPClient() *http.Client { func getHTTPClient() *http.Client {
// nolint:exhaustruct
client := &http.Client{ client := &http.Client{
Transport: &http.Transport{ Transport: &http.Transport{
ExpectContinueTimeout: time.Second * 5, ExpectContinueTimeout: time.Second * 5,