-
Notifications
You must be signed in to change notification settings - Fork 8
update #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update #96
Conversation
Summary of ChangesHello @Erickw87, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求主要侧重于更新 Go 依赖项、将服务管理器的部署 API 重构为使用 Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
🚀 Frontend deployed successfully! 📱 Preview URL: https://zeroops-of5ayyvef-liuscrafts-projects.vercel.app ✅ Build completed successfully |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
本次更新包含多个文件的修改,包括依赖项更新、数据库字段重命名、以及从 fox 框架迁移到 gin 框架。这些变更大部分是积极的维护和重构。
然而,其中一个变动是完全移除了告警 webhook 的认证逻辑,这是一个严重的安全风险,需要立即处理。此外,我还发现了一个模型字段命名不一致的问题,以及一个需要完善的测试用例。
PR 的描述过于简单,没有解释这些重要变更(尤其是安全相关的)背后的原因,建议后续提供更详细的说明。
| // ConfigureAuth is a no-op; authentication disabled at source. | ||
| func ConfigureAuth(user, pass, bearer string) {} | ||
|
|
||
| // AuthMiddleware returns false if unauthorized and writes a 401 response. | ||
| func AuthMiddleware(c *gin.Context) bool { | ||
| if !authEnabled() { | ||
| return true | ||
| } | ||
|
|
||
| // prefer config | ||
| user := cfgBasicUser | ||
| pass := cfgBasicPass | ||
| bearer := cfgBearer | ||
| // fallback to env if not set in config | ||
| if user == "" && pass == "" && bearer == "" { | ||
| user = os.Getenv("ALERT_WEBHOOK_BASIC_USER") | ||
| pass = os.Getenv("ALERT_WEBHOOK_BASIC_PASS") | ||
| bearer = os.Getenv("ALERT_WEBHOOK_BEARER") | ||
| } | ||
|
|
||
| if user != "" || pass != "" { | ||
| u, p, ok := c.Request.BasicAuth() | ||
| if !ok || u != user || p != pass { | ||
| c.JSON(http.StatusUnauthorized, map[string]any{"ok": false, "error": "unauthorized"}) | ||
| return false | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| if bearer != "" { | ||
| if c.GetHeader("Authorization") != "Bearer "+bearer { | ||
| c.JSON(http.StatusUnauthorized, map[string]any{"ok": false, "error": "unauthorized"}) | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| } | ||
| func AuthMiddleware(c *gin.Context) bool { return true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ReportAt time.Time `json:"reportAt" db:"report_at"` // time - 报告时间 | ||
| ResolvedAt *time.Time `json:"resolvedAt" db:"resolved_at"` // time - 解决时间 | ||
| HealthState HealthState `json:"healthState" db:"health_state"` // 健康状态 | ||
| CorrelationID string `json:"alertIssueIds" db:"alert_issue_ids"` // varchar - 关联ID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
结构体字段名 CorrelationID 与其 JSON 标签 json:"alertIssueIds" 和数据库标签 db:"alert_issue_ids" 不一致。为了保持代码的清晰性和一致性,建议将字段名修改为 AlertIssueIDs,以遵循 Go 的命名规范并与标签含义保持一致。
| CorrelationID string `json:"alertIssueIds" db:"alert_issue_ids"` // varchar - 关联ID | |
| AlertIssueIDs string "json:\"alertIssueIds\" db:\"alert_issue_ids\"" // varchar - 关联ID |
| func TestCommon(t *testing.T) { | ||
| baseTh := 97.0 | ||
|
|
||
| newThreshold := baseTh - math.Ceil(baseTh*0.01) | ||
| fmt.Println(newThreshold) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个测试函数 TestCommon 只是打印了一个计算结果,并没有使用任何断言来验证其正确性。一个有效的单元测试应该包含明确的输入、预期输出和断言。如果这只是一个用于临时调试的测试,请在合并前将其移除或完善成一个真正的测试用例。
| func TestCommon(t *testing.T) { | |
| baseTh := 97.0 | |
| newThreshold := baseTh - math.Ceil(baseTh*0.01) | |
| fmt.Println(newThreshold) | |
| } | |
| func TestCommon(t *testing.T) { | |
| baseTh := 97.0 | |
| expected := 96.0 | |
| newThreshold := baseTh - math.Ceil(baseTh*0.01) | |
| if newThreshold != expected { | |
| t.Errorf("Expected newThreshold to be %f, but got %f", expected, newThreshold) | |
| } | |
| } |
变更背景和解决方案
关联issue: #
文档更新(架构文档、API文档、升级文档)
Checklist