Learn AuthGuard/CarrierNode URLs from ProjectConfigurator's push
Adds the receiving end of ProjectConfigurator's core-services push (PUT /api/core-services/internal, X-Internal-Auth-gated) via the shared coreconfig package, so this service's AUTHGUARD_URL/CARRIERNODE_URL env vars become just the bootstrap/fallback value instead of the permanent source of truth. authclient.Client gains a concurrency-safe SetBaseURL so a later push retargets it in place with no restart. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
20e9461d46
commit
7c4a903f59
7 files changed
+323
-11
No files matched your search
+37
-4
@@ -17,6 +17,8 @@ import (
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
|
||||
authclient "repos.gfranz.ch/Gabriel20xx/shared/backend/authclient"
|
||||
"repos.gfranz.ch/Gabriel20xx/shared/backend/carriernodeclient"
|
||||
"repos.gfranz.ch/Gabriel20xx/shared/backend/coreconfig"
|
||||
)
|
||||
|
||||
// The SvelteKit build is copied here by the Docker builder before go build.
|
||||
@@ -27,9 +29,12 @@ import (
|
||||
var webFS embed.FS
|
||||
|
||||
type Server struct {
|
||||
db *DB
|
||||
auth *AuthService
|
||||
startTime time.Time
|
||||
db *DB
|
||||
auth *AuthService
|
||||
startTime time.Time
|
||||
internalServiceSecret string
|
||||
coreConfig *coreconfig.Store
|
||||
carrierNode *carriernodeclient.Client
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -65,8 +70,33 @@ func main() {
|
||||
fmt.Println("auth: DISABLED (AUTHGUARD_URL not set) -- every request is treated as authenticated")
|
||||
}
|
||||
|
||||
// coreConfig holds the AuthGuard/CarrierNode URLs ProjectConfigurator pushes once this project
|
||||
// is registered there (PUT /api/core-services/internal, see registerRoutes) -- AUTHGUARD_URL and
|
||||
// CARRIERNODE_URL above/below are only the bootstrap fallback used until the first push arrives.
|
||||
// See Core/ProjectConfigurator/README.md's "Pushing core service info to other projects".
|
||||
internalServiceSecret := strings.TrimSpace(os.Getenv("INTERNAL_SERVICE_SECRET"))
|
||||
carrierNodeURL := strings.TrimSpace(os.Getenv("CARRIERNODE_URL"))
|
||||
coreConfig := coreconfig.NewStore(coreconfig.Info{AuthGuardURL: authGuardURL, CarrierNodeURL: carrierNodeURL})
|
||||
if authGuard != nil {
|
||||
coreConfig.OnUpdate(func(info coreconfig.Info) {
|
||||
if info.AuthGuardURL != "" {
|
||||
authGuard.SetBaseURL(info.AuthGuardURL)
|
||||
}
|
||||
})
|
||||
}
|
||||
carrierNode := carriernodeclient.New(internalServiceSecret, func(context.Context) string {
|
||||
return coreConfig.CarrierNodeURL()
|
||||
})
|
||||
|
||||
auth := newAuthService(authGuard, database, strings.EqualFold(os.Getenv("COOKIE_SECURE"), "true"))
|
||||
server := &Server{db: database, auth: auth, startTime: time.Now()}
|
||||
server := &Server{
|
||||
db: database,
|
||||
auth: auth,
|
||||
startTime: time.Now(),
|
||||
internalServiceSecret: internalServiceSecret,
|
||||
coreConfig: coreConfig,
|
||||
carrierNode: carrierNode,
|
||||
}
|
||||
|
||||
webRoot, err := fs.Sub(webFS, "web")
|
||||
if err != nil {
|
||||
@@ -132,6 +162,9 @@ func (s *Server) registerRoutes(mux *http.ServeMux, webRoot fs.FS) {
|
||||
// Health and auth bootstrap routes are intentionally public.
|
||||
mux.HandleFunc("GET /health", s.handleHealth)
|
||||
mux.HandleFunc("GET /api/info", s.handleInfo)
|
||||
// X-Internal-Auth-gated, not browser-session-gated -- ProjectConfigurator calls this directly
|
||||
// to push a fresh AuthGuard/CarrierNode URL (see coreConfig's construction in main above).
|
||||
mux.Handle("PUT /api/core-services/internal", coreconfig.Handler(s.internalServiceSecret, s.coreConfig))
|
||||
mux.HandleFunc("GET /api/auth/status", s.auth.handleStatus)
|
||||
mux.HandleFunc("POST /api/auth/setup", s.auth.handleSetup)
|
||||
mux.HandleFunc("POST /api/auth/login", s.auth.handleLogin)
|
||||
|
||||
Reference in new issue
Block a user