Documentation ¶
Index ¶
- func CorsConfig(conf *config.Configuration) cors.Config
- func GenerateApplicationToken() string
- func GenerateClientToken() string
- func GenerateImageName() string
- func GenerateNotExistingToken(generateToken func() string, tokenExists func(token string) bool) string
- func GeneratePluginToken() string
- func GetTokenID(ctx *gin.Context) string
- func GetUserID(ctx *gin.Context) uint
- func RegisterAuthentication(ctx *gin.Context, user *model.User, userID uint, tokenID string)
- func TryGetUserID(ctx *gin.Context) *uint
- type Auth
- type Database
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CorsConfig ¶
func CorsConfig(conf *config.Configuration) cors.Config
CorsConfig generates a config to use in gin cors middleware based on server configuration.
func GenerateApplicationToken ¶
func GenerateApplicationToken() string
GenerateApplicationToken generates an application token.
func GenerateClientToken ¶
func GenerateClientToken() string
GenerateClientToken generates a client token.
func GenerateNotExistingToken ¶
func GenerateNotExistingToken(generateToken func() string, tokenExists func(token string) bool) string
GenerateNotExistingToken receives a token generation func and a func to check whether the token exists, returns a unique token.
func GeneratePluginToken ¶
func GeneratePluginToken() string
GeneratePluginToken generates a plugin token.
func GetUserID ¶
GetUserID returns the user id which was previously registered by RegisterAuthentication.
func RegisterAuthentication ¶
RegisterAuthentication registers the user id, user and or token.
func TryGetUserID ¶ added in v2.1.0
TryGetUserID returns the user id or nil if one is not set.
Types ¶
type Auth ¶
type Auth struct {
DB Database
}
Auth is the provider for authentication middleware.
func (*Auth) Optional ¶ added in v2.1.0
func (a *Auth) Optional() gin.HandlerFunc
func (*Auth) RequireAdmin ¶
func (a *Auth) RequireAdmin() gin.HandlerFunc
RequireAdmin returns a gin middleware which requires a client token or basic authentication header to be supplied with the request. Also the authenticated user must be an administrator.
func (*Auth) RequireApplicationToken ¶
func (a *Auth) RequireApplicationToken() gin.HandlerFunc
RequireApplicationToken returns a gin middleware which requires an application token to be supplied with the request.
func (*Auth) RequireClient ¶
func (a *Auth) RequireClient() gin.HandlerFunc
RequireClient returns a gin middleware which requires a client token or basic authentication header to be supplied with the request.
type Database ¶
type Database interface { GetApplicationByToken(token string) (*model.Application, error) GetClientByToken(token string) (*model.Client, error) GetPluginConfByToken(token string) (*model.PluginConf, error) GetUserByName(name string) (*model.User, error) GetUserByID(id uint) (*model.User, error) }
The Database interface for encapsulating database access.