redis

package
v0.0.0-...-73f8a9c Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CheckTypeExist      = "exist"
	CheckTypeNum        = "limit_num"
	CheckTypeOnlyString = "only_string"
)
View Source
const CheckPass = "pass"

Variables

View Source
var DB *gorm.DB

Functions

func AddWhiteList

func AddWhiteList(ctx context.Context, db *gorm.DB, WhiteList *WhiteList) (int64, error)

func DelWhiteList

func DelWhiteList(ctx context.Context, db *gorm.DB, id int64) error

func ExecQuery

func ExecQuery(ctx context.Context, req *Params) interface{}

ExecQuery ...

func ExecReadTask

func ExecReadTask(ctx context.Context, params *Params) (interface{}, error)

func GetDB

func GetDB() *gorm.DB

func NewRedisCli

func NewRedisCli(clusterName string, database int) (r *redis.Client, err error)

func SetRedisTaskDao

func SetRedisTaskDao(impl RedisTaskDao)

func SetWhiteListDao

func SetWhiteListDao(impl WhiteListDao)

Types

type Check

type Check struct {
}

func (Check) CheckReadCmd

func (Check) CheckReadCmd(ctx context.Context, cmd, cluster string, db int) (bool, string, error)

func (Check) CheckWriteCmd

func (Check) CheckWriteCmd(ctx context.Context, cmd, cluster string, db int) (bool, string, error)

type Params

type Params struct {
	Cmd, Cluster string
	DB           int
}

type PermitCmd

type PermitCmd struct {
	Cmd       string `json:"cmd"`        // key; 去匹配用户输入命令的第一个字段
	CheckType string `json:"check_type"` // val-1; 0 just match, 1 check nums , 2 only string
	LenLimit  int64  `json:"len_limit"`  // val-2;
}

config eg: key: cmd, val : CheckType,LenLimit

func GetReadWhitelist

func GetReadWhitelist(ctx context.Context) ([]PermitCmd, error)

func GetWriteWhitelist

func GetWriteWhitelist(ctx context.Context) ([]PermitCmd, error)

type RedisTask

type RedisTask struct {
	ID        int64  `json:"id" gorm:"column:id"`
	TaskID    int64  `json:"task_id" gorm:"column:task_id"`
	Cmd       string `json:"cmd" gorm:"column:cmd"`
	ExecInfo  string `json:"exec_info" gorm:"column:exec_info"`
	CheckInfo string `json:"check_info" gorm:"column:check_info"`
}

func (*RedisTask) AddTask

func (r *RedisTask) AddTask(ctx context.Context, cluster string, db int, parentTaskID int64) (int64, bool, error)

func (*RedisTask) ExecTask

func (r *RedisTask) ExecTask(ctx context.Context, startSubTaskId, taskId int64, cluster, db string) error

func (*RedisTask) GetTask

func (r *RedisTask) GetTask(id int64) (interface{}, error)

func (*RedisTask) ListPageTask

func (r *RedisTask) ListPageTask(pageInfo request.SortPageInfo, isDBA bool, status []string) (interface{}, int64, error)

func (*RedisTask) ListTask

func (r *RedisTask) ListTask(parentTaskID int64) (interface{}, error)

func (*RedisTask) UpdateTask

func (r *RedisTask) UpdateTask(action string) error

type RedisTaskDao

type RedisTaskDao interface {
	AddTask(db *gorm.DB, task *RedisTask) (int64, error)
	UpdateTask(db *gorm.DB, task *RedisTask) error
	ListRedisTaskByTaskID(db *gorm.DB, id int64) ([]RedisTask, error)
	ListTask(db *gorm.DB, pageInfo request.SortPageInfo, isDBA bool, status []string) ([]RedisTask, int64, error)
	GetTask(db *gorm.DB, id int64) (*RedisTask, error)
}

type WhiteList

type WhiteList struct {
	ID         int64  `json:"id" gorm:"column:id"`
	Cmd        string `json:"cmd" gorm:"column:cmd"`
	CheckType  string `json:"check_type" gorm:"column:check_type"` //exist;limit_num,xx;only_string
	CmdType    string `json:"cmd_type"  gorm:"column:cmd_type"`
	Creator    string `json:"creator" gorm:"column:creator"`
	CreateTime int64  `json:"create_time" gorm:"column:create_time"`
}

func ListReadWhiteList

func ListReadWhiteList(ctx context.Context, db *gorm.DB) ([]WhiteList, error)

func ListWriteWhiteList

func ListWriteWhiteList(ctx context.Context, db *gorm.DB) ([]WhiteList, error)

type WhiteListDao

type WhiteListDao interface {
	AddWhiteList(ctx context.Context, db *gorm.DB, WhiteList *WhiteList) (int64, error)
	DelWhiteList(ctx context.Context, db *gorm.DB, id int64) error
	ListWhiteList(ctx context.Context, db *gorm.DB, cmdType string) ([]WhiteList, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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