mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-06-11 18:12:09 +00:00
75c570e951
- Secure CLI credential injection via AES-256-GCM encrypted env vars - API key management with fine-grained RBAC scopes - resolveAuth/requireAuth middleware across all 25+ HTTP handlers - In-memory API key cache with TTL, negative caching, pubsub invalidation - Sandbox-first execution (fails if unavailable, no silent fallback) - Credential scrubbing, constant-time token comparison, Admin-only CLI creds - SQL migration 000020: secure_cli_binaries + api_keys tables - 14 unit tests for cache and RBAC with race detector Closes #197
36 lines
1.4 KiB
Go
36 lines
1.4 KiB
Go
package http
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/nextlevelbuilder/goclaw/internal/store"
|
|
)
|
|
|
|
// MemoryHandler handles memory document management endpoints.
|
|
type MemoryHandler struct {
|
|
store store.MemoryStore
|
|
token string
|
|
}
|
|
|
|
// NewMemoryHandler creates a handler for memory management endpoints.
|
|
func NewMemoryHandler(s store.MemoryStore, token string) *MemoryHandler {
|
|
return &MemoryHandler{store: s, token: token}
|
|
}
|
|
|
|
// RegisterRoutes registers all memory routes on the given mux.
|
|
func (h *MemoryHandler) RegisterRoutes(mux *http.ServeMux) {
|
|
mux.HandleFunc("GET /v1/memory/documents", h.auth(h.handleListAllDocuments))
|
|
mux.HandleFunc("GET /v1/agents/{agentID}/memory/documents", h.auth(h.handleListDocuments))
|
|
mux.HandleFunc("GET /v1/agents/{agentID}/memory/documents/{path...}", h.auth(h.handleGetDocument))
|
|
mux.HandleFunc("PUT /v1/agents/{agentID}/memory/documents/{path...}", h.auth(h.handlePutDocument))
|
|
mux.HandleFunc("DELETE /v1/agents/{agentID}/memory/documents/{path...}", h.auth(h.handleDeleteDocument))
|
|
mux.HandleFunc("GET /v1/agents/{agentID}/memory/chunks", h.auth(h.handleListChunks))
|
|
mux.HandleFunc("POST /v1/agents/{agentID}/memory/index", h.auth(h.handleIndexDocument))
|
|
mux.HandleFunc("POST /v1/agents/{agentID}/memory/index-all", h.auth(h.handleIndexAll))
|
|
mux.HandleFunc("POST /v1/agents/{agentID}/memory/search", h.auth(h.handleSearch))
|
|
}
|
|
|
|
func (h *MemoryHandler) auth(next http.HandlerFunc) http.HandlerFunc {
|
|
return requireAuth(h.token, "", next)
|
|
}
|