db

package
v1.0.1-0...-3a959c6 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package db contains methods to retrieve and modify local data.

Index

Constants

This section is empty.

Variables

View Source
var Enforcer *casbin.Enforcer

Enforcer is the casbin enforcer used for authorization.

View Source
var ErrAlreadyExists = errors.New("new entity already existed")

ErrAlreadyExists means that the new entity already existed.

View Source
var ErrNotFound = skv.ErrNotFound

ErrNotFound means that the requested entity was not found.

View Source
var ErrRoleHasPolicies = errors.New("there are policies associated with this role")

ErrRoleHasPolicies means that there are policies associated with this role.

View Source
var ErrRoleHasUsers = errors.New("there are users associated with this role")

ErrRoleHasUsers means that there are users associated with this role.

View Source
var ErrRoleNotFound = errors.New("associated role was not found")

ErrRoleNotFound means that the associated role was not found.

View Source
var (
	// RoleDB is the KV-Store for roles.
	RoleDB *skv.KVStore
)
View Source
var (
	// UserDB is the KV-Store for users.
	UserDB *skv.KVStore
)

Functions

func AddPolicy

func AddPolicy(p *db.Policy) (err error)

AddPolicy adds the policy. possible errors: ErrRoleNotFound, ErrAlreadyExists.

func CreateRole

func CreateRole(role db.Role) error

CreateRole creates the role. possible errors: ErrAlreadyExists.

func CreateUser

func CreateUser(user *db.User) error

CreateUser creates the user and hash and salts the password. possible errors: ErrAlreadyExists, ErrRoleNotFound.

func DeletePolicy

func DeletePolicy(p *db.Policy) (err error)

DeletePolicy deletes the policy. possible errors: ErrNotFound.

func DeleteRole

func DeleteRole(name string) error

DeleteRole deletes the role. possible errors: ErrNotFound, ErrRoleHasUsers, ErrRoleHasPolicies.

func DeleteUser

func DeleteUser(name string) error

DeleteUser deletes the user. possible errors: ErrNotFound.

func GetPolicies

func GetPolicies() (result []*db.Policy, err error)

GetPolicies returns all policies.

func GetRole

func GetRole(name string) (db.Role, error)

GetRole returns the role with the name. possible errors: ErrNotFound.

func GetRoles

func GetRoles() ([]db.Role, error)

GetRoles returns alls roles.

func GetUser

func GetUser(name string) (*db.User, error)

GetUser returns the associated user. possible errors: ErrNotFound.

func GetUsers

func GetUsers() ([]*db.User, error)

GetUsers returns all users.

func GetUsersByRole

func GetUsersByRole(role string) ([]*db.User, error)

GetUsersByRole returns all users associated with the role possible errors: ErrRoleNotFound

func RoleExists

func RoleExists(name string) (bool, error)

RoleExists checks if the role exists.

func UpdateUser

func UpdateUser(name string, update *db.User) error

UpdateUser updates the user. hash and salts the password if updated. possible errors: ErrNotFound, ErrRoleNotFound.

func UserExists

func UserExists(name string) (bool, error)

UserExists checks if the user exists.

Types

This section is empty.

Directories

Path Synopsis
Package models contains models for the DB package
Package models contains models for the DB package

Jump to

Keyboard shortcuts

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