config

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2020 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AtLeastOne = func(o *Options) {
	o.ValidationRule = atLeastOne
}

AtLeastOne is an option that defines at least on of permissions or roles should match to pass.

View Source
var BlastlistedDomains = []string{}
View Source
var MatchAll = func(o *Options) {
	o.ValidationRule = matchAll
}

MatchAll is an option that defines all permissions or roles should match the user.

View Source
var ViperConfig *viper.Viper //nolint:gochecknoglobals

Functions

func BootApp

func BootApp()

func CustomErrorHandler

func CustomErrorHandler(c *fiber.Ctx, err error) error

func DeleteToken

func DeleteToken(c *fiber.Ctx)

DeleteToken deletes the jwt token

func GenerateAppKey

func GenerateAppKey(length int)

func LoadAppConfig

func LoadAppConfig()

func LoadAuthConfig

func LoadAuthConfig()

func LoadCacheConfig

func LoadCacheConfig()

func LoadCacheHeaders

func LoadCacheHeaders(c *fiber.Ctx) error

func LoadDBConfig

func LoadDBConfig()

func LoadEnv

func LoadEnv()

func LoadHeaders

func LoadHeaders(c *fiber.Ctx) error

func LoadMailConfig

func LoadMailConfig()

func LoadPaypalConfig

func LoadPaypalConfig()

func LoadQueueConfig

func LoadQueueConfig()

func LoadSession

func LoadSession()

func LoadSessionConfig

func LoadSessionConfig()

func ParseToken

func ParseToken(c *fiber.Ctx, secret string) (uint, error)

ParseToken returns the users id or error

func PermissionParserWithSeperator

func PermissionParserWithSeperator(sep string) func(o *Options)

PermissionParserWithSeperator is an option that parses permission with seperators

func PrepareHtml

func PrepareHtml(view string, body fiber.Map) string

func Send

func Send(to string, subject string, body string, cc string, from string)

func SetupDB

func SetupDB() (*gorm.DB, error)

func SetupMailer

func SetupMailer()

func SetupPermission

func SetupPermission()

Types

type AppConfiguration

type AppConfiguration struct {
	App_Name        string
	App_Upload_Path string
	App_Upload_Size int
	App_Env         string
	App_Key         string
	App_Url         string
	App_Port        string
}
var AppConfig *AppConfiguration //nolint:gochecknoglobals

type AuthConfiguration

type AuthConfiguration struct {
	App_Jwt_Secret string
	Api_Jwt_Secret string
	Jwt_Expire     int
}
var AuthConfig *AuthConfiguration //nolint:gochecknoglobals

type CacheConfiguration

type CacheConfiguration struct {
	Cache_DSN string
	Cache_DB  int
}
var CacheConfig *CacheConfiguration //nolint:gochecknoglobals

type Database

type Database struct {
	DB_Driver string //nolint:goimports,gofmt
	DB_Host   string
	DB_Port   int
	DB_User   string
	DB_Pass   string
	DB_Name   string
}
var DBConfig *Database //nolint:gochecknoglobals

type MailConfiguration

type MailConfiguration struct {
	Mail_Host         string
	Mail_Port         int
	Mail_Username     string
	Mail_Password     string
	Mail_Encryption   string
	Mail_From_Address string
	Mail_From_Name    string
}
var MailConfig *MailConfiguration //nolint:gochecknoglobals

type Options

type Options struct {
	ValidationRule   validationRule
	PermissionParser PermissionParserFunc
}

Options holds options of middleware

type PaypalConfiguration

type PaypalConfiguration struct {
	Paypal_Client_ID string
	Paypal_Secret    string
}
var PaypalConfig *PaypalConfiguration //nolint:gochecknoglobals

type PermissionMiddleware

type PermissionMiddleware struct {
	// ModelFilePath is path to model file for Casbin.
	// Optional. Default: "./model.conf".
	Enforcer *casbin.Enforcer

	// PolicyAdapter is an interface for different persistent providers.
	// Optional. Default: fileadapter.NewAdapter("./policy.csv").
	PolicyAdapter *gormadapter.Adapter

	// Lookup is a function that is used to look up current subject.
	// An empty string is considered as unauthenticated user.
	// Optional. Default: func(c *fiber.Ctx) string { return "" }
	Lookup func(*fiber.Ctx) string

	// Unauthorized defines the response body for unauthorized responses.
	// Optional. Default: func(c *fiber.Ctx) string { c.SendStatus(401) }
	Unauthorized func(*fiber.Ctx) error

	// Forbidden defines the response body for forbidden responses.
	// Optional. Default: func(c *fiber.Ctx) string { c.SendStatus(403) }
	Forbidden func(*fiber.Ctx) error
}

Config holds the configuration for the middleware

func (*PermissionMiddleware) RequiresPermissions

func (cm *PermissionMiddleware) RequiresPermissions(permissions []string, opts ...func(o *Options)) func(*fiber.Ctx) error

RequiresPermissions tries to find the current subject and determine if the subject has the required permissions according to predefined Casbin policies.

func (*PermissionMiddleware) RequiresRoles

func (cm *PermissionMiddleware) RequiresRoles(roles []string, opts ...func(o *Options)) func(*fiber.Ctx) error

RequiresRoles tries to find the current subject and determine if the subject has the required roles according to predefined Casbin policies.

func (*PermissionMiddleware) RoutePermission

func (cm *PermissionMiddleware) RoutePermission() func(*fiber.Ctx) error

RoutePermission tries to find the current subject and determine if the subject has the required permissions according to predefined Casbin policies. This method uses http Path and Method as object and action.

type PermissionParserFunc

type PermissionParserFunc func(str string) []string

PermissionParserFunc is used for parsing the permission to extract object and action usually

type QueueConfiguration

type QueueConfiguration struct {
	Queue_User  string
	Queue_Pass  string
	Queue_Host  string
	Queue_Port  string
	Queue_VHost string
}
var QueueConfig *QueueConfiguration //nolint:gochecknoglobals

type SessionConfiguration

type SessionConfiguration struct {
	Session_DSN    string
	Session_DB     int
	Session_Lookup string
}
var SessionConfig *SessionConfiguration //nolint:gochecknoglobals

type Token

type Token struct {
	Hash   string
	Expire int64
}

func CreateToken

func CreateToken(c *fiber.Ctx, userID uint, secret string) (Token, error)

CreateToken authenticates the user

func RefreshToken

func RefreshToken(c *fiber.Ctx, secret string) (Token, error)

RefreshToken refreshes the token

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL