model

package
v1.2111.0-pre3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2021 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SQLWhitelistExactMatch = "exact_match"
	SQLWhitelistFPMatch    = "fp_match"
)
View Source
const (
	TaskStatusInit             = "initialized"
	TaskStatusAudited          = "audited"
	TaskStatusExecuting        = "executing"
	TaskStatusExecuteSucceeded = "exec_succeeded"
	TaskStatusExecuteFailed    = "exec_failed"
)
View Source
const (
	TaskSQLSourceFromFormData       = "form_data"
	TaskSQLSourceFromSQLFile        = "sql_file"
	TaskSQLSourceFromMyBatisXMLFile = "mybatis_xml_file"
	TaskSQLSourceFromAuditPlan      = "audit_plan"
)
View Source
const (
	SQLAuditStatusInitialized = "initialized"
	SQLAuditStatusDoing       = "doing"
	SQLAuditStatusFinished    = "finished"
)
View Source
const (
	SQLExecuteStatusInitialized = "initialized"
	SQLExecuteStatusDoing       = "doing"
	SQLExecuteStatusFailed      = "failed"
	SQLExecuteStatusSucceeded   = "succeeded"
)
View Source
const (
	WorkflowStepTypeSQLReview      = "sql_review"
	WorkflowStepTypeSQLExecute     = "sql_execute"
	WorkflowStepTypeCreateWorkflow = "create_workflow"
	WorkflowStepTypeUpdateWorkflow = "update_workflow"
)
View Source
const (
	WorkflowStatusRunning = "on_process"
	WorkflowStatusFinish  = "finished"
	WorkflowStatusReject  = "rejected"
	WorkflowStatusCancel  = "canceled"
)
View Source
const (
	WorkflowStepStateInit    = "initialized"
	WorkflowStepStateApprove = "approved"
	WorkflowStepStateReject  = "rejected"
)
View Source
const DefaultAdminUser = "admin"
View Source
const (
	SystemVariableWorkflowExpiredHours = "system_variable_workflow_expired_hours"
)
View Source
const TaskExecResultOK = "OK"

Variables

View Source
var DefaultWorkflowTemplate = "default"
View Source
var MockTime, _ = time.Parse("0000-00-00 00:00:00.0000000", "0000-00-00 00:00:00.0000000")

Functions

func GetDb

func GetDb() *gorm.DB

func GetRuleMapFromAllArray

func GetRuleMapFromAllArray(allRules ...[]Rule) map[string]Rule

func GetSqlxDb

func GetSqlxDb() *sqlx.DB

func GetWorkflowStepTypeDesc

func GetWorkflowStepTypeDesc(s string) string

func InitMockStorage

func InitMockStorage(db *sql.DB)

func InitStorage

func InitStorage(s *Storage)

func UpdateStorage

func UpdateStorage(newStorage *Storage)

Types

type AuditPlan

type AuditPlan struct {
	Model
	Name             string `json:"name" gorm:"not null;index"`
	CronExpression   string `json:"cron_expression" gorm:"not null"`
	DBType           string `json:"db_type" gorm:"not null"`
	Token            string `json:"token" gorm:"not null"`
	InstanceName     string `json:"instance_name"`
	CreateUserID     uint
	InstanceDatabase string `json:"instance_database"`

	CreateUser       *User              `gorm:"foreignkey:CreateUserId"`
	Instance         *Instance          `gorm:"foreignkey:InstanceName;association_foreignkey:Name"`
	AuditPlanSQLs    []*AuditPlanSQL    `gorm:"foreignkey:AuditPlanID"`
	AuditPlanReports []*AuditPlanReport `gorm:"foreignkey:AuditPlanID"`
}

type AuditPlanListDetail

type AuditPlanListDetail struct {
	Name             string `json:"name"`
	Cron             string `json:"cron_expression"`
	DBType           string `json:"db_type"`
	Token            string `json:"token"`
	InstanceName     string `json:"instance_name"`
	InstanceDatabase string `json:"instance_database"`
}

type AuditPlanReport

type AuditPlanReport struct {
	Model
	AuditPlanID uint `json:"audit_plan_id" gorm:"index"`

	AuditPlan           *AuditPlan            `gorm:"foreignkey:AuditPlanID"`
	AuditPlanReportSQLs []*AuditPlanReportSQL `gorm:"foreignkey:AuditPlanReportID"`
}

type AuditPlanReportListDetail

type AuditPlanReportListDetail struct {
	ID       string `json:"id"`
	CreateAt string `json:"created_at"`
}

type AuditPlanReportSQL

type AuditPlanReportSQL struct {
	Model
	AuditResult string `json:"audit_result" gorm:"type:text"`

	AuditPlanSQLID    uint `json:"audit_plan_sql_id" gorm:"index"`
	AuditPlanReportID uint `json:"audit_plan_report_id" gorm:"index"`

	AuditPlanSQL    *AuditPlanSQL    `gorm:"foreignkey:AuditPlanSQLID"`
	AuditPlanReport *AuditPlanReport `gorm:"foreignkey:AuditPlanReportID"`
}

type AuditPlanReportSQLListDetail

