Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
feat(cloudcp): wire Pulse Account bootstrap route
rcourtmandbc3b7962cc2
diff --git a/internal/cloudcp/routes.go b/internal/cloudcp/routes.goindex d9c261c34c..f1737b9163 100644--- a/internal/cloudcp/routes.go+++ b/internal/cloudcp/routes.go@@ -112,17 +112,16 @@ func RegisterRoutes(mux *http.ServeMux, deps *Deps) {baseDomain := baseDomainFromURL(deps.Config.BaseURL)mux.Handle("/auth/magic-link/verify", magicLinkVerifyLimiter.Middleware(http.HandlerFunc(cpauth.HandleMagicLinkVerify(deps.MagicLinks, deps.Registry, deps.Config.TenantsDir(), baseDomain))))if deps.MagicLinks != nil {- mux.Handle("/auth/logout", sessionAuthLimiter.Middleware(sessionAuth(cpauth.HandleLogout(deps.Registry))))+ mux.Handle(portal.PortalLogoutPath, sessionAuthLimiter.Middleware(sessionAuth(cpauth.HandleLogout(deps.Registry))))}// Hosted Pulse Pro trial signup: public form + checkout + return completion.trialSignupHandlers := NewTrialSignupHandlers(deps.Config, deps.EmailSender, deps.TrialSignupStore, hostedEntitlements)hostedEntitlementHandlers := NewHostedEntitlementHandlers(hostedEntitlements)- trialSignupRateLimited := trialSignupHandlers.HandleRateLimitedTrialSignup- mux.Handle("/start-pro-trial", trialSignupPageLimiter.MiddlewareWithRejected(http.HandlerFunc(trialSignupHandlers.HandleStartProTrial), trialSignupRateLimited))- mux.Handle("/api/trial-signup/request-verification", trialSignupVerificationLimiter.MiddlewareWithRejected(http.HandlerFunc(trialSignupHandlers.HandleRequestVerification), trialSignupRateLimited))- mux.Handle("/trial-signup/verify", trialSignupVerifyLimiter.MiddlewareWithRejected(http.HandlerFunc(trialSignupHandlers.HandleVerifyEmail), trialSignupRateLimited))- mux.Handle("/api/trial-signup/checkout", trialSignupCheckoutLimiter.MiddlewareWithRejected(http.HandlerFunc(trialSignupHandlers.HandleCheckout), trialSignupRateLimited))+ mux.Handle("/start-pro-trial", trialSignupPageLimiter.Middleware(http.HandlerFunc(trialSignupHandlers.HandleStartProTrial)))+ mux.Handle("/api/trial-signup/request-verification", trialSignupVerificationLimiter.Middleware(http.HandlerFunc(trialSignupHandlers.HandleRequestVerification)))+ mux.Handle("/trial-signup/verify", trialSignupVerifyLimiter.Middleware(http.HandlerFunc(trialSignupHandlers.HandleVerifyEmail)))+ mux.Handle("/api/trial-signup/checkout", trialSignupCheckoutLimiter.Middleware(http.HandlerFunc(trialSignupHandlers.HandleCheckout)))mux.Handle("/trial-signup/complete", trialSignupCompleteLimiter.Middleware(http.HandlerFunc(trialSignupHandlers.HandleTrialSignupComplete)))mux.Handle("/api/trial-signup/redeem", trialSignupRedeemLimiter.Middleware(http.HandlerFunc(trialSignupHandlers.HandleTrialSignupRedeem)))mux.Handle("/api/entitlements/refresh", hostedEntitlementRefreshLimiter.Middleware(http.HandlerFunc(hostedEntitlementHandlers.HandleRefresh)))@@ -223,17 +222,18 @@ func RegisterRoutes(mux *http.ServeMux, deps *Deps) {mux.Handle("/api/accounts/{account_id}/tenants/{tenant_id}/handoff", accountAPILimiter.Middleware(accountSessionAuth(accountIDFromPath, handoffHandler)))// MSP portal API (session + account-membership authenticated)- mux.Handle("/api/portal/dashboard", portalAPILimiter.Middleware(accountSessionAuth(accountIDFromPortalRequest, portal.HandlePortalDashboard(deps.Registry))))- mux.Handle("/api/portal/workspaces/{tenant_id}", portalAPILimiter.Middleware(accountSessionAuth(accountIDFromPortalRequest, portal.HandlePortalWorkspaceDetail(deps.Registry))))+ mux.Handle(portal.PortalBootstrapPath, portalAPILimiter.Middleware(sessionAuth(portal.HandlePortalBootstrap(deps.MagicLinks, deps.Registry))))+ mux.Handle(portal.PortalDashboardPath, portalAPILimiter.Middleware(accountSessionAuth(accountIDFromPortalRequest, portal.HandlePortalDashboard(deps.Registry))))+ mux.Handle(portal.PortalWorkspacePath, portalAPILimiter.Middleware(accountSessionAuth(accountIDFromPortalRequest, portal.HandlePortalWorkspaceDetail(deps.Registry))))// Stripe Customer Portal redirect (session + account-membership authenticated)billingCfg := portal.BillingPortalConfig{StripeAPIKey: deps.Config.StripeAPIKey,- ReturnURL: buildCPURL(deps.Config.BaseURL, "/portal", nil),+ ReturnURL: buildCPURL(deps.Config.BaseURL, portal.PortalPagePath, nil),}- mux.Handle("/api/portal/billing", portalAPILimiter.Middleware(accountSessionAuth(accountIDFromPortalRequest, portal.HandleBillingPortalRedirect(deps.Registry, billingCfg))))+ mux.Handle(portal.PortalBillingPath, portalAPILimiter.Middleware(accountSessionAuth(accountIDFromPortalRequest, portal.HandleBillingPortalRedirect(deps.Registry, billingCfg))))// MSP/Cloud portal HTML page — self-authenticating (shows login form if no session)portalPageLimiter := NewCPRateLimiter(60, time.Minute)- mux.Handle("/portal", portalPageLimiter.Middleware(http.HandlerFunc(portal.HandlePortalPage(deps.MagicLinks, deps.Registry))))+ mux.Handle(portal.PortalPagePath, portalPageLimiter.Middleware(http.HandlerFunc(portal.HandlePortalPage(deps.MagicLinks, deps.Registry))))}diff --git a/internal/cloudcp/routes_auth_test.go b/internal/cloudcp/routes_auth_test.goindex 6679de803d..89f0f3b3f4 100644--- a/internal/cloudcp/routes_auth_test.go+++ b/internal/cloudcp/routes_auth_test.go@@ -3,9 +3,11 @@ package cloudcpimport ("net/http""net/http/httptest"+ "strings""testing"cpauth "github.com/rcourtman/pulse-go-rewrite/internal/cloudcp/auth"+ "github.com/rcourtman/pulse-go-rewrite/internal/cloudcp/portal""github.com/rcourtman/pulse-go-rewrite/internal/cloudcp/registry")@@ -225,7 +227,7 @@ func TestRegisterRoutes_LogoutRevokesSession(t *testing.T) {Version: "test",})- logoutReq := httptest.NewRequest(http.MethodPost, "/auth/logout", nil)+ logoutReq := httptest.NewRequest(http.MethodPost, portal.PortalLogoutPath, nil)logoutReq.Header.Set("Authorization", "Bearer "+token)logoutRec := httptest.NewRecorder()mux.ServeHTTP(logoutRec, logoutReq)@@ -241,3 +243,99 @@ func TestRegisterRoutes_LogoutRevokesSession(t *testing.T) {t.Fatalf("post-logout status = %d, want %d (body=%q)", afterRec.Code, http.StatusUnauthorized, afterRec.Body.String())}}++func TestRegisterRoutes_PortalBootstrapRequiresSession(t *testing.T) {+ dir := t.TempDir()+ reg, err := registry.NewTenantRegistry(dir)+ if err != nil {+ t.Fatalf("NewTenantRegistry: %v", err)+ }+ t.Cleanup(func() { _ = reg.Close() })++ accountID, err := registry.GenerateAccountID()+ if err != nil {+ t.Fatalf("GenerateAccountID: %v", err)+ }+ if err := reg.CreateAccount(®istry.Account{+ ID: accountID,+ Kind: registry.AccountKindIndividual,+ DisplayName: "Hosted Account",+ }); err != nil {+ t.Fatalf("CreateAccount: %v", err)+ }++ userID, err := registry.GenerateUserID()+ if err != nil {+ t.Fatalf("GenerateUserID: %v", err)+ }+ if err := reg.CreateUser(®istry.User{+ ID: userID,+ Email: "[email protected]",+ }); err != nil {+ t.Fatalf("CreateUser: %v", err)+ }+ if err := reg.CreateMembership(®istry.AccountMembership{+ AccountID: accountID,+ UserID: userID,+ Role: registry.MemberRoleOwner,+ }); err != nil {+ t.Fatalf("CreateMembership: %v", err)+ }++ magicSvc, err := cpauth.NewService(dir)+ if err != nil {+ t.Fatalf("NewService: %v", err)+ }+ t.Cleanup(magicSvc.Close)++ token, err := magicSvc.GenerateSessionToken(userID, "[email protected]", cpauth.SessionTTL)+ if err != nil {+ t.Fatalf("GenerateSessionToken: %v", err)+ }++ mux := http.NewServeMux()+ RegisterRoutes(mux, &Deps{+ Config: &CPConfig{+ DataDir: dir,+ AdminKey: "test-admin-key",+ BaseURL: "https://cloud.example.com",+ StripeWebhookSecret: "whsec_test",+ },+ Registry: reg,+ MagicLinks: magicSvc,+ Version: "test",+ })++ unauthReq := httptest.NewRequest(http.MethodGet, portal.PortalBootstrapPath, nil)+ unauthRec := httptest.NewRecorder()+ mux.ServeHTTP(unauthRec, unauthReq)+ if unauthRec.Code != http.StatusUnauthorized {+ t.Fatalf("unauth status = %d, want %d (body=%q)", unauthRec.Code, http.StatusUnauthorized, unauthRec.Body.String())+ }++ authReq := httptest.NewRequest(http.MethodGet, portal.PortalBootstrapPath, nil)+ authReq.Header.Set("Authorization", "Bearer "+token)+ authRec := httptest.NewRecorder()+ mux.ServeHTTP(authRec, authReq)+ if authRec.Code != http.StatusOK {+ t.Fatalf("auth status = %d, want %d (body=%q)", authRec.Code, http.StatusOK, authRec.Body.String())+ }+ if !strings.Contains(authRec.Body.String(), "\"email\":\"[email protected]\"") {+ t.Fatalf("expected bootstrap payload to include owner email, body=%q", authRec.Body.String())+ }+ if !strings.Contains(authRec.Body.String(), "\"id\":\""+accountID+"\"") {+ t.Fatalf("expected bootstrap payload to include account id, body=%q", authRec.Body.String())+ }++ if _, err := reg.RevokeUserSessions(userID); err != nil {+ t.Fatalf("RevokeUserSessions: %v", err)+ }++ revokedReq := httptest.NewRequest(http.MethodGet, portal.PortalBootstrapPath, nil)+ revokedReq.Header.Set("Authorization", "Bearer "+token)+ revokedRec := httptest.NewRecorder()+ mux.ServeHTTP(revokedRec, revokedReq)+ if revokedRec.Code != http.StatusUnauthorized {+ t.Fatalf("revoked status = %d, want %d (body=%q)", revokedRec.Code, http.StatusUnauthorized, revokedRec.Body.String())+ }+}