auth

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MatchAll      string = "*"
	MatchWildcard        = "#"
)
View Source
const (
	PermissionAuthUserSelfWrite        Permission = "auth.user.self.write"
	PermissionAuthUserCompanyWrite                = "auth.user.company.write"
	PermissionAuthUserSelfRead                    = "auth.user.self.read"
	PermissionAuthUserCompanyRead                 = "auth.user.company.read"
	PermissionAuthRoleSelfWrite                   = "auth.role.self.write"
	PermissionAuthRoleCompanyWrite                = "auth.role.company.write"
	PermissionAuthRoleSelfRead                    = "auth.role.self.read"
	PermissionAuthRoleCompanyRead                 = "auth.role.company.read"
	PermissionAuthUserInfoSelfWrite               = "auth.user-info.self.write"
	PermissionAuthUserInfoCompanyWrite            = "auth.user-info.company.write"
	PermissionAuthUserInfoSelfRead                = "auth.user-info.self.read"
	PermissionAuthUserInfoCompanyRead             = "auth.user-info.company.read"
)

Variables

View Source
var (
	ErrCredentialNotMatched    = errors.New("credential not matched")
	ErrIncompatibleHashVersion = errors.New("incompatible hash version")
)
View Source
var (
	ErrPermissionDenied = errors.New("permission denied")
)
View Source
var (
	ErrUserDoesNotHaveAnyPermission = errors.New("user does not have any permission")
)

Functions

This section is empty.

Types

type Credentials

type Credentials struct {
	Hash          string   `json:"-"`
	SshPublicKeys []string `json:"-"`
}

func NewPasswordCredentials

func NewPasswordCredentials(password string) (Credentials, error)

func (Credentials) ValidatePassword

func (c Credentials) ValidatePassword(password string) error

type Permission

type Permission = string

type Role

type Role struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Accesses    []string `json:"accesses"`
}

func (Role) IsAllowed

func (r Role) IsAllowed(perm Permission) error

IsAllowed if Role's permissions matched the given permission return nil, otherwise ErrPermissionDenied time-complex = O(n*m) n = Accesses length m = permission's depth e.g. "auth.user.self.write" depth = 4

type User

type User struct {
	Username    string       `json:"username"`
	Credentials *Credentials `json:"-"`
	Roles       []Role       `json:"roles"`
	IsActivated bool         `json:"is_activated"`
	CreatedAt   time.Time    `json:"created_at"`
}

func NewUser

func NewUser(username string, cred Credentials) User

func (User) IsAllowed

func (u User) IsAllowed(perm Permission) error

Jump to

Keyboard shortcuts

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