type AuditPlanReportSQLListDetail struct {
	AuditResult string `json:"audit_result"`

	Fingerprint          string `json:"fingerprint"`
	LastReceiveText      string `json:"last_sql"`
	LastReceiveTimestamp string `json:"last_receive_timestamp"`
}

type AuditPlanSQL

type AuditPlanSQL struct {
	Model
	AuditPlanID          uint   `json:"audit_plan_id" gorm:"UNIQUE_INDEX:idx_audit_plan_sqls_audit_plan_id_fingerprint;not null"`
	Fingerprint          string `json:"fingerprint" gorm:"UNIQUE_INDEX:idx_audit_plan_sqls_audit_plan_id_fingerprint;not null"`
	Counter              int    `json:"counter" gorm:"not null"`
	LastSQL              string `json:"last_sql" gorm:"not null"`
	LastReceiveTimestamp string `json:"last_receive_timestamp" gorm:"not null"`
}

type AuditPlanSQLListDetail

type AuditPlanSQLListDetail struct {
	Fingerprint          string `json:"fingerprint"`
	Counter              string `json:"counter"`
	LastReceiveText      string `json:"last_sql"`
	LastReceiveTimestamp string `json:"last_receive_timestamp"`
}

type BaseSQL

type BaseSQL struct {
	Model
	TaskId uint `json:"-" gorm:"index"`
	Number uint `json:"number"`

	// Content store single SQL or batch SQLs
	//
	// Content may store batch SQLs When BaseSQL embed to RollbackSQL.
	// Split Content to single SQL before execute RollbackSQL.
	Content         string `json:"sql" gorm:"type:text"`
	StartBinlogFile string `json:"start_binlog_file"`
	StartBinlogPos  int64  `json:"start_binlog_pos"`
	EndBinlogFile   string `json:"end_binlog_file"`
	EndBinlogPos    int64  `json:"end_binlog_pos"`
	RowAffects      int64  `json:"row_affects"`
	ExecStatus      string `json:"exec_status" gorm:"default:\"initialized\""`
	ExecResult      string `json:"exec_result"`
}

func (*BaseSQL) GetExecStatusDesc

func (s *BaseSQL) GetExecStatusDesc() string

type ExecuteSQL

type ExecuteSQL struct {
	BaseSQL
	AuditStatus string `json:"audit_status" gorm:"default:\"initialized\""`
	AuditResult string `json:"audit_result" gorm:"type:text"`
	// AuditFingerprint generate from SQL and SQL audit result use MD5 hash algorithm,
	// it used for deduplication in one audit task.
	AuditFingerprint string `json:"audit_fingerprint" gorm:"index;type:char(32)"`
	// AuditLevel has four level: error, warn, notice, normal.
	AuditLevel string `json:"audit_level"`
}

func (*ExecuteSQL) GetAuditResultDesc

func (s *ExecuteSQL) GetAuditResultDesc() string

func (*ExecuteSQL) GetAuditStatusDesc

func (s *ExecuteSQL) GetAuditStatusDesc() string

func (ExecuteSQL) TableName

func (s ExecuteSQL) TableName() string

type Instance

type Instance struct {
	Model
	// has created composite index: [id, name] by gorm#AddIndex
	Name               string `json:"name" gorm:"not null;index" example:""`
	DbType             string `json:"db_type" gorm:"column:db_type; not null" example:"mysql"`
	Host               string `json:"host" gorm:"column:db_host; not null" example:"10.10.10.10"`
	Port               string `json:"port" gorm:"column:db_port; not null" example:"3306"`
	User               string `json:"user" gorm:"column:db_user; not null" example:"root"`
	Password           string `json:"-" gorm:"-"`
	SecretPassword     string `json:"secret_password" gorm:"column:db_password; not null"`
	Desc               string `json:"desc" example:"this is a instance"`
	WorkflowTemplateId uint   `json:"workflow_template_id"`

	// relation table
	Roles            []*Role           `json:"-" gorm:"many2many:instance_role;"`
	RuleTemplates    []RuleTemplate    `json:"-" gorm:"many2many:instance_rule_template"`
	WorkflowTemplate *WorkflowTemplate `gorm:"foreignkey:WorkflowTemplateId"`
}

Instance is a table for database info

func (*Instance) AfterFind

func (i *Instance) AfterFind() error

AfterFind is a hook implement gorm model after query, ignore err if query from db

func (*Instance) BeforeSave

func (i *Instance) BeforeSave() error

BeforeSave is a hook implement gorm model before exec create

type InstanceDetail

type InstanceDetail struct {
	Name                 string         `json:"name"`
	Desc                 string         `json:"desc"`
	Host                 string         `json:"db_host"`
	Port                 string         `json:"db_port"`
	User                 string         `json:"db_user"`
	WorkflowTemplateName sql.NullString `json:"workflow_template_name"`
	RoleNames            RowList        `json:"role_names"`
	RuleTemplateNames    RowList        `json:"rule_template_names"`
}

type LDAPConfiguration added in v1.2111.0

