Spaces:
Paused
Paused
security: complete destruction of keys in public stats
Browse files- internal/handler/keys.go +25 -3
internal/handler/keys.go
CHANGED
|
@@ -67,10 +67,32 @@ func HandleGenKey(w http.ResponseWriter, r *http.Request) {
|
|
| 67 |
key := GenerateKey(name)
|
| 68 |
json.NewEncoder(w).Encode(map[string]string{"key": key, "name": name})
|
| 69 |
}
|
|
|
|
| 70 |
func HandleStats(w http.ResponseWriter, r *http.Request) {
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
res := make(map[string]Pub)
|
| 75 |
for k, v := range store.Keys { masked := k[:8] + "..."; res[masked] = Pub{Name: v.Name, Key: masked, Requests: v.Requests, Tokens: v.Tokens} }
|
| 76 |
json.NewEncoder(w).Encode(map[string]interface{}{"keys": res})
|
|
|
|
| 67 |
key := GenerateKey(name)
|
| 68 |
json.NewEncoder(w).Encode(map[string]string{"key": key, "name": name})
|
| 69 |
}
|
| 70 |
+
|
| 71 |
func HandleStats(w http.ResponseWriter, r *http.Request) {
|
| 72 |
+
store.mu.Lock()
|
| 73 |
+
defer store.mu.Unlock()
|
| 74 |
+
w.Header().Set("Content-Type", "application/json")
|
| 75 |
+
|
| 76 |
+
type Pub struct {
|
| 77 |
+
Name string `json:"name"`
|
| 78 |
+
Requests int `json:"requests"`
|
| 79 |
+
Tokens int `json:"tokens"`
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
res := make(map[string]Pub)
|
| 83 |
+
i := 0
|
| 84 |
+
for _, v := range store.Keys {
|
| 85 |
+
// Usamos un ID genérico para el JSON para que no rastreen nada
|
| 86 |
+
id := fmt.Sprintf("user_%d", i)
|
| 87 |
+
res[id] = Pub{
|
| 88 |
+
Name: v.Name,
|
| 89 |
+
Requests: v.Requests,
|
| 90 |
+
Tokens: v.Tokens,
|
| 91 |
+
}
|
| 92 |
+
i++
|
| 93 |
+
}
|
| 94 |
+
json.NewEncoder(w).Encode(map[string]interface{}{"keys": res})
|
| 95 |
+
}
|
| 96 |
res := make(map[string]Pub)
|
| 97 |
for k, v := range store.Keys { masked := k[:8] + "..."; res[masked] = Pub{Name: v.Name, Key: masked, Requests: v.Requests, Tokens: v.Tokens} }
|
| 98 |
json.NewEncoder(w).Encode(map[string]interface{}{"keys": res})
|