Spaces:
Paused
Paused
security: force key masking
Browse files- internal/handler/keys.go +17 -3
internal/handler/keys.go
CHANGED
|
@@ -85,15 +85,29 @@ func HandleGenKey(w http.ResponseWriter, r *http.Request) {
|
|
| 85 |
json.NewEncoder(w).Encode(map[string]string{"key": key, "name": name})
|
| 86 |
}
|
| 87 |
func HandleStats(w http.ResponseWriter, r *http.Request) {
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
| 91 |
type KeyPublic struct {
|
| 92 |
Name string `json:"name"`
|
| 93 |
Key string `json:"key"`
|
| 94 |
Requests int `json:"requests"`
|
| 95 |
Tokens int `json:"tokens"`
|
| 96 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
publicKeys := make(map[string]KeyPublic)
|
| 98 |
for k, v := range store.Keys {
|
| 99 |
// Mostramos solo el prefijo y los primeros 3 caracteres de la key
|
|
|
|
| 85 |
json.NewEncoder(w).Encode(map[string]string{"key": key, "name": name})
|
| 86 |
}
|
| 87 |
func HandleStats(w http.ResponseWriter, r *http.Request) {
|
| 88 |
+
store.mu.Lock()
|
| 89 |
+
defer store.mu.Unlock()
|
| 90 |
+
w.Header().Set("Content-Type", "application/json")
|
| 91 |
+
|
| 92 |
type KeyPublic struct {
|
| 93 |
Name string `json:"name"`
|
| 94 |
Key string `json:"key"`
|
| 95 |
Requests int `json:"requests"`
|
| 96 |
Tokens int `json:"tokens"`
|
| 97 |
}
|
| 98 |
+
|
| 99 |
+
publicKeys := make(map[string]KeyPublic)
|
| 100 |
+
for k, v := range store.Keys {
|
| 101 |
+
masked := k[:8] + "..."
|
| 102 |
+
publicKeys[masked] = KeyPublic{
|
| 103 |
+
Name: v.Name,
|
| 104 |
+
Key: masked,
|
| 105 |
+
Requests: v.Requests,
|
| 106 |
+
Tokens: v.Tokens,
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
json.NewEncoder(w).Encode(map[string]interface{}{"keys": publicKeys})
|
| 110 |
+
}
|
| 111 |
publicKeys := make(map[string]KeyPublic)
|
| 112 |
for k, v := range store.Keys {
|
| 113 |
// Mostramos solo el prefijo y los primeros 3 caracteres de la key
|