type LDAPConfiguration struct {
	Model
	// whether the ldap is enabled
	Enable bool `json:"enable" gorm:"not null"`
	// ldap server's ip
	Host string `json:"host" gorm:"not null"`
	// ldap server's port
	Port string `json:"port" gorm:"not null"`
	// the DN of the ldap administrative user for verification
	ConnectDn string `json:"connect_dn" gorm:"not null"`
	// the password of the ldap administrative user for verification
	ConnectPassword string `json:"-" gorm:"-"`
	// the secret password of the ldap administrative user for verification
	ConnectSecretPassword string `json:"connect_secret_password" gorm:"not null"`
	// base dn used for ldap verification
	BaseDn string `json:"base_dn" gorm:"not null"`
	// the key corresponding to the user name in ldap
	UserNameRdnKey string `json:"ldap_user_name_rdn_key" gorm:"not null"`
	// the key corresponding to the user email in ldap
	UserEmailRdnKey string `json:"ldap_user_email_rdn_key" gorm:"not null"`
}

LDAPConfiguration store ldap server configuration.

func (*LDAPConfiguration) AfterFind added in v1.2111.0

func (i *LDAPConfiguration) AfterFind() error

AfterFind is a hook implement gorm model after query, ignore err if query from db

func (*LDAPConfiguration) BeforeSave added in v1.2111.0

func (i *LDAPConfiguration) BeforeSave() error

BeforeSave is a hook implement gorm model before exec create

func (*LDAPConfiguration) TableName added in v1.2111.0

func (i *LDAPConfiguration) TableName() string

type Model

type Model struct {
	ID        uint       `json:"id" gorm:"primary_key" example:"1"`
	CreatedAt time.Time  `json:"created_at" gorm:"default:current_timestamp" example:"2018-10-21T16:40:23+08:00"`
	UpdatedAt time.Time  `json:"updated_at" gorm:"default:current_timestamp on update current_timestamp" example:"2018-10-21T16:40:23+08:00"`
	DeletedAt *time.Time `json:"-" sql:"index"`
}

type Role

type Role struct {
	Model
	Name      string `gorm:"index"`
	Desc      string
	Users     []*User     `gorm:"many2many:user_role;"`
	Instances []*Instance `gorm:"many2many:instance_role;"`
}

type RoleDetail

type RoleDetail struct {
	Id            int
	Name          string `json:"name"`
	Desc          string
	UserNames     RowList `json:"user_names"`
	InstanceNames RowList `json:"instance_names"`
}

type RollbackSQL

type RollbackSQL struct {
	BaseSQL
	ExecuteSQLId uint `gorm:"index;column:execute_sql_id"`
}

func (RollbackSQL) TableName

func (s RollbackSQL) TableName() string

type RowList

type RowList []string

func (*RowList) Scan

func (r *RowList) Scan(src interface{}) error

type Rule

type Rule struct {
	Name   string `json:"name" gorm:"primary_key; not null"`
	DBType string `json:"db_type" gorm:"primary_key; not null; default:\"mysql\""`
	Desc   string `json:"desc"`
	Value  string `json:"value"`
	Level  string `json:"level" example:"error"` // notice, warn, error
	Typ    string `json:"type" gorm:"column:type; not null"`
}

func (Rule) TableName

func (r Rule) TableName() string

type RuleTemplate

type RuleTemplate struct {
	Model
	Name      string             `json:"name"`
	Desc      string             `json:"desc"`
	DBType    string             `json:"db_type"`
	Instances []Instance         `json:"instance_list" gorm:"many2many:instance_rule_template"`
	RuleList  []RuleTemplateRule `json:"rule_list" gorm:"foreignkey:rule_template_id;association_foreignkey:id"`
}

type RuleTemplateDetail

type RuleTemplateDetail struct {
	Name          string  `json:"name"`
	Desc          string  `json:"desc"`
	DBType        string  `json:"db_type"`
	RuleNames     RowList `json:"rule_names"`
	InstanceNames RowList `json:"instance_names"`
}

type RuleTemplateRule

type RuleTemplateRule struct {
	RuleTemplateId uint   `json:"rule_template_id" gorm:"primary_key;auto_increment:false;"`
	RuleName       string `json:"name" gorm:"primary_key;"`
	RuleLevel      string `json:"level" gorm:"column:level;"`
	RuleValue      string `json:"value" gorm:"column:value;" `
	RuleDBType     string `json:"rule_db_type" gorm:"column:db_type; not null; default:'mysql'"`

	Rule *Rule `json:"-" gorm:"foreignkey:Name,DBType;association_foreignkey:RuleName,RuleDBType"`
}

func NewRuleTemplateRule

func NewRuleTemplateRule(t *RuleTemplate, r *Rule) RuleTemplateRule

func (*RuleTemplateRule) TableName

func (rtr *RuleTemplateRule) TableName() string

type SMTPConfiguration

type SMTPConfiguration struct {
	Model
	Host           string `json:"smtp_host" gorm:"column:smtp_host; not null"`
	Port           string `json:"smtp_port" gorm:"column:smtp_port; not null"`
	Username       string `json:"smtp_username" gorm:"column:smtp_username; not null"`
	Password       string `json:"-"`
	SecretPassword string `json:"secret_smtp_password" gorm:"column:secret_smtp_password; not null"`
}

