utils

package
v0.0.0-...-8bc6207 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoToken      = errors.New("token not found")
	ErrInvalidToken = errors.New("invalid token")
)

Functions

func NewDB

func NewDB(config DatabaseConfig) (bucket *gocb.Bucket, err error)

NewDB Initialises the connection to the database

Types

type AFCAccessClaims

type AFCAccessClaims struct {
	Id   uint64 `json:"id"`
	Role string `json:"role"`
	jwt.StandardClaims
}

type AccessClaims

type AccessClaims struct {
	UserID      int      `json:"id"`
	Role        string   `json:"role"`
	Permissions []string `json:"perms"`
	jwt.StandardClaims
}

AccessClaims represents an identifiable JWT

type Accesser

type Accesser struct {
	// contains filtered or unexported fields
}

func NewAccesser

func NewAccesser(conf Config) *Accesser

NewAccesser allows the validation of JWT tokens both as headers and as cookies

func (*Accesser) AFCAdminMiddleware

func (a *Accesser) AFCAdminMiddleware(next echo.HandlerFunc) echo.HandlerFunc

func (*Accesser) AFCAuthMiddleware

func (a *Accesser) AFCAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc

AFCAuthMiddleware checks a HTTP request for a valid token either in the header or cookie

func (*Accesser) AdminAuthMiddleware

func (a *Accesser) AdminAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc

AdminAuthMiddleware checks a HTTP request for a valid token either in the header or cookie

func (*Accesser) AdminInitAuthMiddleware

func (a *Accesser) AdminInitAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc

AdminInitAuthMiddleware checks a HTTP request for a valid token either in the header or cookie

func (*Accesser) AuthMiddleware

func (a *Accesser) AuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc

AuthMiddleware checks a HTTP request for a valid token either in the header or cookie

func (*Accesser) FindAdminToken

func (a *Accesser) FindAdminToken(r *http.Request) bool

FindAdminToken will return the claims from an AFC access token JWT

First will check the Authorization header, if unset will check the access cookie

func (*Accesser) GetAFCToken

func (a *Accesser) GetAFCToken(r *http.Request) (*AFCAccessClaims, error)

GetAFCToken will return the claims from an AFC access token JWT

First will check the Authorization header, if unset will check the access cookie

func (*Accesser) GetAdminToken

func (a *Accesser) GetAdminToken(r *http.Request) (*jwt.Token, error)

GetAdminToken will return the claims from an admin access token JWT

First will check the Authorization header, if unset will check the access cookie

func (*Accesser) GetAdminTokenKIDAndClaims

func (a *Accesser) GetAdminTokenKIDAndClaims(r *http.Request) (string, *jwt.StandardClaims, error)

GetAdminToken will return the claims from an admin access token JWT

First will check the Authorization header, if unset will check the access cookie

func (*Accesser) GetToken

func (a *Accesser) GetToken(r *http.Request) (*AccessClaims, error)

GetToken will return the claims from an access token JWT

First will check the Authorization header, if unset will check the access cookie

func (*Accesser) NilMiddleware

func (a *Accesser) NilMiddleware(next echo.HandlerFunc) echo.HandlerFunc

NilMiddleware checks a HTTP request for a valid token either in the header or cookie

type Admin

type Admin struct {
	AdminAccessCookieName, Key0, Key1, Key2, Key3, TOTP string
}

type AdminRequest

type AdminRequest struct {
	Key0     string `json:"key_0"`
	Key1     string `json:"key_1"`
	Key2     string `json:"key_2"`
	Key3     string `json:"key_3"`
	TOTPCode string `json:"totp_code"`
}

type AdminResponse

type AdminResponse struct {
	JWTToken string `json:"jwt_token"`
}

type Config

type Config struct {
	AccessCookieName string
	SigningKey       []byte
	DomainName       string
	Admin            Admin
}

type DatabaseConfig

type DatabaseConfig struct {
	Host     string
	SSLMode  string
	Bucket   string
	Username string
	Password string
}

DatabaseConfig represents a configuration to connect to an SQL database

type Defaults

type Defaults struct {
	DefaultTo   string
	DefaultCC   []string
	DefaultBCC  []string
	DefaultFrom string
}

Defaults allows for default recipients to be set

type Error

type Error struct {
	Error string `json:"error"`
}

type Mail

type Mail struct {
	Subject     string
	To          string
	Cc          []string
	Bcc         []string
	From        string
	Error       error
	UseDefaults bool
	Tpl         *template.Template
	TplData     interface{}
}

Mail represents an email to be sent

type MailConfig

type MailConfig struct {
	Host     string
	Port     int
	Username string
	Password string
}

MailConfig represents a configuration to connect to an SMTP server

type Mailer

type Mailer struct {
	*mail.SMTPClient
	Defaults Defaults
	Enabled  bool
}

Mailer encapsulates the dependency

func NewMailer

func NewMailer(config MailConfig) (*Mailer, error)

NewMailer creates a new SMTP client

func (*Mailer) AddDefaults

func (m *Mailer) AddDefaults(defaults Defaults)

AddDefaults adds the default recipients

func (*Mailer) CheckSendable

func (m *Mailer) CheckSendable(item Mail) error

CheckSendable verifies that the email can be sent

func (*Mailer) SendErrorFatalMail

func (m *Mailer) SendErrorFatalMail(item Mail) error

SendErrorFatalMail sends a standard template error fatal email

func (*Mailer) SendErrorMail

func (m *Mailer) SendErrorMail(item Mail) error

SendErrorMail sends a standard template error email

func (*Mailer) SendMail

func (m *Mailer) SendMail(item Mail) error

SendMail sends a template email

type Permission

type Permission struct {
	Name string `json:"name"`
}

Permission represents the permissions that a user has

Jump to

Keyboard shortcuts

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