gateway: fix linter errors
Fix errors reported by default golangci-lint linters
This commit is contained in:
parent
f152b6a6da
commit
c5abbee3d8
|
@ -21,7 +21,6 @@ import (
|
|||
csapi "agola.io/agola/internal/services/configstore/api"
|
||||
"agola.io/agola/internal/services/types"
|
||||
"agola.io/agola/internal/util"
|
||||
"go.uber.org/zap"
|
||||
|
||||
errors "golang.org/x/xerrors"
|
||||
)
|
||||
|
@ -66,11 +65,6 @@ type CreateSecretRequest struct {
|
|||
Path string
|
||||
}
|
||||
|
||||
type CreateSecretHandler struct {
|
||||
log *zap.SugaredLogger
|
||||
configstoreClient *csapi.Client
|
||||
}
|
||||
|
||||
func (h *ActionHandler) CreateSecret(ctx context.Context, req *CreateSecretRequest) (*csapi.Secret, error) {
|
||||
isVariableOwner, err := h.IsVariableOwner(ctx, req.ParentType, req.ParentRef)
|
||||
if err != nil {
|
||||
|
|
|
@ -78,22 +78,22 @@ func httpError(w http.ResponseWriter, err error) bool {
|
|||
switch {
|
||||
case errors.Is(err, &util.ErrBadRequest{}):
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write(resj)
|
||||
_, _ = w.Write(resj)
|
||||
case errors.Is(err, &util.ErrNotFound{}):
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
w.Write(resj)
|
||||
_, _ = w.Write(resj)
|
||||
case errors.Is(err, &util.ErrForbidden{}):
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
w.Write(resj)
|
||||
_, _ = w.Write(resj)
|
||||
case errors.Is(err, &util.ErrUnauthorized{}):
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
w.Write(resj)
|
||||
_, _ = w.Write(resj)
|
||||
case errors.Is(err, &util.ErrInternal{}):
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write(resj)
|
||||
_, _ = w.Write(resj)
|
||||
default:
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write(resj)
|
||||
_, _ = w.Write(resj)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ func httpErrorFromRemote(w http.ResponseWriter, resp *http.Response, err error)
|
|||
} else {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
w.Write(resj)
|
||||
_, _ = w.Write(resj)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
|
|
@ -176,7 +176,7 @@ func createUserResponse(u *types.User) *UserResponse {
|
|||
for tokenName := range u.Tokens {
|
||||
user.Tokens = append(user.Tokens, tokenName)
|
||||
}
|
||||
sort.Sort(sort.StringSlice(user.Tokens))
|
||||
sort.Strings(user.Tokens)
|
||||
|
||||
for _, la := range u.LinkedAccounts {
|
||||
user.LinkedAccounts = append(user.LinkedAccounts, &LinkedAccountResponse{
|
||||
|
|
|
@ -137,15 +137,10 @@ func NewGateway(gc *config.Config) (*Gateway, error) {
|
|||
}
|
||||
|
||||
func (g *Gateway) Run(ctx context.Context) error {
|
||||
// noop coors handler
|
||||
corsHandler := func(h http.Handler) http.Handler {
|
||||
return h
|
||||
}
|
||||
|
||||
corsAllowedMethodsOptions := ghandlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "DELETE"})
|
||||
corsAllowedHeadersOptions := ghandlers.AllowedHeaders([]string{"Accept", "Accept-Encoding", "Authorization", "Content-Length", "Content-Type", "X-CSRF-Token", "Authorization"})
|
||||
corsAllowedOriginsOptions := ghandlers.AllowedOrigins([]string{"*"})
|
||||
corsHandler = ghandlers.CORS(corsAllowedMethodsOptions, corsAllowedHeadersOptions, corsAllowedOriginsOptions)
|
||||
corsHandler := ghandlers.CORS(corsAllowedMethodsOptions, corsAllowedHeadersOptions, corsAllowedOriginsOptions)
|
||||
|
||||
webhooksHandler := api.NewWebhooksHandler(logger, g.ah, g.configstoreClient, g.runserviceClient, g.c.APIExposedURL)
|
||||
|
||||
|
@ -307,7 +302,7 @@ func (g *Gateway) Run(ctx context.Context) error {
|
|||
router.Handle("/webhooks", webhooksHandler).Methods("POST")
|
||||
router.PathPrefix("/").HandlerFunc(handlers.NewWebBundleHandlerFunc(g.c.APIExposedURL))
|
||||
|
||||
maxBytesHandler := handlers.NewMaxBytesHandler(router, 1024*1024)
|
||||
maxBytesHandler := handlers.NewMaxBytesHandler(router, maxRequestSize)
|
||||
|
||||
mainrouter := mux.NewRouter()
|
||||
mainrouter.PathPrefix("/repos/").Handler(corsHandler(reposRouter))
|
||||
|
|
|
@ -150,7 +150,7 @@ func (h *AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
func stripPrefixFromTokenString(prefix string) func(tok string) (string, error) {
|
||||
return func(tok string) (string, error) {
|
||||
pl := len(prefix)
|
||||
if len(tok) > pl && strings.ToUpper(tok[0:pl+1]) == strings.ToUpper(prefix+" ") {
|
||||
if len(tok) > pl && strings.EqualFold(tok[0:pl+1], prefix+" ") {
|
||||
return tok[pl+1:], nil
|
||||
}
|
||||
return "", nil
|
||||
|
@ -161,20 +161,20 @@ func stripPrefixFromTokenString(prefix string) func(tok string) (string, error)
|
|||
// header
|
||||
// Uses PostExtractionFilter to strip "token " prefix from header
|
||||
var TokenExtractor = &jwtrequest.PostExtractionFilter{
|
||||
jwtrequest.MultiExtractor{
|
||||
Extractor: jwtrequest.MultiExtractor{
|
||||
jwtrequest.HeaderExtractor{"Authorization"},
|
||||
jwtrequest.ArgumentExtractor{"access_token"},
|
||||
},
|
||||
stripPrefixFromTokenString("token"),
|
||||
Filter: stripPrefixFromTokenString("token"),
|
||||
}
|
||||
|
||||
// BearerTokenExtractor extracts a bearer token in format "bearer THETOKEN" from
|
||||
// Authorization header
|
||||
// Uses PostExtractionFilter to strip "Bearer " prefix from header
|
||||
var BearerTokenExtractor = &jwtrequest.PostExtractionFilter{
|
||||
jwtrequest.MultiExtractor{
|
||||
Extractor: jwtrequest.MultiExtractor{
|
||||
jwtrequest.HeaderExtractor{"Authorization"},
|
||||
jwtrequest.ArgumentExtractor{"access_token"},
|
||||
},
|
||||
stripPrefixFromTokenString("bearer"),
|
||||
Filter: stripPrefixFromTokenString("bearer"),
|
||||
}
|
||||
|
|
|
@ -51,7 +51,9 @@ func NewWebBundleHandlerFunc(gatewayURL string) func(w http.ResponseWriter, r *h
|
|||
gatewayURL,
|
||||
"/api/v1alpha",
|
||||
}
|
||||
configTpl.Execute(&buf, configTplData)
|
||||
if err := configTpl.Execute(&buf, configTplData); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
config := buf.Bytes()
|
||||
|
||||
|
|
Loading…
Reference in New Issue