SMTPConfiguration store SMTP server configuration.

func (*SMTPConfiguration) AfterFind

func (i *SMTPConfiguration) AfterFind() error

AfterFind is a hook implement gorm model after query, ignore err if query from db.

func (*SMTPConfiguration) BeforeSave

func (i *SMTPConfiguration) BeforeSave() error

BeforeSave is a hook implement gorm model before exec create.

func (*SMTPConfiguration) TableName

func (i *SMTPConfiguration) TableName() string

type SqlWhitelist

type SqlWhitelist struct {
	Model
	// Value store SQL text.
	Value            string `json:"value" gorm:"not null;type:text"`
	CapitalizedValue string `json:"-" gorm:"-"`
	Desc             string `json:"desc"`
	// MessageDigest deprecated after 1.1.0, keep it for compatibility.
	MessageDigest string `json:"message_digest" gorm:"type:char(32) not null comment 'md5 data';" `
	MatchType     string `json:"match_type" gorm:"default:\"exact_match\""`
}

func (*SqlWhitelist) AfterFind

func (s *SqlWhitelist) AfterFind() error

AfterFind is a hook implement gorm model after query, ignore err if query from db

func (*SqlWhitelist) BeforeSave

func (s *SqlWhitelist) BeforeSave() error

BeforeSave is a hook implement gorm model before exec create

func (SqlWhitelist) TableName

func (s SqlWhitelist) TableName() string

type Storage

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

func GetStorage

func GetStorage() *Storage

func NewStorage

func NewStorage(user, password, host, port, schema string, debug bool) (*Storage, error)

func (*Storage) AutoMigrate

func (s *Storage) AutoMigrate() error

func (*Storage) CloneRuleTemplateRules

func (s *Storage) CloneRuleTemplateRules(source, destination *RuleTemplate) error

func (*Storage) Create

func (s *Storage) Create(model interface{}) error

func (*Storage) CreateAdminUser

func (s *Storage) CreateAdminUser() error

func (*Storage) CreateDefaultTemplate

func (s *Storage) CreateDefaultTemplate(rules map[string][]*driver.Rule) error

func (*Storage) CreateDefaultWorkflowTemplate

func (s *Storage) CreateDefaultWorkflowTemplate() error

func (*Storage) CreateRulesIfNotExist

func (s *Storage) CreateRulesIfNotExist(rules map[string][]*driver.Rule) error

func (*Storage) CreateWorkflow

func (s *Storage) CreateWorkflow(subject, desc string, user *User, task *Task,
	stepTemplates []*WorkflowStepTemplate) error

func (*Storage) Delete

func (s *Storage) Delete(model interface{}) error

func (*Storage) DeleteTask

func (s *Storage) DeleteTask(task *Task) error

func (*Storage) DeleteWorkflow

func (s *Storage) DeleteWorkflow(workflow *Workflow) error

func (*Storage) Exist

func (s *Storage) Exist(model interface{}) (bool, error)

func (*Storage) GetAllRoleTip

func (s *Storage) GetAllRoleTip() ([]*Role, error)

func (*Storage) GetAllRule

func (s *Storage) GetAllRule() ([]*Rule, error)

func (*Storage) GetAllRuleByDBType

func (s *Storage) GetAllRuleByDBType(dbType string) ([]*Rule, error)

func (*Storage) GetAllUserTip

func (s *Storage) GetAllUserTip() ([]*User, error)

func (*Storage) GetAndCheckInstanceExist

func (s *Storage) GetAndCheckInstanceExist(instanceNames []string) (instances []*Instance, err error)

func (*Storage) GetAndCheckRoleExist

func (s *Storage) GetAndCheckRoleExist(roleNames []string) (roles []*Role, err error)

func (*Storage) GetAndCheckRuleExist

func (s *Storage) GetAndCheckRuleExist(ruleNames []string, dbType string) (rules []Rule, err error)

func (*Storage) GetAndCheckRuleTemplateExist

func (s *Storage) GetAndCheckRuleTemplateExist(templateNames []string) (ruleTemplates []*RuleTemplate, err error)

func (*Storage) GetAndCheckUserExist

func (s *Storage) GetAndCheckUserExist(userNames []string) (users []*User, err error)

func (*Storage) GetAuditPlanByName

func (s *Storage) GetAuditPlanByName(name string) (*AuditPlan, bool, error)

func (*Storage) GetAuditPlanReportSQLsByReq

func (s *Storage) GetAuditPlanReportSQLsByReq(data map[string]interface{}) (
	list []*AuditPlanReportSQLListDetail, count uint64, err error)

func (*Storage) GetAuditPlanReportsByReq

func (s *Storage) GetAuditPlanReportsByReq(data map[string]interface{}) (
	list []*AuditPlanReportListDetail, count uint64, err error)

func (*Storage) GetAuditPlanSQLs

func (s *Storage) GetAuditPlanSQLs(name string) ([]*AuditPlanSQL, error)

func (*Storage) GetAuditPlanSQLsByReq

func (s *Storage) GetAuditPlanSQLsByReq(data map[string]interface{}) (
	list []*AuditPlanSQLListDetail, count uint64, err error)

func (*Storage) GetAuditPlans

func (s *Storage) GetAuditPlans() ([]*AuditPlan, error)

func (*Storage) GetAuditPlansByReq

func (s *Storage) GetAuditPlansByReq(data map[string]interface{}) (
	list []*AuditPlanListDetail, count uint64, err error)

func (*Storage) GetDefaultRuleTemplateName added in v1.2111.0

func (s *Storage) GetDefaultRuleTemplateName(dbType string) string

func (*Storage) GetExpiredTasks

func (s *Storage) GetExpiredTasks(start time.Time) ([]*Task, error)

func (*Storage) GetExpiredWorkflows

func (s *Storage) GetExpiredWorkflows(start time.Time) ([]*Workflow, error)

func (*Storage) GetInstanceById

func (s *Storage) GetInstanceById(id string) (*Instance, bool, error)

func (*Storage) GetInstanceByName

func (s *Storage) GetInstanceByName(name string) (*Instance, bool, error)

func (*Storage) GetInstanceDetailByName

func (s *Storage) GetInstanceDetailByName(name string) (*Instance, bool, error)

func (*Storage) GetInstanceNamesByWorkflowTemplateId

func (s *Storage) GetInstanceNamesByWorkflowTemplateId(id uint) ([]string, error)

func (*Storage) GetInstancesByNames

func (s *Storage) GetInstancesByNames(names []string) ([]*Instance, error)

func (*Storage) GetInstancesByReq

func (s *Storage) GetInstancesByReq(data map[string]interface{}) (
	result []*InstanceDetail, count uint64, err error)

func (*Storage) GetLDAPConfiguration added in v1.2111.0

func (s *Storage) GetLDAPConfiguration() (*LDAPConfiguration, bool, error)

func (*Storage) GetLastWorkflow

func (s *Storage) GetLastWorkflow() (*Workflow, bool, error)

func (*Storage) GetRelatedDDLTask

func (s *Storage) GetRelatedDDLTask(task *Task) ([]Task, error)

func (*Storage) GetRoleByName

func (s *Storage) GetRoleByName(name string) (*Role, bool, error)

func (*Storage) GetRolesByNames

func (s *Storage) GetRolesByNames(names []string) ([]*Role, error)

func (*Storage) GetRolesByReq

func (s *Storage) GetRolesByReq(data map[string]interface{}) (
	result []*RoleDetail, count uint64, err error)

func (*Storage) GetRule

func (s *Storage) GetRule(name, dbType string) (*Rule, bool, error)

func (*Storage) GetRuleTemplateByName

func (s *Storage) GetRuleTemplateByName(name string) (*RuleTemplate, bool, error)

func (*Storage) GetRuleTemplateDetailByName

func (s *Storage) GetRuleTemplateDetailByName(name string) (*RuleTemplate, bool, error)

func (*Storage) GetRuleTemplateTips

func (s *Storage) GetRuleTemplateTips(dbType string) ([]*RuleTemplate, error)

func (*Storage) GetRuleTemplatesByInstance

func (s *Storage) GetRuleTemplatesByInstance(inst *Instance) ([]RuleTemplate, error)

func (*Storage) GetRuleTemplatesByNames

func (s *Storage) GetRuleTemplatesByNames(names []string) ([]*RuleTemplate, error)

func (*Storage) GetRuleTemplatesByReq

func (s *Storage) GetRuleTemplatesByReq(data map[string]interface{}) (
	result []*RuleTemplateDetail, count uint64, err error)

func (*Storage) GetRulesByInstanceId

func (s *Storage) GetRulesByInstanceId(instanceId string) ([]*Rule, error)

func (*Storage) GetRulesByNames

func (s *Storage) GetRulesByNames(names []string, dbType string) ([]Rule, error)

func (*Storage) GetRulesFromRuleTemplateByName

func (s *Storage) GetRulesFromRuleTemplateByName(name string) ([]*Rule, error)

func (*Storage) GetSMTPConfiguration

func (s *Storage) GetSMTPConfiguration() (*SMTPConfiguration, bool, error)

func (*Storage) GetSqlWhitelist

func (s *Storage) GetSqlWhitelist(pageIndex, pageSize uint32) ([]SqlWhitelist, uint32, error)

func (*Storage) GetSqlWhitelistById

func (s *Storage) GetSqlWhitelistById(sqlWhiteId string) (*SqlWhitelist, bool, error)

func (*Storage) GetTaskById

func (s *Storage) GetTaskById(taskId string) (*Task, bool, error)

func (*Storage) GetTaskByInstanceId

func (s *Storage) GetTaskByInstanceId(instanceId uint) ([]Task, error)

func (*Storage) GetTaskDetailById

func (s *Storage) GetTaskDetailById(taskId string) (*Task, bool, error)

func (*Storage) GetTaskExecuteSQLContent

func (s *Storage) GetTaskExecuteSQLContent(taskId string) ([]byte, error)

func (*Storage) GetTaskSQLsByReq

func (s *Storage) GetTaskSQLsByReq(data map[string]interface{}) (
	result []*TaskSQLDetail, count uint64, err error)

