Documentation ¶
Index ¶
- Constants
- Variables
- func GetDb() *gorm.DB
- func GetRuleMapFromAllArray(allRules ...[]Rule) map[string]Rule
- func GetSqlxDb() *sqlx.DB
- func GetWorkflowStepTypeDesc(s string) string
- func InitMockStorage(db *sql.DB)
- func InitStorage(s *Storage)
- func UpdateStorage(newStorage *Storage)
- type AuditPlan
- type AuditPlanListDetail
- type AuditPlanReport
- type AuditPlanReportListDetail
- type AuditPlanReportSQL
- type AuditPlanReportSQLListDetail
- type AuditPlanSQL
- type AuditPlanSQLListDetail
- type BaseSQL
- type ExecuteSQL
- type Instance
- type InstanceDetail
- type LDAPConfiguration
- type Model
- type Role
- type RoleDetail
- type RollbackSQL
- type RowList
- type Rule
- type RuleTemplate
- type RuleTemplateDetail
- type RuleTemplateRule
- type SMTPConfiguration
- type SqlWhitelist
- type Storage
- func (s *Storage) AutoMigrate() error
- func (s *Storage) CloneRuleTemplateRules(source, destination *RuleTemplate) error
- func (s *Storage) Create(model interface{}) error
- func (s *Storage) CreateAdminUser() error
- func (s *Storage) CreateDefaultTemplate(rules map[string][]*driver.Rule) error
- func (s *Storage) CreateDefaultWorkflowTemplate() error
- func (s *Storage) CreateRulesIfNotExist(rules map[string][]*driver.Rule) error
- func (s *Storage) CreateWorkflow(subject, desc string, user *User, task *Task, ...) error
- func (s *Storage) Delete(model interface{}) error
- func (s *Storage) DeleteTask(task *Task) error
- func (s *Storage) DeleteWorkflow(workflow *Workflow) error
- func (s *Storage) Exist(model interface{}) (bool, error)
- func (s *Storage) GetAllRoleTip() ([]*Role, error)
- func (s *Storage) GetAllRule() ([]*Rule, error)
- func (s *Storage) GetAllRuleByDBType(dbType string) ([]*Rule, error)
- func (s *Storage) GetAllUserTip() ([]*User, error)
- func (s *Storage) GetAndCheckInstanceExist(instanceNames []string) (instances []*Instance, err error)
- func (s *Storage) GetAndCheckRoleExist(roleNames []string) (roles []*Role, err error)
- func (s *Storage) GetAndCheckRuleExist(ruleNames []string, dbType string) (rules []Rule, err error)
- func (s *Storage) GetAndCheckRuleTemplateExist(templateNames []string) (ruleTemplates []*RuleTemplate, err error)
- func (s *Storage) GetAndCheckUserExist(userNames []string) (users []*User, err error)
- func (s *Storage) GetAuditPlanByName(name string) (*AuditPlan, bool, error)
- func (s *Storage) GetAuditPlanReportSQLsByReq(data map[string]interface{}) (list []*AuditPlanReportSQLListDetail, count uint64, err error)
- func (s *Storage) GetAuditPlanReportsByReq(data map[string]interface{}) (list []*AuditPlanReportListDetail, count uint64, err error)
- func (s *Storage) GetAuditPlanSQLs(name string) ([]*AuditPlanSQL, error)
- func (s *Storage) GetAuditPlanSQLsByReq(data map[string]interface{}) (list []*AuditPlanSQLListDetail, count uint64, err error)
- func (s *Storage) GetAuditPlans() ([]*AuditPlan, error)
- func (s *Storage) GetAuditPlansByReq(data map[string]interface{}) (list []*AuditPlanListDetail, count uint64, err error)
- func (s *Storage) GetDefaultRuleTemplateName(dbType string) string
- func (s *Storage) GetExpiredTasks(start time.Time) ([]*Task, error)
- func (s *Storage) GetExpiredWorkflows(start time.Time) ([]*Workflow, error)
- func (s *Storage) GetInstanceById(id string) (*Instance, bool, error)
- func (s *Storage) GetInstanceByName(name string) (*Instance, bool, error)
- func (s *Storage) GetInstanceDetailByName(name string) (*Instance, bool, error)
- func (s *Storage) GetInstanceNamesByWorkflowTemplateId(id uint) ([]string, error)
- func (s *Storage) GetInstancesByNames(names []string) ([]*Instance, error)
- func (s *Storage) GetInstancesByReq(data map[string]interface{}) (result []*InstanceDetail, count uint64, err error)
- func (s *Storage) GetLDAPConfiguration() (*LDAPConfiguration, bool, error)
- func (s *Storage) GetLastWorkflow() (*Workflow, bool, error)
- func (s *Storage) GetRelatedDDLTask(task *Task) ([]Task, error)
- func (s *Storage) GetRoleByName(name string) (*Role, bool, error)
- func (s *Storage) GetRolesByNames(names []string) ([]*Role, error)
- func (s *Storage) GetRolesByReq(data map[string]interface{}) (result []*RoleDetail, count uint64, err error)
- func (s *Storage) GetRule(name, dbType string) (*Rule, bool, error)
- func (s *Storage) GetRuleTemplateByName(name string) (*RuleTemplate, bool, error)
- func (s *Storage) GetRuleTemplateDetailByName(name string) (*RuleTemplate, bool, error)
- func (s *Storage) GetRuleTemplateTips(dbType string) ([]*RuleTemplate, error)
- func (s *Storage) GetRuleTemplatesByInstance(inst *Instance) ([]RuleTemplate, error)
- func (s *Storage) GetRuleTemplatesByNames(names []string) ([]*RuleTemplate, error)
- func (s *Storage) GetRuleTemplatesByReq(data map[string]interface{}) (result []*RuleTemplateDetail, count uint64, err error)
- func (s *Storage) GetRulesByInstanceId(instanceId string) ([]*Rule, error)
- func (s *Storage) GetRulesByNames(names []string, dbType string) ([]Rule, error)
- func (s *Storage) GetRulesFromRuleTemplateByName(name string) ([]*Rule, error)
- func (s *Storage) GetSMTPConfiguration() (*SMTPConfiguration, bool, error)
- func (s *Storage) GetSqlWhitelist(pageIndex, pageSize uint32) ([]SqlWhitelist, uint32, error)
- func (s *Storage) GetSqlWhitelistById(sqlWhiteId string) (*SqlWhitelist, bool, error)
- func (s *Storage) GetTaskById(taskId string) (*Task, bool, error)
- func (s *Storage) GetTaskByInstanceId(instanceId uint) ([]Task, error)
- func (s *Storage) GetTaskDetailById(taskId string) (*Task, bool, error)
- func (s *Storage) GetTaskExecuteSQLContent(taskId string) ([]byte, error)
- func (s *Storage) GetTaskSQLsByReq(data map[string]interface{}) (result []*TaskSQLDetail, count uint64, err error)
- func (s *Storage) GetUserByName(name string) (*User, bool, error)
- func (s *Storage) GetUserDetailByName(name string) (*User, bool, error)
- func (s *Storage) GetUserInstanceTip(user *User, dbType string) ([]*Instance, error)
- func (s *Storage) GetUsersByNames(names []string) ([]*User, error)
- func (s *Storage) GetUsersByReq(data map[string]interface{}) (result []*UserDetail, count uint64, err error)
- func (s *Storage) GetWorkflowBySubject(subject string) (*Workflow, bool, error)
- func (s *Storage) GetWorkflowByTaskId(id uint) (*Workflow, bool, error)
- func (s *Storage) GetWorkflowCountByReq(data map[string]interface{}) (uint64, error)
- func (s *Storage) GetWorkflowDetailById(id string) (*Workflow, bool, error)
- func (s *Storage) GetWorkflowExpiredHoursOrDefault() (time.Duration, error)
- func (s *Storage) GetWorkflowHistoryById(id string) ([]*WorkflowRecord, error)
- func (s *Storage) GetWorkflowRecordByTaskId(id string) (*WorkflowRecord, bool, error)
- func (s *Storage) GetWorkflowStepsByTemplateId(id uint) ([]*WorkflowStepTemplate, error)
- func (s *Storage) GetWorkflowStepsDetailByTemplateId(id uint) ([]*WorkflowStepTemplate, error)
- func (s *Storage) GetWorkflowTemplateById(id uint) (*WorkflowTemplate, bool, error)
- func (s *Storage) GetWorkflowTemplateByName(name string) (*WorkflowTemplate, bool, error)
- func (s *Storage) GetWorkflowTemplateTip() ([]*WorkflowTemplate, error)
- func (s *Storage) GetWorkflowTemplatesByReq(data map[string]interface{}) (result []*WorkflowTemplateDetail, count uint64, err error)
- func (s *Storage) GetWorkflowsByReq(data map[string]interface{}) (result []*WorkflowListDetail, count uint64, err error)
- func (s *Storage) HardDelete(model interface{}) error
- func (s *Storage) OverrideAuditPlanSQLs(apName string, sqls []*AuditPlanSQL) error
- func (s *Storage) Save(model interface{}) error
- func (s *Storage) SaveWorkflowTemplate(template *WorkflowTemplate) error
- func (s *Storage) TaskWorkflowIsRunning(taskIds []uint) (bool, error)
- func (s *Storage) TxExec(fn func(tx *sql.Tx) error) error
- func (s *Storage) Update(model interface{}, attrs ...interface{}) error
- func (s *Storage) UpdateAuditPlanByName(name string, attrs map[string]interface{}) error
- func (s *Storage) UpdateAuditPlanSQLs(apName string, sqls []*AuditPlanSQL) error
- func (s *Storage) UpdateExecuteSQLById(executeSQLId string, attrs ...interface{}) error
- func (s *Storage) UpdateExecuteSQLStatusByTaskId(task *Task, status string) error
- func (s *Storage) UpdateExecuteSQLs(ExecuteSQLs []*ExecuteSQL) error
- func (s *Storage) UpdateExecuteSqlStatus(baseSQL *BaseSQL, status, result string) error
- func (s *Storage) UpdateInstanceById(InstanceId uint, attrs ...interface{}) error
- func (s *Storage) UpdateInstanceRoles(instance *Instance, rs ...*Role) error
- func (s *Storage) UpdateInstanceRuleTemplates(instance *Instance, ts ...*RuleTemplate) error
- func (s *Storage) UpdatePassword(user *User, newPassword string) error
- func (s *Storage) UpdateRoleInstances(role *Role, instances ...*Instance) error
- func (s *Storage) UpdateRoleUsers(role *Role, users ...*User) error
- func (s *Storage) UpdateRollbackSQLById(rollbackSQLId string, attrs ...interface{}) error
- func (s *Storage) UpdateRollbackSQLs(rollbackSQLs []*RollbackSQL) error
- func (s *Storage) UpdateRollbackSqlStatus(baseSQL *BaseSQL, status, result string) error
- func (s *Storage) UpdateRuleTemplateInstances(tpl *RuleTemplate, instances ...*Instance) error
- func (s *Storage) UpdateRuleTemplateRules(tpl *RuleTemplate, rules ...RuleTemplateRule) error
- func (s *Storage) UpdateTask(task *Task, attrs ...interface{}) error
- func (s *Storage) UpdateTaskStatusById(taskId uint, status string) error
- func (s *Storage) UpdateUserRoles(user *User, rs ...*Role) error
- func (s *Storage) UpdateWorkflowRecord(w *Workflow, task *Task) error
- func (s *Storage) UpdateWorkflowStatus(w *Workflow, operateStep *WorkflowStep) error
- func (s *Storage) UpdateWorkflowTemplateInstances(workflowTemplate *WorkflowTemplate, instances ...*Instance) error
- func (s *Storage) UpdateWorkflowTemplateSteps(templateId uint, steps []*WorkflowStepTemplate) error
- func (s *Storage) UserCanAccessInstance(user *User, instance *Instance) (bool, error)
- func (s *Storage) UserCanAccessWorkflow(user *User, workflow *Workflow) (bool, error)
- func (s *Storage) UserHasBindWorkflowTemplate(user *User) (bool, error)
- func (s *Storage) UserHasRunningWorkflow(userId uint) (bool, error)
- type SystemVariable
- type Task
- type TaskSQLDetail
- type User
- type UserAuthenticationType
- type UserDetail
- type Workflow
- func (w *Workflow) CreateUserName() string
- func (w *Workflow) CurrentAssigneeUser() []*User
- func (w *Workflow) CurrentStep() *WorkflowStep
- func (w *Workflow) FinalStep() *WorkflowStep
- func (w *Workflow) IsFirstRecord(record *WorkflowRecord) bool
- func (w *Workflow) IsOperationUser(user *User) bool
- func (w *Workflow) NextStep() *WorkflowStep
- type WorkflowListDetail
- type WorkflowRecord
- type WorkflowStep
- type WorkflowStepTemplate
- type WorkflowTemplate
- type WorkflowTemplateDetail
Constants ¶
const ( SQLWhitelistExactMatch = "exact_match" SQLWhitelistFPMatch = "fp_match" )
const ( TaskStatusInit = "initialized" TaskStatusAudited = "audited" TaskStatusExecuting = "executing" TaskStatusExecuteSucceeded = "exec_succeeded" TaskStatusExecuteFailed = "exec_failed" )
const ( TaskSQLSourceFromFormData = "form_data" TaskSQLSourceFromSQLFile = "sql_file" TaskSQLSourceFromMyBatisXMLFile = "mybatis_xml_file" TaskSQLSourceFromAuditPlan = "audit_plan" )
const ( SQLAuditStatusInitialized = "initialized" SQLAuditStatusDoing = "doing" SQLAuditStatusFinished = "finished" )
const ( SQLExecuteStatusInitialized = "initialized" SQLExecuteStatusDoing = "doing" SQLExecuteStatusFailed = "failed" SQLExecuteStatusSucceeded = "succeeded" )
const ( WorkflowStepTypeSQLReview = "sql_review" WorkflowStepTypeSQLExecute = "sql_execute" WorkflowStepTypeCreateWorkflow = "create_workflow" WorkflowStepTypeUpdateWorkflow = "update_workflow" )
const ( WorkflowStatusRunning = "on_process" WorkflowStatusFinish = "finished" WorkflowStatusReject = "rejected" WorkflowStatusCancel = "canceled" )
const ( WorkflowStepStateInit = "initialized" WorkflowStepStateApprove = "approved" WorkflowStepStateReject = "rejected" )
const DefaultAdminUser = "admin"
const (
SystemVariableWorkflowExpiredHours = "system_variable_workflow_expired_hours"
)
const TaskExecResultOK = "OK"
Variables ¶
var DefaultWorkflowTemplate = "default"
var MockTime, _ = time.Parse("0000-00-00 00:00:00.0000000", "0000-00-00 00:00:00.0000000")
Functions ¶
func GetRuleMapFromAllArray ¶
func GetWorkflowStepTypeDesc ¶
func InitMockStorage ¶
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 AuditPlanReport ¶
type AuditPlanReport struct { Model AuditPlanID uint `json:"audit_plan_id" gorm:"index"` AuditPlan *AuditPlan `gorm:"foreignkey:AuditPlanID"` AuditPlanReportSQLs []*AuditPlanReportSQL `gorm:"foreignkey:AuditPlanReportID"` }
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 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 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 ¶
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 ¶
AfterFind is a hook implement gorm model after query, ignore err if query from db
func (*Instance) BeforeSave ¶
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 RoleDetail ¶
type RollbackSQL ¶
func (RollbackSQL) TableName ¶
func (s RollbackSQL) TableName() string
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"` }
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 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 (*Storage) AutoMigrate ¶
func (*Storage) CloneRuleTemplateRules ¶
func (s *Storage) CloneRuleTemplateRules(source, destination *RuleTemplate) error
func (*Storage) CreateAdminUser ¶
func (*Storage) CreateDefaultTemplate ¶
func (*Storage) CreateDefaultWorkflowTemplate ¶
func (*Storage) CreateRulesIfNotExist ¶
func (*Storage) CreateWorkflow ¶
func (*Storage) DeleteTask ¶
func (*Storage) DeleteWorkflow ¶
func (*Storage) GetAllRoleTip ¶
func (*Storage) GetAllRule ¶
func (*Storage) GetAllRuleByDBType ¶
func (*Storage) GetAllUserTip ¶
func (*Storage) GetAndCheckInstanceExist ¶
func (*Storage) GetAndCheckRoleExist ¶
func (*Storage) GetAndCheckRuleExist ¶
func (*Storage) GetAndCheckRuleTemplateExist ¶
func (s *Storage) GetAndCheckRuleTemplateExist(templateNames []string) (ruleTemplates []*RuleTemplate, err error)
func (*Storage) GetAndCheckUserExist ¶
func (*Storage) GetAuditPlanByName ¶
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 (*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 (*Storage) GetExpiredTasks ¶
func (*Storage) GetExpiredWorkflows ¶
func (*Storage) GetInstanceById ¶
func (*Storage) GetInstanceByName ¶
func (*Storage) GetInstanceDetailByName ¶
func (*Storage) GetInstanceNamesByWorkflowTemplateId ¶
func (*Storage) GetInstancesByNames ¶
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) GetRolesByNames ¶
func (*Storage) GetRolesByReq ¶
func (s *Storage) GetRolesByReq(data map[string]interface{}) ( result []*RoleDetail, count uint64, err 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 (*Storage) GetRulesByNames ¶
func (*Storage) GetRulesFromRuleTemplateByName ¶
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) GetTaskByInstanceId ¶
func (*Storage) GetTaskDetailById ¶
func (*Storage) GetTaskExecuteSQLContent ¶
func (*Storage) GetTaskSQLsByReq ¶
func (s *Storage) GetTaskSQLsByReq(data map[string]interface{}) ( result []*TaskSQLDetail, count uint64, err error)
func (*Storage) GetUserDetailByName ¶
func (*Storage) GetUserInstanceTip ¶
func (*Storage) GetUsersByNames ¶
func (*Storage) GetUsersByReq ¶
func (s *Storage) GetUsersByReq(data map[string]interface{}) ( result []*UserDetail, count uint64, err error)
func (*Storage) GetWorkflowBySubject ¶
func (*Storage) GetWorkflowByTaskId ¶
func (*Storage) GetWorkflowCountByReq ¶
func (*Storage) GetWorkflowDetailById ¶
func (*Storage) GetWorkflowExpiredHoursOrDefault ¶
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 (*Storage) OverrideAuditPlanSQLs ¶
func (s *Storage) OverrideAuditPlanSQLs(apName string, sqls []*AuditPlanSQL) error
func (*Storage) SaveWorkflowTemplate ¶
func (s *Storage) SaveWorkflowTemplate(template *WorkflowTemplate) error
func (*Storage) TaskWorkflowIsRunning ¶
func (*Storage) UpdateAuditPlanByName ¶
func (*Storage) UpdateAuditPlanSQLs ¶
func (s *Storage) UpdateAuditPlanSQLs(apName string, sqls []*AuditPlanSQL) error
func (*Storage) UpdateExecuteSQLById ¶
func (*Storage) UpdateExecuteSQLStatusByTaskId ¶
func (*Storage) UpdateExecuteSQLs ¶
func (s *Storage) UpdateExecuteSQLs(ExecuteSQLs []*ExecuteSQL) error
func (*Storage) UpdateExecuteSqlStatus ¶
func (*Storage) UpdateInstanceById ¶
func (*Storage) UpdateInstanceRoles ¶
func (*Storage) UpdateInstanceRuleTemplates ¶
func (s *Storage) UpdateInstanceRuleTemplates(instance *Instance, ts ...*RuleTemplate) error
func (*Storage) UpdatePassword ¶
func (*Storage) UpdateRoleInstances ¶
func (*Storage) UpdateRoleUsers ¶
func (*Storage) UpdateRollbackSQLById ¶
func (*Storage) UpdateRollbackSQLs ¶
func (s *Storage) UpdateRollbackSQLs(rollbackSQLs []*RollbackSQL) error
func (*Storage) UpdateRollbackSqlStatus ¶
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 (*Storage) UpdateTaskStatusById ¶
func (*Storage) UpdateWorkflowRecord ¶
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 (*Storage) UserCanAccessWorkflow ¶
func (*Storage) UserHasBindWorkflowTemplate ¶
type SystemVariable ¶
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 (*Task) HasDoingExecute ¶
func (*Task) HasDoingRollback ¶
func (*Task) InstanceName ¶
func (*Task) IsExecuteFailed ¶
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 ¶
AfterFind is a hook implement gorm model after query, ignore err if query from db
func (*User) BeforeSave ¶
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 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 (*Workflow) CurrentAssigneeUser ¶
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 (*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 WorkflowTemplate ¶
type WorkflowTemplate struct { Model Name string Desc string Steps []*WorkflowStepTemplate `json:"-" gorm:"foreignkey:workflowTemplateId"` Instances []*Instance `gorm:"foreignkey:WorkflowTemplateId"` }