fix: add latest config apply state retrieval; enhance status response with configuration details

This commit is contained in:
GitHub Actions
2026-02-13 18:49:28 +00:00
parent d8c08c4b5d
commit 0024b81e39
3 changed files with 73 additions and 0 deletions
@@ -198,9 +198,43 @@ func (h *SecurityHandler) GetStatus(c *gin.Context) {
"mode": aclMode,
"enabled": aclEnabled,
},
"config_apply": latestConfigApplyState(h.db),
})
}
func latestConfigApplyState(db *gorm.DB) gin.H {
state := gin.H{
"available": false,
"status": "unknown",
}
if db == nil {
return state
}
var latest models.CaddyConfig
err := db.Order("applied_at desc").First(&latest).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return state
}
return state
}
status := "failed"
if latest.Success {
status = "applied"
}
state["available"] = true
state["status"] = status
state["success"] = latest.Success
state["applied_at"] = latest.AppliedAt
state["error_msg"] = latest.ErrorMsg
return state
}
// GetConfig returns the site security configuration from DB or default
func (h *SecurityHandler) GetConfig(c *gin.Context) {
cfg, err := h.svc.Get()