Sync shared snapshot from 51eef30
This commit is contained in:
1 parent
b3d27ff37e
commit
ec82a8a8b9
4 files changed
+93
-1
No files matched your search
@@ -172,6 +172,7 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
@@ -276,6 +277,12 @@ type Service struct {
|
||||
// real base URL.
|
||||
authGuard *authclient.Client
|
||||
configurationError error
|
||||
// loginRequiredOverride is populated by the internal ProjectConfigurator
|
||||
// endpoint. Some legacy consumers intentionally use a no-op ProxyStore for
|
||||
// this setting because they historically had no local toggle; the live
|
||||
// override lets those services still honor the central setting immediately.
|
||||
loginRequiredMu sync.RWMutex
|
||||
loginRequiredOverride *bool
|
||||
}
|
||||
|
||||
// ServiceOption configures optional New/NewWithStore construction behavior.
|
||||
@@ -750,6 +757,15 @@ func (s *Service) AdminNeeded(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *Service) LoginRequired(ctx context.Context) (bool, error) {
|
||||
s.loginRequiredMu.RLock()
|
||||
override := s.loginRequiredOverride
|
||||
s.loginRequiredMu.RUnlock()
|
||||
if override != nil {
|
||||
return *override, nil
|
||||
}
|
||||
if s.store == nil {
|
||||
return true, nil
|
||||
}
|
||||
return s.store.LoginRequired(ctx)
|
||||
}
|
||||
|
||||
@@ -783,7 +799,40 @@ func (s *Service) UpdateAccessSettings(w http.ResponseWriter, r *http.Request) {
|
||||
// central "Require Login" toggle (ConfigWorkspace.svelte's loginControls) apply here without an
|
||||
// admin session of its own.
|
||||
func (s *Service) SetLoginRequired(ctx context.Context, required bool) error {
|
||||
return s.store.SetLoginRequired(ctx, required)
|
||||
if s.store != nil {
|
||||
if err := s.store.SetLoginRequired(ctx, required); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
s.loginRequiredMu.Lock()
|
||||
s.loginRequiredOverride = &required
|
||||
s.loginRequiredMu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetLoginRequiredInternal returns the X-Internal-Auth-gated handler used by
|
||||
// ProjectConfigurator to apply its per-project "Require Login" setting. It
|
||||
// lives on the shared service so projects outside the core-service family can
|
||||
// expose the same propagation endpoint without duplicating its JSON handling.
|
||||
func (s *Service) SetLoginRequiredInternal(secret string) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.TrimSpace(secret) == "" || r.Header.Get("X-Internal-Auth") != secret {
|
||||
writeProxyError(w, http.StatusUnauthorized, "internal service authentication required")
|
||||
return
|
||||
}
|
||||
var input struct {
|
||||
LoginRequired *bool `json:"loginRequired"`
|
||||
}
|
||||
if err := decodeProxyJSON(r, &input); err != nil || input.LoginRequired == nil {
|
||||
writeProxyError(w, http.StatusBadRequest, "loginRequired must be a boolean")
|
||||
return
|
||||
}
|
||||
if err := s.SetLoginRequired(r.Context(), *input.LoginRequired); err != nil {
|
||||
writeProxyError(w, http.StatusInternalServerError, "access setting could not be saved")
|
||||
return
|
||||
}
|
||||
writeProxyJSON(w, http.StatusOK, map[string]bool{"loginRequired": *input.LoginRequired})
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Service) Status(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in new issue
Block a user