Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

feat(cloudcp): add Pulse Account bootstrap contract

rcourtmanbd9603e15da8
diff --git a/internal/cloudcp/portal/assets/portal.js b/internal/cloudcp/portal/assets/portal.js
index f06611e98b..4f9131461e 100644
--- a/internal/cloudcp/portal/assets/portal.js
+++ b/internal/cloudcp/portal/assets/portal.js
@@ -1,5 +1,13 @@
-var portalRoot = document.querySelector('[data-commercial-api-base]');
-var LICENSE_API_BASE = portalRoot ? (portalRoot.getAttribute('data-commercial-api-base') || '') : '';
+var bootstrapEl = document.getElementById('pulse-account-bootstrap');
+var portalBootstrap = {};
+if (bootstrapEl) {
+ try {
+ portalBootstrap = JSON.parse(bootstrapEl.textContent || '{}');
+ } catch (_) {
+ portalBootstrap = {};
+ }
+}
+var LICENSE_API_BASE = portalBootstrap.commercial_api_base_url || '';
function showToast(msg, isError) {
var t = document.getElementById('toast');
diff --git a/internal/cloudcp/portal/handlers_test.go b/internal/cloudcp/portal/handlers_test.go
index 4cfbdb9937..df9dde74f6 100644
--- a/internal/cloudcp/portal/handlers_test.go
+++ b/internal/cloudcp/portal/handlers_test.go
@@ -727,7 +727,10 @@ func TestPortalPageTemplate_AccountServicesRendered(t *testing.T) {
mustContain := []string{
"<title>Pulse Account</title>",
"Pulse Account",
- `data-commercial-api-base="https://license.pulserelay.pro"`,
+ `id="pulse-account-bootstrap"`,
+ `"commercial_api_base_url":"https://license.pulserelay.pro"`,
+ `"email":"[email protected]"`,
+ `"accounts":[{"id":"a_test"`,
"Other account services",
`id="open-manage-service"`,
`id="open-retrieve-service"`,
diff --git a/internal/cloudcp/portal/page.go b/internal/cloudcp/portal/page.go
index 61e02a44ae..9295b5de67 100644
--- a/internal/cloudcp/portal/page.go
+++ b/internal/cloudcp/portal/page.go
@@ -1,6 +1,7 @@
package portal
import (
+ "encoding/json"
"html/template"
"net/http"
"time"
@@ -42,6 +43,7 @@ type portalPageData struct {
Accounts []portalPageAccount
Styles template.CSS
Script template.JS
+ BootstrapJSON template.JS
}
type loginPageData struct {
@@ -50,6 +52,32 @@ type loginPageData struct {
Script template.JS
}
+type portalBootstrapWorkspace struct {
+ ID string `json:"id"`
+ DisplayName string `json:"display_name"`
+ State string `json:"state"`
+ Healthy bool `json:"healthy"`
+}
+
+type portalBootstrapAccount struct {
+ ID string `json:"id"`
+ Kind string `json:"kind"`
+ KindLabel string `json:"kind_label"`
+ Name string `json:"name"`
+ Role string `json:"role"`
+ CanManage bool `json:"can_manage"`
+ HasBilling bool `json:"has_billing"`
+ Workspaces []portalBootstrapWorkspace `json:"workspaces"`
+}
+
+type portalBootstrapData struct {
+ Email string `json:"email"`
+ PublicSiteURL string `json:"public_site_url"`
+ SupportEmail string `json:"support_email"`
+ CommercialAPIBaseURL string `json:"commercial_api_base_url"`
+ Accounts []portalBootstrapAccount `json:"accounts"`
+}
+
const (
defaultPublicSiteURL = "https://pulserelay.pro"
defaultSupportEmail = "[email protected]"
@@ -173,6 +201,11 @@ func HandlePortalPage(sessionSvc *cpauth.Service, reg *registry.TenantRegistry)
func renderPortalPage(w http.ResponseWriter, nonce, email string, accounts []portalPageAccount) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK)
+ bootstrapJSON, err := buildPortalBootstrapJSON(email, accounts)
+ if err != nil {
+ log.Error().Err(err).Msg("cloudcp.portal.page: marshal bootstrap data")
+ bootstrapJSON = template.JS(`{}`)
+ }
if err := portalPageTmpl.Execute(w, portalPageData{
Nonce: nonce,
Email: email,
@@ -182,6 +215,7 @@ func renderPortalPage(w http.ResponseWriter, nonce, email string, accounts []por
Accounts: accounts,
Styles: portalStyles,
Script: portalScript,
+ BootstrapJSON: bootstrapJSON,
}); err != nil {
log.Error().Err(err).Msg("cloudcp.portal.page: render portal page")
}
@@ -198,3 +232,40 @@ func renderLoginPage(w http.ResponseWriter, nonce string) {
log.Error().Err(err).Msg("cloudcp.portal.page: render login page")
}
}
+
+func buildPortalBootstrapJSON(email string, accounts []portalPageAccount) (template.JS, error) {
+ bootstrapAccounts := make([]portalBootstrapAccount, 0, len(accounts))
+ for _, account := range accounts {
+ workspaces := make([]portalBootstrapWorkspace, 0, len(account.Workspaces))
+ for _, workspace := range account.Workspaces {
+ workspaces = append(workspaces, portalBootstrapWorkspace{
+ ID: workspace.ID,
+ DisplayName: workspace.DisplayName,
+ State: workspace.State,
+ Healthy: workspace.Healthy,
+ })
+ }
+ bootstrapAccounts = append(bootstrapAccounts, portalBootstrapAccount{
+ ID: account.ID,
+ Kind: account.Kind,
+ KindLabel: account.KindLabel,
+ Name: account.Name,
+ Role: account.Role,
+ CanManage: account.CanManage,
+ HasBilling: account.HasBilling,
+ Workspaces: workspaces,
+ })
+ }
+
+ payload, err := json.Marshal(portalBootstrapData{
+ Email: email,
+ PublicSiteURL: defaultPublicSiteURL,
+ SupportEmail: defaultSupportEmail,
+ CommercialAPIBaseURL: defaultCommercialAPIBaseURL,
+ Accounts: bootstrapAccounts,
+ })
+ if err != nil {
+ return "", err
+ }
+ return template.JS(payload), nil
+}
diff --git a/internal/cloudcp/portal/templates/portal.html b/internal/cloudcp/portal/templates/portal.html
index 654fd445a4..1acf0069cd 100644
--- a/internal/cloudcp/portal/templates/portal.html
+++ b/internal/cloudcp/portal/templates/portal.html
@@ -14,7 +14,9 @@
</div>
</header>
-<main class="main" data-commercial-api-base="{{.CommercialAPIBaseURL}}">
+<script id="pulse-account-bootstrap" type="application/json">{{.BootstrapJSON}}</script>
+
+<main class="main">
<section class="intro-card">
<h1>Pulse Account</h1>
<p>Manage hosted Cloud and MSP workspaces here today. Self-hosted license and recovery tools still live on the public commercial surface during the current rollout, and are linked below so the account experience does not stay fragmented forever.</p>