baseuser

package
v0.0.0-...-37076da Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package baseuser is a domain package wich contains the common users features and behavior.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidBaseUsrImplementation = errors.New("invalid base user implementation")

Functions

func IsProducer

func IsProducer(b BaseUser) bool

Check if the user implementation is producer

func IsStudent

func IsStudent(b BaseUser) bool

Check if the user implementation is Student

Types

type ACL

type ACL interface {
	// CanRead will check if the current user can read the resource
	CanRead(resource Resource) bool
	// CanWrite will check if the current user can write the resource
	CanWrite(resource Resource) bool
	// FullAccess will check if the current user can read and write the resource
	FullAccess(resource Resource) bool
	// GetResources will return two slices from resources.
	// Readable resources and Writable resources in order.
	GetResources() ([]Resource, []Resource)
}

ACL will provide the access control list for the current user and the resources that can be accessed by the current user

func NewACL

func NewACL(opts ...ACLOptions) ACL

NewACL returns a new ACL with permissions configured by the given options.

func ProducerACL

func ProducerACL() ACL

ProducerACL is the ACL for a producer.

The ACL preconfigured for a producer.

func StudentACL

func StudentACL() ACL

StudentACL is the ACL for a student.

The ACL preconfigured for a student.

type ACLOptions

type ACLOptions func(a *acl)

ACLOptions is a function that will be used to configure the ACL

func CanRead

func CanRead(resource Resource) ACLOptions

CanRead set ACLOptions to allow read access to the given resource.

func CanWrite

func CanWrite(resource Resource) ACLOptions

CanWrite set ACLOptions to allow write access to the given resource.

func FullAccess

func FullAccess(resource Resource) ACLOptions

FullAccess set ACLOptions to allow read and write access to the given resource.

type BaseUser

type BaseUser interface {
	// GetID will return the current user id
	GetID() string
	// GetEmail will return the current user email
	GetEmail() string
	// GetPassword will return the current user password
	GetPassword() string
	// GetScope will return the user scope
	GetScope() Scope
	// GetACL will return ACL for the current user
	GetACL() ACL

	// SyncData receives an array of options and applies them to the current user
	SyncData(usrOption ...Option) error

	// IsPasswordValid will check if the user password received
	// is valid password for the current user
	IsPasswordValid(password string) bool

	// HashPassword will hash the password received and return the hash
	//
	// It should have a password, else it will return an error
	HashPassword() error

	// AddScope will add current scope to current user.
	//
	// Looks possible cases:
	//
	// 		student.AddScope(PRODUCER)	// student.GetScope()	=> BOTH
	// 		producer.AddScope(STUDENT)	// producer.GetScope()	=> BOTH
	// 		student.AddScope(STUDENT) 	// student.GetScope()	=> STUDENT
	// 		producer.AddScope(PRODUCER)	// producer.GetScope()	=> PRODUCER
	// 		student.AddScope(BOTH) 		// student.GetScope()	=> BOTH
	// 		producer.AddScope(BOTH)		// producer.GetScope()	=> BOTH
	//
	// If user scope is `student` and call `AddScope(PRODUCER)`, it
	// will make user scope as `BOTH`.
	//
	// If user scope is `producer` and call `AddScope(STUDENT)`, it
	// will make user scope as `BOTH` too.
	//
	// If current scope matches with call `AddScope`. Nothing happens
	AddScope(Scope)
}

type Option

type Option func(u BaseUser) error

Option is a optional function argument for BaseUser

It will be used to configure the BaseUser instance

type Resource

type Resource string

Resource is a custom type to represent the different resources that can be used in the ACL

const (
	GetMe  Resource = "get_me"
	Login  Resource = "login"
	Logout Resource = "logout"
)

func (Resource) String

func (r Resource) String() string

String will only parse resource to a string

type Scope

type Scope string

Scope is a config option to users.

It determines if user is a student, producer or both

const (
	STUDENT  Scope = "student"
	PRODUCER Scope = "producer"
	BOTH     Scope = "both"
)

func (Scope) String

func (s Scope) String() string

String will return scope as string

Jump to

Keyboard shortcuts

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