Files
mcr/internal/server/admin_audit.go
Kyle Isom dddc66f31b Phases 5, 6, 8: OCI pull/push paths and admin REST API
Phase 5 (OCI pull): internal/oci/ package with manifest GET/HEAD by
tag/digest, blob GET/HEAD with repo membership check, tag listing with
OCI pagination, catalog listing. Multi-segment repo names via
parseOCIPath() right-split routing. DB query layer in
internal/db/repository.go.

Phase 6 (OCI push): blob uploads (monolithic and chunked) with
uploadManager tracking in-progress BlobWriters, manifest push
implementing full ARCHITECTURE.md §5 flow in a single SQLite
transaction (create repo, upsert manifest, populate manifest_blobs,
atomic tag move). Digest verification on both blob commit and manifest
push-by-digest.

Phase 8 (admin REST): /v1 endpoints for auth (login/logout/health),
repository management (list/detail/delete), policy CRUD with engine
reload, audit log listing with filters, GC trigger/status stubs.
RequireAdmin middleware, platform-standard error format.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 18:25:18 -07:00

49 lines
1.0 KiB
Go

package server
import (
"net/http"
"strconv"
"git.wntrmute.dev/kyle/mcr/internal/db"
)
// AdminListAuditHandler handles GET /v1/audit.
func AdminListAuditHandler(database *db.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
limit := 50
if n := q.Get("n"); n != "" {
if v, err := strconv.Atoi(n); err == nil && v > 0 {
limit = v
}
}
offset := 0
if o := q.Get("offset"); o != "" {
if v, err := strconv.Atoi(o); err == nil && v >= 0 {
offset = v
}
}
filter := db.AuditFilter{
EventType: q.Get("event_type"),
ActorID: q.Get("actor_id"),
Repository: q.Get("repository"),
Since: q.Get("since"),
Until: q.Get("until"),
Limit: limit,
Offset: offset,
}
events, err := database.ListAuditEvents(filter)
if err != nil {
writeAdminError(w, http.StatusInternalServerError, "internal error")
return
}
if events == nil {
events = []db.AuditEvent{}
}
writeJSON(w, http.StatusOK, events)
}
}