func (*Storage) GetUserByName

func (s *Storage) GetUserByName(name string) (*User, bool, error)

func (*Storage) GetUserDetailByName

func (s *Storage) GetUserDetailByName(name string) (*User, bool, error)

func (*Storage) GetUserInstanceTip

func (s *Storage) GetUserInstanceTip(user *User, dbType string) ([]*Instance, error)

func (*Storage) GetUsersByNames

func (s *Storage) GetUsersByNames(names []string) ([]*User, error)

func (*Storage) GetUsersByReq

func (s *Storage) GetUsersByReq(data map[string]interface{}) (
	result []*UserDetail, count uint64, err error)

func (*Storage) GetWorkflowBySubject

func (s *Storage) GetWorkflowBySubject(subject string) (*Workflow, bool, error)

func (*Storage) GetWorkflowByTaskId

func (s *Storage) GetWorkflowByTaskId(id uint) (*Workflow, bool, error)

func (*Storage) GetWorkflowCountByReq

func (s *Storage) GetWorkflowCountByReq(data map[string]interface{}) (uint64, error)

func (*Storage) GetWorkflowDetailById

func (s *Storage) GetWorkflowDetailById(id string) (*Workflow, bool, error)

func (*Storage) GetWorkflowExpiredHoursOrDefault

func (s *Storage) GetWorkflowExpiredHoursOrDefault() (time.Duration, error)

func (*Storage) GetWorkflowHistoryById

func (s *Storage) GetWorkflowHistoryById(id string) ([]*WorkflowRecord, error)

func (*Storage) GetWorkflowRecordByTaskId

func (s *Storage) GetWorkflowRecordByTaskId(id string) (*WorkflowRecord, bool, error)

TODO: args `id` using uint

func (*Storage) GetWorkflowStepsByTemplateId

func (s *Storage) GetWorkflowStepsByTemplateId(id uint) ([]*WorkflowStepTemplate, error)

func (*Storage) GetWorkflowStepsDetailByTemplateId

func (s *Storage) GetWorkflowStepsDetailByTemplateId(id uint) ([]*WorkflowStepTemplate, error)

func (*Storage) GetWorkflowTemplateById

func (s *Storage) GetWorkflowTemplateById(id uint) (*WorkflowTemplate, bool, error)

func (*Storage) GetWorkflowTemplateByName

func (s *Storage) GetWorkflowTemplateByName(name string) (*WorkflowTemplate, bool, error)

func (*Storage) GetWorkflowTemplateTip

func (s *Storage) GetWorkflowTemplateTip() ([]*WorkflowTemplate, error)

func (*Storage) GetWorkflowTemplatesByReq

func (s *Storage) GetWorkflowTemplatesByReq(data map[string]interface{}) (
	result []*WorkflowTemplateDetail, count uint64, err error)

func (*Storage) GetWorkflowsByReq

func (s *Storage) GetWorkflowsByReq(data map[string]interface{}) (
	result []*WorkflowListDetail, count uint64, err error)

func (*Storage) HardDelete

func (s *Storage) HardDelete(model interface{}) error

func (*Storage) OverrideAuditPlanSQLs

func (s *Storage) OverrideAuditPlanSQLs(apName string, sqls []*AuditPlanSQL) error

func (*Storage) Save

func (s *Storage) Save(model interface{}) error

func (*Storage) SaveWorkflowTemplate

func (s *Storage) SaveWorkflowTemplate(template *WorkflowTemplate) error

func (*Storage) TaskWorkflowIsRunning

func (s *Storage) TaskWorkflowIsRunning(taskIds []uint) (bool, error)

func (*Storage) TxExec

func (s *Storage) TxExec(fn func(tx *sql.Tx) error) error

func (*Storage) Update

func (s *Storage) Update(model interface{}, attrs ...interface{}) error

func (*Storage) UpdateAuditPlanByName

func (s *Storage) UpdateAuditPlanByName(name string, attrs map[string]interface{}) error

func (*Storage) UpdateAuditPlanSQLs

func (s *Storage) UpdateAuditPlanSQLs(apName string, sqls []*AuditPlanSQL) error

func (*Storage) UpdateExecuteSQLById

func (s *Storage) UpdateExecuteSQLById(executeSQLId string, attrs ...interface{}) error

func (*Storage) UpdateExecuteSQLStatusByTaskId

func (s *Storage) UpdateExecuteSQLStatusByTaskId(task *Task, status string) error

func (*Storage) UpdateExecuteSQLs

func (s *Storage) UpdateExecuteSQLs(ExecuteSQLs []*ExecuteSQL) error

func (*Storage) UpdateExecuteSqlStatus

func (s *Storage) UpdateExecuteSqlStatus(baseSQL *BaseSQL, status, result string) error

func (*Storage) UpdateInstanceById

func (s *Storage) UpdateInstanceById(InstanceId uint, attrs ...interface{}) error

func (*Storage) UpdateInstanceRoles

func (s *Storage) UpdateInstanceRoles(instance *Instance, rs ...*Role) error

func (*Storage) UpdateInstanceRuleTemplates

