package api import ( "context" "net/http" "time" "droboticflow/internal/store" ) func (s *server) handleSourceAdmissionReadiness(w http.ResponseWriter, r *http.Request) { principal, allowed := s.productionAdmin(w, r) if !allowed { return } db, ok := s.store.(store.SourceReadinessStore) if !ok { renderJSON(w, http.StatusServiceUnavailable, map[string]string{"error": "source readiness reporting unavailable"}) return } w.Header().Set("Cache-Control", "no-store") ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second) defer cancel() org, project := s.requestOrganizationID(r), r.URL.Query().Get("projectId") if r.URL.Query().Get("scope") == "deployment" { if !principal.User.IsSuperAdmin || project != "" { renderJSON(w, http.StatusForbidden, map[string]string{"error": "deployment readiness requires super administrator and no project filter"}) return } org = "" } if !s.sourceReadinessRunning.CompareAndSwap(false, true) { renderJSON(w, http.StatusTooManyRequests, map[string]string{"error": "source readiness report already running"}) return } defer s.sourceReadinessRunning.Store(false) report, err := db.SourceAdmissionReadiness(ctx, org, project) if err != nil { renderJSON(w, http.StatusServiceUnavailable, map[string]string{"error": "source readiness report incomplete", "requestId": store.ReadRequestID(r.Context())}) return } report.Namespace = s.k8sNamespace report.BuildCommit = s.buildCommit renderJSON(w, http.StatusOK, report) }