auth

package
v0.0.0-...-94e6d93 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingParameters is returned if some required fields on the input message are missing / unset
	ErrMissingParameters = eris.New("some parameters are missing")

	// ErrDbIssue is returned if the request could not be processed due to DB issues
	ErrDbIssue = eris.New("a DB query failed")

	// ErrAuthCtxMissing is returned if the request didn't contain an authContext
	ErrAuthCtxMissing = eris.New("auth context missing")
)
View Source
var ErrInvalidRole = eris.New("invalid user role")

ErrInvalidRole is returned if the current user has an invalid role

View Source
var ErrInvalidTarget = eris.New("invalid target")

ErrInvalidTarget is returned if the target doesn't follow the expected format

Functions

func CheckPermission

func CheckPermission(ctx context.Context, perm Permission, bag Bag) error

CheckPermission verifies that the currently authenticated user has the given permission

func GetRole

func GetRole(ctx context.Context) (*rbac.Role, error)

GetRole checks authentication if necessary and returns the user's role

func GetUser

func GetUser(ctx context.Context) (guardian.Info, error)

GetUser returns the current user info

func Init

func Init(q *queries.DBQuerier)

Init prepares static objects used throughout the lifecycle

func IssueToken

func IssueToken(ctx context.Context, username string, uid int, roles []string) (string, error)

IssueToken generates a new session token with the associated user

func MakeAuthMiddleware

func MakeAuthMiddleware(next http.Handler) http.Handler

MakeAuthMiddleware constructs the necessary middleware required for our Auth* API

func MarshalBag

func MarshalBag(src interface{}) (string, error)

func UnmarshalBag

func UnmarshalBag(data string, dest interface{}) error

Types

type Bag

type Bag struct{}

type ModBag

type ModBag struct {
	Bag
	UserID         int
	ModID          string
	ReleaseVersion string
}

type Permission

type Permission string
const (
	// Mods [takes ModBag]
	PermViewMod   Permission = "ViewMod"
	PermCreateMod Permission = "CreateMod"
	PermEditMod   Permission = "EditMod"
	PermDeleteMod Permission = "DeleteMod"

	// Special perms [takes ModBag]
	PermEditModTeam  Permission = "EditModTeam"
	PermCreateEngine Permission = "CreateEngine"

	// Releases [takes ModBag]
	PermViewRelease   Permission = "ViewRelease"
	PermCreateRelease Permission = "CreateRelease"
	PermEditRelease   Permission = "EditRelease"
	PermDeleteRelease Permission = "DeleteRelease"

	// Users [takes UserBag]
	// Note: CreateUser does *not* apply to the normal registration process
	PermCreateUser Permission = "CreateUser"
	PermEditUser   Permission = "EditUser"
	PermDeleteUser Permission = "DeleteUser"
)

type UserBag

type UserBag struct {
	Bag
	CurrentUser int
	TargetUser  int
}

Jump to

Keyboard shortcuts

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