admin_token_model

package
v0.0.0-...-1dc8ef7 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdminPermission

type AdminPermission = string
const (
	AdminPermissionRoot  AdminPermission = "root"
	AdminPermissionSudo  AdminPermission = "sudo"
	AdminPermissionRead  AdminPermission = "read"
	AdminPermissionWrite AdminPermission = "write"
)

type Model

type Model interface {
	TokenModel
	db.AutoMigrater
}

func New

func New(db *gorm.DB) Model

type Token

type Token struct {
	CreatedAt time.Time
	UpdatedAt time.Time

	Id uuid.UUID `gorm:"primaryKey;not null;uniqueIndex"`

	TokenParam
}

func (*Token) BeforeCreate

func (t *Token) BeforeCreate(tx *gorm.DB) (err error)

func (*Token) IsValid

func (t *Token) IsValid() bool

type TokenModel

type TokenModel interface {
	ReadTokenInfoByRaw(tokenRaw string) (*Token, error)
	UpdateTokenInfoByRaw(tokenRaw string, param TokenParam) error
	DeleteTokenByRaw(tokenRaw string) error
	CreateToken(param TokenParam) (token Token, err error)
	ReadAllTokens() (token []Token, err error)
	ReadTokensByQuery(tokenRaws []string) (token []Token, err error)
	IsTokenExist(token string) bool
	GenerateSudoToken(sudoToken string) (token Token)
	GenerateRootToken(rootToken string) (token Token)
}

type TokenParam

type TokenParam struct {
	Type            TokenType      `gorm:"default:'admin'"`
	Raw             string         `gorm:"unique;index"`
	AdminPermission pq.StringArray `gorm:"type:varchar[]"`
	Comment         string
	ExpiredAt       time.Time
	IsValid         bool
}

type TokenType

type TokenType string
const (
	TokenTypeAdmin TokenType = "admin"
	TokenTypeSudo  TokenType = "sudo"
	TokenTypeRoot  TokenType = "root"
)

Jump to

Keyboard shortcuts

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