func (s *Storage) UpdateInstanceRuleTemplates(instance *Instance, ts ...*RuleTemplate) error

func (*Storage) UpdatePassword

func (s *Storage) UpdatePassword(user *User, newPassword string) error

func (*Storage) UpdateRoleInstances

func (s *Storage) UpdateRoleInstances(role *Role, instances ...*Instance) error

func (*Storage) UpdateRoleUsers

func (s *Storage) UpdateRoleUsers(role *Role, users ...*User) error

func (*Storage) UpdateRollbackSQLById

func (s *Storage) UpdateRollbackSQLById(rollbackSQLId string, attrs ...interface{}) error

func (*Storage) UpdateRollbackSQLs

func (s *Storage) UpdateRollbackSQLs(rollbackSQLs []*RollbackSQL) error

func (*Storage) UpdateRollbackSqlStatus

func (s *Storage) UpdateRollbackSqlStatus(baseSQL *BaseSQL, status, result string) error

func (*Storage) UpdateRuleTemplateInstances

func (s *Storage) UpdateRuleTemplateInstances(tpl *RuleTemplate, instances ...*Instance) error

func (*Storage) UpdateRuleTemplateRules

func (s *Storage) UpdateRuleTemplateRules(tpl *RuleTemplate, rules ...RuleTemplateRule) error

func (*Storage) UpdateTask

func (s *Storage) UpdateTask(task *Task, attrs ...interface{}) error

func (*Storage) UpdateTaskStatusById

func (s *Storage) UpdateTaskStatusById(taskId uint, status string) error

func (*Storage) UpdateUserRoles

func (s *Storage) UpdateUserRoles(user *User, rs ...*Role) error

func (*Storage) UpdateWorkflowRecord

func (s *Storage) UpdateWorkflowRecord(w *Workflow, task *Task) error

func (*Storage) UpdateWorkflowStatus

func (s *Storage) UpdateWorkflowStatus(w *Workflow, operateStep *WorkflowStep) error

func (*Storage) UpdateWorkflowTemplateInstances

func (s *Storage) UpdateWorkflowTemplateInstances(workflowTemplate *WorkflowTemplate,
	instances ...*Instance) error

func (*Storage) UpdateWorkflowTemplateSteps

func (s *Storage) UpdateWorkflowTemplateSteps(templateId uint, steps []*WorkflowStepTemplate) error

func (*Storage) UserCanAccessInstance

func (s *Storage) UserCanAccessInstance(user *User, instance *Instance) (bool, error)

func (*Storage) UserCanAccessWorkflow

func (s *Storage) UserCanAccessWorkflow(user *User, workflow *Workflow) (bool, error)

func (*Storage) UserHasBindWorkflowTemplate

func (s *Storage) UserHasBindWorkflowTemplate(user *User) (bool, error)

func (*Storage) UserHasRunningWorkflow

func (s *Storage) UserHasRunningWorkflow(userId uint) (bool, error)

type SystemVariable

type SystemVariable struct {
	Key   string `gorm:"primary_key"`
	Value string `gorm:"not null"`
}

SystemVariable store misc K-V.

type Task

type Task struct {
	Model
	InstanceId   uint    `json:"instance_id"`
	Schema       string  `json:"instance_schema" gorm:"column:instance_schema" example:"db1"`
	PassRate     float64 `json:"pass_rate"`
	SQLSource    string  `json:"sql_source" gorm:"column:sql_source"`
	DBType       string  `json:"db_type" gorm:"default:'mysql'" example:"mysql"`
	Status       string  `json:"status" gorm:"default:\"initialized\""`
	CreateUserId uint

	CreateUser   *User          `gorm:"foreignkey:CreateUserId"`
	Instance     *Instance      `json:"-" gorm:"foreignkey:InstanceId"`
	ExecuteSQLs  []*ExecuteSQL  `json:"-" gorm:"foreignkey:TaskId"`
	RollbackSQLs []*RollbackSQL `json:"-" gorm:"foreignkey:TaskId"`
}

func (*Task) HasDoingAudit

func (t *Task) HasDoingAudit() bool

func (*Task) HasDoingExecute

func (t *Task) HasDoingExecute() bool

func (*Task) HasDoingRollback

func (t *Task) HasDoingRollback() bool

func (*Task) InstanceName

func (t *Task) InstanceName() string

func (*Task) IsExecuteFailed

func (t *Task) IsExecuteFailed() bool

type TaskSQLDetail

type TaskSQLDetail struct {
	Number      uint           `json:"number"`
	ExecSQL     string         `json:"exec_sql"`
	AuditResult string         `json:"audit_result"`
	AuditLevel  string         `json:"audit_level"`
	AuditStatus string         `json:"audit_status"`
	ExecResult  string         `json:"exec_result"`
	ExecStatus  string         `json:"exec_status"`
	RollbackSQL sql.NullString `json:"rollback_sql"`
}

type User

