Skip to content

Conversation

@BugsGuru
Copy link
Collaborator

@BugsGuru BugsGuru commented Dec 4, 2025

User description

关联的 issue

https://github.com/actiontech/sqle-ee/issues/2597

描述你的变更

工作台审核支持在线审核

确认项(pr提交后操作)

Tip

请在指定复审人之前,确认并完成以下事项,完成后✅


  • 我已完成自测
  • 我已记录完整日志方便进行诊断
  • 我已在关联的issue里补充了实现方案
  • 我已在关联的issue里补充了测试影响面
  • 我已确认了变更的兼容性,如果不兼容则在issue里标记 not_compatible
  • 我已确认了是否要更新文档,如果要更新则在issue里标记 need_update_doc

link actiontech/sqle#3181


Description

  • 增加直接审计请求附加字段

  • 调整获取默认Schema逻辑顺序

  • 更新GraphQL请求参数传递


Diagram Walkthrough

flowchart LR
  A["原有参数处理"] --> B["添加 InstanceName"]
  A --> C["添加 SchemaName"]
  B --> D["更新DirectAuditParams"]
  C --> D
  D --> E["GraphQL请求中传参更新"]
Loading

File Walkthrough

Relevant files
Enhancement
cloudbeaver.go
增强直接审计请求参数处理                                                                                         

internal/dms/biz/cloudbeaver.go

  • 新增调用 getWorkflowExecParams 获取工作流参数
  • dbService.Name 赋予 InstanceName
  • 使用获取的 execParams.instanceSchema 赋予 SchemaName
  • 调整获取默认Schema判断顺序
+9/-4     
graphql.go
新增 GraphQL请求参数字段传递                                                                             

internal/pkg/cloudbeaver/graphql.go

  • AuditSQLReq 中添加 InstanceNameSchemaName 字段
  • 在 GraphQL中传递新增字段
+4/-0     

@actiontech-bot actiontech-bot requested review from LordofAvernus and removed request for LordofAvernus December 4, 2025 08:03
@github-actions
Copy link

github-actions bot commented Dec 4, 2025

PR Reviewer Guide 🔍

(Review updated until commit 063d93b)

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

逻辑调整

修改了获取默认Schema的逻辑顺序,现在如果DefaultCatalog存在将优先返回,需确认此调整是否符合业务预期。

contextInfo := res.Contexts[0]
if contextInfo.DefaultCatalog != nil && *contextInfo.DefaultCatalog != "" {
	return *contextInfo.DefaultCatalog, nil
}
if contextInfo.DefaultSchema != nil && *contextInfo.DefaultSchema != "" {
	return *contextInfo.DefaultSchema, nil
}
字段扩展

在AuditSQLReq结构体中新增了InstanceName和SchemaName字段,并在MutationResolver中传递相关参数,建议确认这些新增字段在后续数据处理和调用中均得到正确使用。

type AuditSQLReq struct {
	InstanceType string `json:"instance_type" form:"instance_type" example:"MySQL" valid:"required"`
	// 调用方不应该关心SQL是否被完美的拆分成独立的条目, 拆分SQL由SQLE实现
	SQLContent       string `json:"sql_content" form:"sql_content" example:"select * from t1; select * from t2;" valid:"required"`
	SQLType          string `json:"sql_type" form:"sql_type" example:"sql" enums:"sql,mybatis," valid:"omitempty,oneof=sql mybatis"`
	ProjectId        string `json:"project_id" form:"project_id" example:"700300" valid:"required"`
	RuleTemplateName string `json:"rule_template_name" form:"rule_template_name" example:"default" valid:"required"`
	InstanceName     string `json:"instance_name" form:"instance_name" example:"instance1"`
	SchemaName       string `json:"schema_name" form:"schema_name" example:"schema1"`
}

type DirectAuditParams struct {
	AuditSQLReq
	SQLEAddr                         string
	AllowQueryWhenLessThanAuditLevel string
}

type AuditSQLResV2 struct {
	Number      uint                 `json:"number"`
	ExecSQL     string               `json:"exec_sql"`
	AuditResult dbmodel.AuditResults `json:"audit_result"`
	AuditLevel  string               `json:"audit_level"`
	SQLType     string               `json:"sql_type"`
}

type AuditResDataV2 struct {
	AuditLevel string          `json:"audit_level" enums:"normal,notice,warn,error,"`
	Score      int32           `json:"score"`
	PassRate   float64         `json:"pass_rate"`
	SQLResults []AuditSQLResV2 `json:"sql_results"`
}

type auditSQLReply struct {
	Code    int             `json:"code" example:"0"`
	Message string          `json:"message" example:"ok"`
	Data    *AuditResDataV2 `json:"data"`
}

// AuditSQL todo: this is a provisional programme that will need to be adjusted at a later stage
func (r *MutationResolverImpl) AuditSQL(ctx context.Context, sql string, connectionID string) (auditSuccess bool, result []AuditSQLResV2, err error) {
	header := map[string]string{
		"Authorization": pkgHttp.DefaultDMSToken,
	}

	ctxVal := ctx.Value(SQLEDirectAudit)
	directAuditParams, ok := ctxVal.(DirectAuditParams)
	if !ok {
		return false, nil, fmt.Errorf("ctx.value %v failed", SQLEDirectAudit)
	}

	if directAuditParams.SQLEAddr == "" {
		return false, nil, fmt.Errorf("%v is empty", SQLEDirectAudit)
	}

	req := AuditSQLReq{
		InstanceType:     directAuditParams.InstanceType,
		SQLContent:       sql,
		SQLType:          "sql",
		ProjectId:        directAuditParams.ProjectId,
		RuleTemplateName: directAuditParams.RuleTemplateName,
		InstanceName:     directAuditParams.InstanceName,
		SchemaName:       directAuditParams.SchemaName,
	}

@github-actions
Copy link

github-actions bot commented Dec 4, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
检查 nil 指针解引用

建议在解引用 execParams 前先验证其是否为 nil,以防止潜在的空指针解引用导致 panic。如果确定 execParams 可能为 nil,请添加相应的
nil 检查。

internal/dms/biz/cloudbeaver.go [489-493]

 execParams, err := cu.getWorkflowExecParams(c, params)
 if err != nil {
     return err
 }
-cu.log.Debugf("sql server exec params: %+v", *execParams)
+if execParams != nil {
+    cu.log.Debugf("sql server exec params: %+v", *execParams)
+} else {
+    cu.log.Debug("sql server exec params is nil")
+}
Suggestion importance[1-10]: 7

__

Why: The suggestion adds a nil-check before dereferencing execParams to prevent potential panics, which is a good safety improvement but not critical to overall functionality.

Medium

@github-actions
Copy link

github-actions bot commented Dec 5, 2025

Persistent review updated to latest commit 063d93b

@github-actions
Copy link

github-actions bot commented Dec 5, 2025

PR Code Suggestions ✨

No code suggestions found for the PR.

@LordofAvernus LordofAvernus merged commit 4a6ba7f into main Dec 5, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants