Files
sam 864b87faa6
Quality / check (push) Successful in 3m52s
deploy / gate (push) Successful in 4m29s
deploy / archied-image (push) Successful in 2m48s
deploy / agent-image (push) Successful in 11s
deploy / dist-zip (push) Skipped
refactor(webui): extract event-types, mappings and sources modules (#1778)
Same pattern as the bindings pilot: eventTypesAPI (registers unconditionally,
list answers enabled:false without a store), mappingsAPI and sourcesAPI
(constructed only when their store is configured, 503 stub otherwise).
Shared helpers unsignedSources/recentRefusals/listedIn stay on Server; the
dispatch-ledger handler stays shared for captures/tasks. task check green.
2026-11-03 07:42:50 +11:00

63 lines
1.9 KiB
Go

package webui
import (
"context"
"net/http"
"time"
"github.com/samcharles93/archie-core/internal/domain/org"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
)
// Shared source helpers: unsignedSources feeds the bindings list, recentRefusals
// the sources list, listedIn every workspace-scoped list.
// Capture sources and their signing setting. A secret is returned only by the
// two writes that generate it, so the operator can copy it into the sender;
// every other read withholds it. Turning signing off is a request plus an
// approval, both behind the same mutation gate that arms a binding.
// unsignedSources is the set of source paths approved to take unsigned
// events. With no source store nothing is unsigned.
func (s *Server) unsignedSources(ctx context.Context) (map[string]bool, error) {
out := map[string]bool{}
if s.Sources == nil {
return out, nil
}
list, err := s.Sources.ListSources(ctx)
if err != nil {
return nil, err
}
for _, src := range list {
if src.Unsigned() {
out[src.Path] = true
}
}
return out, nil
}
// recentRefusals maps each source to what the network rules refused on it in
// the last day. Unavailable refusals leave the map empty.
func (s *Server) recentRefusals(r *http.Request) map[string]storecontract.CaptureRefusals {
out := map[string]storecontract.CaptureRefusals{}
if s.Refusals == nil {
return out
}
list, err := s.Refusals.CaptureRefusals(r.Context(), s.clock().Add(-24*time.Hour))
if err != nil {
s.Log.WarnContext(r.Context(), "capture refusals unavailable", "err", err)
return out
}
for _, c := range list {
out[c.Source] = c
}
return out
}
// listedIn reports whether a record in ws belongs in a list the request
// narrowed with ?workspace=; with none, every record does.
func listedIn(r *http.Request, ws org.WorkspaceID) bool {
want := r.URL.Query().Get("workspace")
return want == "" || org.WorkspaceID(want) == ws
}