35 lines
1015 B
Go
35 lines
1015 B
Go
package webui
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/access"
|
|
)
|
|
|
|
const defaultDenialsListLimit = 100
|
|
|
|
// handleListDenials lists the caller's org's recorded access denials, newest
|
|
// first. The route's read_audit grant limits it to the org's admins and
|
|
// owners, and the store scopes the list by the credential's org, so no
|
|
// request field chooses the org an operator reads.
|
|
func (a *accessAPI) handleListDenials(w http.ResponseWriter, r *http.Request) {
|
|
if a.denials == nil {
|
|
http.Error(w, "denial records unavailable", http.StatusServiceUnavailable)
|
|
return
|
|
}
|
|
limit, err := strconv.ParseInt(r.URL.Query().Get("limit"), 10, 32)
|
|
if err != nil || limit <= 0 || limit > 1000 {
|
|
limit = defaultDenialsListLimit
|
|
}
|
|
denials, err := a.denials.ListDenials(r.Context(), policyOrg(r), int(limit))
|
|
if err != nil {
|
|
writeControlPlaneError(w, err)
|
|
return
|
|
}
|
|
if denials == nil {
|
|
denials = []access.Denial{}
|
|
}
|
|
writeJSON(w, map[string]any{"denials": denials})
|
|
}
|