model

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultUser = "root"

Variables

Functions

This section is empty.

Types

type AccessType

type AccessType string
const (
	AccessTypeRead  AccessType = "read"
	AccessTypeWrite AccessType = "write"
	AccessTypeAll   AccessType = "all"
	AccessTypeAny   AccessType = matchAllSymbol
)

type Scope

type Scope struct {
	AccessType AccessType `json:"access_type"`
	Service    string     `json:"service"`
	Action     string     `json:"action"`
}

func ScopeFrom

func ScopeFrom(scopeName string) (Scope, error)

func (Scope) String

func (s Scope) String() string

type ScopeChecker

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

func NewScopeChecker

func NewScopeChecker(ctx context.Context, s string) (*ScopeChecker, error)

func (*ScopeChecker) IsAllowed

func (s *ScopeChecker) IsAllowed(role UserRole, scopes Scopes, requestPasswordChange bool) bool

type Scopes

type Scopes []Scope

func NormalizeScopes

func NormalizeScopes(ctx context.Context, scopes Scopes) (filtered Scopes, err error)

type User

type User struct {
	CreatedAt      time.Time          `bson:"created_at" json:"created_at"`
	Role           UserRole           `bson:"role" json:"role"`
	Name           string             `bson:"name" json:"name"`
	Scopes         Scopes             `bson:"scopes" json:"scopes"`
	PasswordHash   []byte             `bson:"password_hash" json:"password_hash"`
	ID             primitive.ObjectID `bson:"_id" json:"id"`
	OrgID          primitive.ObjectID `bson:"org_id" json:"org_id"`
	ChangePassword bool               `bson:"change_password" json:"change_password"`
}

func NewUser

func NewUser(orgID primitive.ObjectID, name string, needChangePassword bool) *User

func (*User) IsPasswordValid

func (u *User) IsPasswordValid(s string) bool

func (*User) SetPassword

func (u *User) SetPassword(s string) (err error)

type UserRole

type UserRole string
const (
	UserRoleSuperRoot UserRole = "super_root"
	UserRoleRoot      UserRole = "root"
	UserRoleManager   UserRole = "manager"
	UserRoleEmpty     UserRole = ""
)

func (UserRole) IsAnyRoot

func (r UserRole) IsAnyRoot() bool

func (UserRole) IsEmptyRole

func (r UserRole) IsEmptyRole() bool

func (UserRole) IsManager

func (r UserRole) IsManager() bool

func (UserRole) IsRoot

func (r UserRole) IsRoot() bool

func (UserRole) IsSuperRoot

func (r UserRole) IsSuperRoot() bool

func (UserRole) String

func (r UserRole) String() string

Jump to

Keyboard shortcuts

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