2022-11-16 23:46:24 +01:00
|
|
|
/*
|
|
|
|
Package reqcontext contains the request context. Each request will have its own instance of RequestContext filled by the
|
|
|
|
middleware code in the api-context-wrapper.go (parent package).
|
|
|
|
|
|
|
|
Each value here should be assumed valid only per request only, with some exceptions like the logger.
|
|
|
|
*/
|
|
|
|
package reqcontext
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gofrs/uuid"
|
2022-11-18 13:05:40 +01:00
|
|
|
"github.com/notherealmarco/WASAPhoto/service/database"
|
2022-11-16 23:46:24 +01:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2022-11-18 17:18:46 +01:00
|
|
|
type AuthStatus int
|
|
|
|
|
|
|
|
const (
|
|
|
|
AUTHORIZED = 0
|
|
|
|
UNAUTHORIZED = 1
|
|
|
|
FORBIDDEN = 2
|
|
|
|
)
|
|
|
|
|
2022-11-16 23:46:24 +01:00
|
|
|
// RequestContext is the context of the request, for request-dependent parameters
|
|
|
|
type RequestContext struct {
|
|
|
|
// ReqUUID is the request unique ID
|
|
|
|
ReqUUID uuid.UUID
|
|
|
|
|
|
|
|
// Logger is a custom field logger for the request
|
|
|
|
Logger logrus.FieldLogger
|
2022-11-18 13:05:40 +01:00
|
|
|
|
|
|
|
Auth Authorization
|
|
|
|
}
|
|
|
|
|
|
|
|
type Authorization interface {
|
|
|
|
GetType() string
|
|
|
|
Authorized(db database.AppDatabase) (bool, error)
|
2022-11-18 17:18:46 +01:00
|
|
|
UserAuthorized(db database.AppDatabase, uid string) (AuthStatus, error)
|
2022-11-16 23:46:24 +01:00
|
|
|
}
|