type User struct {
	Model
	// has created composite index: [id, login_name] by gorm#AddIndex
	Name                   string `gorm:"index;column:login_name"`
	Email                  string
	Password               string                 `json:"-" gorm:"-"`
	SecretPassword         string                 `json:"secret_password" gorm:"not null;column:password"`
	UserAuthenticationType UserAuthenticationType `json:"user_authentication_type" gorm:"not null"`
	Roles                  []*Role                `gorm:"many2many:user_role;"`

	WorkflowStepTemplates []*WorkflowStepTemplate `gorm:"many2many:workflow_step_template_user"`
}

func (*User) AfterFind

func (i *User) AfterFind() error

AfterFind is a hook implement gorm model after query, ignore err if query from db

func (*User) BeforeSave

func (i *User) BeforeSave() error

BeforeSave is a hook implement gorm model before exec create

type UserAuthenticationType added in v1.2111.0

type UserAuthenticationType string
const (
	UserAuthenticationTypeLDAP UserAuthenticationType = "ldap" // user verify through ldap
	UserAuthenticationTypeSQLE UserAuthenticationType = "sqle" //user verify through sqle
)

type UserDetail

type UserDetail struct {
	Id        int
	Name      string `json:"login_name"`
	Email     string
	RoleNames RowList `json:"role_names"`
}

type Workflow

type Workflow struct {
	Model
	Subject          string
	Desc             string
	CreateUserId     uint
	WorkflowRecordId uint

	CreateUser    *User             `gorm:"foreignkey:CreateUserId"`
	Record        *WorkflowRecord   `gorm:"foreignkey:WorkflowRecordId"`
	RecordHistory []*WorkflowRecord `gorm:"many2many:workflow_record_history;"`
}

func (*Workflow) CreateUserName

func (w *Workflow) CreateUserName() string

func (*Workflow) CurrentAssigneeUser

func (w *Workflow) CurrentAssigneeUser() []*User

func (*Workflow) CurrentStep

func (w *Workflow) CurrentStep() *WorkflowStep

func (*Workflow) FinalStep

func (w *Workflow) FinalStep() *WorkflowStep

func (*Workflow) IsFirstRecord

func (w *Workflow) IsFirstRecord(record *WorkflowRecord) bool

IsFirstRecord check the record is the first record in workflow; you must load record history first and then use it.

func (*Workflow) IsOperationUser

func (w *Workflow) IsOperationUser(user *User) bool

func (*Workflow) NextStep

func (w *Workflow) NextStep() *WorkflowStep

type WorkflowListDetail

type WorkflowListDetail struct {
	Id                      uint           `json:"workflow_id"`
	Subject                 string         `json:"subject"`
	Desc                    string         `json:"desc"`
	TaskPassRate            float64        `json:"task_pass_rate"`
	TaskInstance            sql.NullString `json:"task_instance_name"`
	TaskInstanceDeletedAt   *time.Time     `json:"task_instance_deleted_at"`
	TaskInstanceSchema      string         `json:"task_instance_schema"`
	TaskStatus              string         `json:"task_status"`
	CreateUser              sql.NullString `json:"create_user_name"`
	CreateUserDeletedAt     *time.Time     `json:"create_user_deleted_at"`
	CreateTime              *time.Time     `json:"create_time"`
	CurrentStepType         sql.NullString `json:"current_step_type" enums:"sql_review,sql_execute"`
	CurrentStepAssigneeUser RowList        `json:"current_step_assignee_user_name_list"`
	Status                  string         `json:"status"`
}

type WorkflowRecord

type WorkflowRecord struct {
	Model
	TaskId                uint `gorm:"index"`
	CurrentWorkflowStepId uint
	Status                string `gorm:"default:\"on_process\""`

	CurrentStep *WorkflowStep   `gorm:"foreignkey:CurrentWorkflowStepId"`
	Steps       []*WorkflowStep `gorm:"foreignkey:WorkflowRecordId"`
}

type WorkflowStep

type WorkflowStep struct {
	Model
	OperationUserId        uint
	OperateAt              *time.Time
	WorkflowId             uint   `gorm:"index; not null"`
	WorkflowRecordId       uint   `gorm:"index; not null"`
	WorkflowStepTemplateId uint   `gorm:"index; not null"`
	State                  string `gorm:"default:\"initialized\""`
	Reason                 string

	Template      *WorkflowStepTemplate `gorm:"foreignkey:WorkflowStepTemplateId"`
	OperationUser *User                 `gorm:"foreignkey:OperationUserId"`
}

type WorkflowStepTemplate

type WorkflowStepTemplate struct {
	Model
	Number             uint   `gorm:"index; column:step_number"`
	WorkflowTemplateId int    `gorm:"index"`
	Typ                string `gorm:"column:type; not null"`
	Desc               string

	Users []*User `gorm:"many2many:workflow_step_template_user"`
}

type WorkflowTemplate

type WorkflowTemplate struct {
	Model
	Name string
	Desc string

	Steps     []*WorkflowStepTemplate `json:"-" gorm:"foreignkey:workflowTemplateId"`
	Instances []*Instance             `gorm:"foreignkey:WorkflowTemplateId"`
}

type WorkflowTemplateDetail

type WorkflowTemplateDetail struct {
	Name string `json:"workflow_template_name"`
	Desc string `json:"desc"`
}

Jump to

Keyboard shortcuts

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