linting and other cleanups

This commit is contained in:
Florian Schade
2020-11-16 14:01:32 +01:00
committed by Benedikt Kulmann
parent f8aa1a5e08
commit 8be5323276
8 changed files with 16 additions and 8 deletions

View File

@@ -267,7 +267,7 @@ func loadMiddlewares(ctx context.Context, l log.Logger, cfg *config.Config) alic
}
return alice.New(
middleware.HTTPsRedirect,
middleware.HTTPSRedirect,
middleware.OIDCAuth(
middleware.Logger(l),
middleware.OIDCProviderFunc(func() (middleware.OIDCProvider, error) {

View File

@@ -17,6 +17,8 @@ import (
"strings"
)
// AccountResolver provides a middleware which mints a jwt and adds it to the proxied request based
// on the oidc-claims
func AccountResolver(optionSetters ...Option) func(next http.Handler) http.Handler {
options := newOptions(optionSetters...)
logger := options.Logger

View File

@@ -9,6 +9,7 @@ import (
"strings"
)
// BasicAuth provides a middleware to check if BasicAuth is provided
func BasicAuth(optionSetters ...Option) func(next http.Handler) http.Handler {
options := newOptions(optionSetters...)

View File

@@ -14,6 +14,7 @@ import (
"net/http"
)
// CreateHome provides a middleware which sends a CreateHome request to the reva gateway
func CreateHome(optionSetters ...Option) func(next http.Handler) http.Handler {
options := newOptions(optionSetters...)
logger := options.Logger

View File

@@ -5,8 +5,8 @@ import (
"net/http"
)
// RedirectToHTTPS redirects insecure requests to https
func HTTPsRedirect(next http.Handler) http.Handler {
// HTTPSRedirect redirects insecure requests to https
func HTTPSRedirect(next http.Handler) http.Handler {
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
proto := req.Header.Get("x-forwarded-proto")
if proto == "http" || proto == "HTTP" {

View File

@@ -5,7 +5,12 @@ import (
)
var (
// ErrInvalidToken is returned when the request token is invalid.
ErrInvalidToken = errors.New("invalid or missing token")
// ErrUnauthorized is returned if the request is not authorized
ErrUnauthorized = errors.New("unauthorized")
// ErrInternal is returned if something went wrong
ErrInternal = errors.New("internal error")
)

View File

@@ -10,10 +10,12 @@ import (
"strings"
)
// OIDCProvider used to mock the oidc provider during tests
type OIDCProvider interface {
UserInfo(ctx context.Context, ts oauth2.TokenSource) (*gOidc.UserInfo, error)
}
// OIDCAuth provides a middleware to check access secured by a static token.
func OIDCAuth(optionSetters ...Option) func(next http.Handler) http.Handler {
options := newOptions(optionSetters...)
@@ -111,9 +113,5 @@ func (m oidcAuth) shouldServe(req *http.Request) bool {
}
}
if !strings.HasPrefix(header, "Bearer ") {
return false
}
return true
return strings.HasPrefix(header, "Bearer ")
}

View File

@@ -19,6 +19,7 @@ import (
"time"
)
// SignedURLAuth provides a middleware to check access secured by a signed URL.
func SignedURLAuth(optionSetters ...Option) func(next http.Handler) http.Handler {
options := newOptions(optionSetters...)