feat: harden query read-only workflow
This commit is contained in:
1 parent
58bbc394e9
commit
617c15dbfe
29 files changed
+1417
-395
No files matched your search
@@ -396,25 +396,41 @@ func RedisInfo(c *gin.Context) {
|
||||
defer client.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
info, err := client.Info(ctx, "server", "memory", "clients", "stats", "keyspace").Result()
|
||||
info, err := client.Info(ctx).Result()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"detail": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// Parse info into structured map
|
||||
// Parse Redis INFO into both a flat map and section groups.
|
||||
result := make(map[string]interface{})
|
||||
grouped := make(map[string]map[string]interface{})
|
||||
currentSection := "General"
|
||||
sections := strings.Split(info, "\n# ")
|
||||
for _, section := range sections {
|
||||
lines := strings.Split(section, "\n")
|
||||
for _, line := range lines {
|
||||
for lineIndex, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" || strings.HasPrefix(line, "#") {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(line, "#") {
|
||||
currentSection = strings.TrimSpace(strings.TrimPrefix(line, "#"))
|
||||
continue
|
||||
}
|
||||
if lineIndex == 0 && !strings.Contains(line, ":") {
|
||||
currentSection = strings.TrimSpace(line)
|
||||
continue
|
||||
}
|
||||
parts := strings.SplitN(line, ":", 2)
|
||||
if len(parts) == 2 {
|
||||
result[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])
|
||||
key := strings.TrimSpace(parts[0])
|
||||
value := strings.TrimSpace(parts[1])
|
||||
result[key] = value
|
||||
if _, ok := grouped[currentSection]; !ok {
|
||||
grouped[currentSection] = make(map[string]interface{})
|
||||
}
|
||||
grouped[currentSection][key] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -422,8 +438,15 @@ func RedisInfo(c *gin.Context) {
|
||||
// Add db_size
|
||||
dbSize, _ := client.DBSize(ctx).Result()
|
||||
result["db_size"] = dbSize
|
||||
if _, ok := grouped["Keyspace"]; !ok {
|
||||
grouped["Keyspace"] = make(map[string]interface{})
|
||||
}
|
||||
grouped["Keyspace"]["db_size"] = dbSize
|
||||
|
||||
c.JSON(http.StatusOK, result)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"info": result,
|
||||
"sections": grouped,
|
||||
})
|
||||
}
|
||||
|
||||
// GET /api/v1/redis/:id/dbsize
|
||||
|
||||
Reference in new issue
Block a user