Skip to content

Commit

Permalink
style: Upgrade linter and patch code
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyno-zeta committed Feb 13, 2024
1 parent 603f2fb commit 3359f59
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.55.2
version: v1.56.1

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ ifndef HAS_GOLANGCI_LINT
ifndef HAS_CURL
$(error You must install curl)
endif
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.55.2
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.56.1
endif
ifndef HAS_GIT
$(error You must install Git)
Expand Down
3 changes: 3 additions & 0 deletions pkg/s3-proxy/authx/authentication/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,15 @@ func (s *service) oidcAuthMiddleware(res *config.Resource) func(http.Handler) ht
if claims["family_name"] != nil {
ouser.FamilyName, _ = claims["family_name"].(string)
}

if claims["given_name"] != nil {
ouser.GivenName, _ = claims["given_name"].(string)
}

if claims["name"] != nil {
ouser.Name, _ = claims["name"].(string)
}

if claims["preferred_username"] != nil {
ouser.PreferredUsername, _ = claims["preferred_username"].(string)
}
Expand Down
1 change: 0 additions & 1 deletion pkg/s3-proxy/authx/authorization/header-oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func isHeaderOIDCAuthorizedBasic(groups []string, email string, authorizationAcc
}
} else {
// Not a regex case

// Check group case
if item.Group != "" {
result := funk.Contains(groups, item.Group)
Expand Down
2 changes: 2 additions & 0 deletions pkg/s3-proxy/authx/authorization/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func Middleware(
if resource.OIDC != nil || resource.Header != nil {
// Initialize variables
var authorizationProvider string
// Initialize variables
var headerOIDCResource *config.ResourceHeaderOIDC

// Check if resource is OIDC
Expand Down Expand Up @@ -103,6 +104,7 @@ func Middleware(
if headerOIDCResource.AuthorizationOPAServer != nil {
var err error
authorized, err = isOPAServerAuthorized(r, user, headerOIDCResource)
// Check error
if err != nil {
// Check if bucket request context doesn't exist to use local default files
if brctx == nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/s3-proxy/bucket/bucket-req-impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ func (bri *bucketReqImpl) Get(ctx context.Context, input *GetInput) {
err = err2
} else if headOutput != nil {
// File found

// Redirect to signed url
err = bri.redirectToSignedURL(ctx, key, input)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/s3-proxy/config/managerimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (impl *managerimpl) Load() error {
// Loop over config files
funk.ForEach(impl.configs, func(vip *viper.Viper) {
// Add hooks for on change events
vip.OnConfigChange(func(in fsnotify.Event) {
vip.OnConfigChange(func(_ fsnotify.Event) {
impl.logger.Infof("Reload configuration detected for file %s", vip.ConfigFileUsed())

// Reload config
Expand Down
4 changes: 2 additions & 2 deletions pkg/s3-proxy/config/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func validateSSLCertificateComponentConfig(
}

if componentURLConfig != nil {
err = validateSSLURLConfig(componentURLConfig, fmt.Sprintf("%sUrlConfig", componentName))
err = validateSSLURLConfig(componentURLConfig, componentName+"UrlConfig")
if err != nil {
return err
}
Expand All @@ -315,7 +315,7 @@ func validateSSLURLConfig(urlConfig *SSLURLConfig, component string) error {
if urlConfig.HTTPTimeout != "" {
duration, err := time.ParseDuration(urlConfig.HTTPTimeout)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("%s.httpTimeout is invalid", component))
return errors.Wrap(err, component+".httpTimeout is invalid")
}

if duration < time.Duration(0) {
Expand Down
9 changes: 5 additions & 4 deletions pkg/s3-proxy/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func (svr *Server) GenerateServer() error {
}
// Change server handler
server.Handler = r

svr.logger.Info("Server handler reloaded")
})

Expand Down Expand Up @@ -236,7 +237,7 @@ func (svr *Server) generateRouter() (http.Handler, error) {
// Add authorization middleware to router
rt2 = rt2.With(authorization.Middleware(svr.cfgManager, svr.metricsCl))

rt2.Get("/", func(rw http.ResponseWriter, req *http.Request) {
rt2.Get("/", func(_ http.ResponseWriter, req *http.Request) {
// Get response handler
resHan := responsehandler.GetResponseHandlerFromContext(req.Context())

Expand Down Expand Up @@ -286,7 +287,7 @@ func (svr *Server) generateRouter() (http.Handler, error) {
// Check if GET action is enabled
if tgt.Actions.GET != nil && tgt.Actions.GET.Enabled {
// Add GET method to router
rt2.Get("/*", func(rw http.ResponseWriter, req *http.Request) {
rt2.Get("/*", func(_ http.ResponseWriter, req *http.Request) {
// Get bucket request context
brctx := bucket.GetBucketRequestContextFromContext(req.Context())
// Get response handler
Expand Down Expand Up @@ -367,7 +368,7 @@ func (svr *Server) generateRouter() (http.Handler, error) {
// Check if PUT action is enabled
if tgt.Actions.PUT != nil && tgt.Actions.PUT.Enabled {
// Add PUT method to router
rt2.Put("/*", func(rw http.ResponseWriter, req *http.Request) {
rt2.Put("/*", func(_ http.ResponseWriter, req *http.Request) {
// Get bucket request context
brctx := bucket.GetBucketRequestContextFromContext(req.Context())
// Get response handler
Expand Down Expand Up @@ -429,7 +430,7 @@ func (svr *Server) generateRouter() (http.Handler, error) {
// Check if DELETE action is enabled
if tgt.Actions.DELETE != nil && tgt.Actions.DELETE.Enabled {
// Add DELETE method to router
rt2.Delete("/*", func(rw http.ResponseWriter, req *http.Request) {
rt2.Delete("/*", func(_ http.ResponseWriter, req *http.Request) {
// Get bucket request context
brctx := bucket.GetBucketRequestContextFromContext(req.Context())
// Get response handler
Expand Down
7 changes: 2 additions & 5 deletions pkg/s3-proxy/server/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"fmt"
"math/big"
"time"

Expand Down Expand Up @@ -142,8 +141,7 @@ func getCertificateFromConfig(certConfig *config.ServerSSLCertificate, logger lo
if err != nil {
logger.Errorf("Failed to get certificate from URL %s: %v", *certConfig.CertificateURL, err)

return nil, errors.Wrap(err, fmt.Sprintf(
"failed to get certificate from URL: %s", *certConfig.CertificateURL))
return nil, errors.Wrap(err, "failed to get certificate from URL: "+*certConfig.CertificateURL)
}

default:
Expand All @@ -164,8 +162,7 @@ func getCertificateFromConfig(certConfig *config.ServerSSLCertificate, logger lo
if err != nil {
logger.Errorf("Failed to get private key from URL %s: %v", *certConfig.PrivateKeyURL, err)

return nil, errors.Wrap(err, fmt.Sprintf(
"failed to get private key from URL: %s", *certConfig.PrivateKeyURL))
return nil, errors.Wrap(err, "failed to get private key from URL: "+*certConfig.PrivateKeyURL)
}

default:
Expand Down
10 changes: 5 additions & 5 deletions pkg/s3-proxy/utils/generalutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ type GetDocumentFromURLOption func(awsCfg *aws.Config, httpClient *http.Client)

// WithAWSEndpoint is an option for GetDocumentFromURL to set the AWS service endpoint.
func WithAWSEndpoint(endpoint string) GetDocumentFromURLOption {
return func(awsCfg *aws.Config, httpClient *http.Client) {
return func(awsCfg *aws.Config, _ *http.Client) {
if awsCfg != nil {
awsCfg.Endpoint = aws.String(endpoint)
}
Expand All @@ -189,7 +189,7 @@ func WithAWSEndpoint(endpoint string) GetDocumentFromURLOption {

// WithAWSRegion is an option for GetDocumentFromURL to set the AWS region.
func WithAWSRegion(region string) GetDocumentFromURLOption {
return func(awsCfg *aws.Config, httpClient *http.Client) {
return func(awsCfg *aws.Config, _ *http.Client) {
if awsCfg != nil {
awsCfg.Region = aws.String(region)
}
Expand All @@ -198,7 +198,7 @@ func WithAWSRegion(region string) GetDocumentFromURLOption {

// WithAWSDisableSSL is an option for GetDocumentFromURL to optionally disable SSL for requests.
func WithAWSDisableSSL(disableSSL bool) GetDocumentFromURLOption {
return func(awsCfg *aws.Config, httpClient *http.Client) {
return func(awsCfg *aws.Config, _ *http.Client) {
if awsCfg != nil {
awsCfg.DisableSSL = aws.Bool(disableSSL)
}
Expand All @@ -207,7 +207,7 @@ func WithAWSDisableSSL(disableSSL bool) GetDocumentFromURLOption {

// WithAWSStaticCredentials is an option for GetDocumentFromURL to set AWS credentials.
func WithAWSStaticCredentials(accessKey, secretKey, token string) GetDocumentFromURLOption {
return func(awsCfg *aws.Config, httpClient *http.Client) {
return func(awsCfg *aws.Config, _ *http.Client) {
if awsCfg != nil {
awsCfg.Credentials = credentials.NewStaticCredentials(accessKey, secretKey, token)
}
Expand Down Expand Up @@ -349,7 +349,7 @@ func getDocumentFromS3(bucket, key string, opts ...GetDocumentFromURLOption) ([]
// Otherwise, we end up with URLs like https://bucketname.127.0.0.1/
endpointURL, err := url.Parse(*cfg.Endpoint)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("invalid S3 endpoint URL: %s", *cfg.Endpoint))
return nil, errors.Wrap(err, "invalid S3 endpoint URL: "+*cfg.Endpoint)
}

hostIP := net.ParseIP(endpointURL.Hostname())
Expand Down
4 changes: 2 additions & 2 deletions pkg/s3-proxy/utils/templateutils/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package templateutils
import (
"bytes"
"context"
"fmt"
"os"
"strings"
"text/template"
Expand Down Expand Up @@ -154,8 +153,9 @@ func s3ProxyFuncMap(t *template.Template) template.FuncMap {

if v, ok := includedNames[name]; ok {
if v > recursionMaxNums {
return "", errors.Wrapf(fmt.Errorf("unable to execute template"), "rendering template has a nested reference name: %s", name)
return "", errors.Wrapf(errors.New("unable to execute template"), "rendering template has a nested reference name: %s", name)
}

includedNames[name]++
} else {
includedNames[name] = 1
Expand Down

0 comments on commit 3359f59

Please sign in to comment.