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.

refactor(cloudcp): split Pulse Account bootstrap model

rcourtman50b05953bfd2
diff --git a/internal/cloudcp/portal/bootstrap.go b/internal/cloudcp/portal/bootstrap.go
new file mode 100644
index 0000000000..3c096ba421
--- /dev/null
+++ b/internal/cloudcp/portal/bootstrap.go
@@ -0,0 +1,81 @@
+package portal
+
+import (
+ "encoding/json"
+ "html/template"
+)
+
+type BootstrapWorkspace struct {
+ ID string `json:"id"`
+ DisplayName string `json:"display_name"`
+ State string `json:"state"`
+ Healthy bool `json:"healthy"`
+}
+
+type BootstrapAccount 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 []BootstrapWorkspace `json:"workspaces"`
+}
+
+type BootstrapData struct {
+ Email string `json:"email"`
+ PublicSiteURL string `json:"public_site_url"`
+ SupportEmail string `json:"support_email"`
+ CommercialAPIBaseURL string `json:"commercial_api_base_url"`
+ PortalPath string `json:"portal_path"`
+ LogoutPath string `json:"logout_path"`
+ AccountAPIBasePath string `json:"account_api_base_path"`
+ PortalAPIBasePath string `json:"portal_api_base_path"`
+ Accounts []BootstrapAccount `json:"accounts"`
+}
+
+func MarshalBootstrapJSON(email string, accounts []portalPageAccount) (template.JS, error) {
+ payload, err := json.Marshal(BuildBootstrapData(email, accounts))
+ if err != nil {
+ return "", err
+ }
+ return template.JS(payload), nil
+}
+
+func BuildBootstrapData(email string, accounts []portalPageAccount) BootstrapData {
+ bootstrapAccounts := make([]BootstrapAccount, 0, len(accounts))
+ for _, account := range accounts {
+ workspaces := make([]BootstrapWorkspace, 0, len(account.Workspaces))
+ for _, workspace := range account.Workspaces {
+ workspaces = append(workspaces, BootstrapWorkspace{
+ ID: workspace.ID,
+ DisplayName: workspace.DisplayName,
+ State: workspace.State,
+ Healthy: workspace.Healthy,
+ })
+ }
+ bootstrapAccounts = append(bootstrapAccounts, BootstrapAccount{
+ ID: account.ID,
+ Kind: account.Kind,
+ KindLabel: account.KindLabel,
+ Name: account.Name,
+ Role: account.Role,
+ CanManage: account.CanManage,
+ HasBilling: account.HasBilling,
+ Workspaces: workspaces,
+ })
+ }
+
+ return BootstrapData{
+ Email: email,
+ PublicSiteURL: defaultPublicSiteURL,
+ SupportEmail: defaultSupportEmail,
+ CommercialAPIBaseURL: defaultCommercialAPIBaseURL,
+ PortalPath: defaultPortalPath,
+ LogoutPath: defaultLogoutPath,
+ AccountAPIBasePath: defaultAccountAPIBasePath,
+ PortalAPIBasePath: defaultPortalAPIBasePath,
+ Accounts: bootstrapAccounts,
+ }
+}
diff --git a/internal/cloudcp/portal/page.go b/internal/cloudcp/portal/page.go
index 6e8799f6fa..752f8fe11e 100644
--- a/internal/cloudcp/portal/page.go
+++ b/internal/cloudcp/portal/page.go
@@ -1,7 +1,6 @@
package portal
import (
- "encoding/json"
"errors"
"html/template"
"net/http"
@@ -57,36 +56,6 @@ type loginPageData struct {
Script template.JS
}
-type BootstrapWorkspace struct {
- ID string `json:"id"`
- DisplayName string `json:"display_name"`
- State string `json:"state"`
- Healthy bool `json:"healthy"`
-}
-
-type BootstrapAccount 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 []BootstrapWorkspace `json:"workspaces"`
-}
-
-type BootstrapData struct {
- Email string `json:"email"`
- PublicSiteURL string `json:"public_site_url"`
- SupportEmail string `json:"support_email"`
- CommercialAPIBaseURL string `json:"commercial_api_base_url"`
- PortalPath string `json:"portal_path"`
- LogoutPath string `json:"logout_path"`
- AccountAPIBasePath string `json:"account_api_base_path"`
- PortalAPIBasePath string `json:"portal_api_base_path"`
- Accounts []BootstrapAccount `json:"accounts"`
-}
-
const (
defaultPublicSiteURL = "https://pulserelay.pro"
defaultSupportEmail = "[email protected]"
@@ -267,48 +236,3 @@ func renderLoginPage(w http.ResponseWriter, nonce string) {
log.Error().Err(err).Msg("cloudcp.portal.page: render login page")
}
}
-
-func MarshalBootstrapJSON(email string, accounts []portalPageAccount) (template.JS, error) {
- payload, err := json.Marshal(BuildBootstrapData(email, accounts))
- if err != nil {
- return "", err
- }
- return template.JS(payload), nil
-}
-
-func BuildBootstrapData(email string, accounts []portalPageAccount) BootstrapData {
- bootstrapAccounts := make([]BootstrapAccount, 0, len(accounts))
- for _, account := range accounts {
- workspaces := make([]BootstrapWorkspace, 0, len(account.Workspaces))
- for _, workspace := range account.Workspaces {
- workspaces = append(workspaces, BootstrapWorkspace{
- ID: workspace.ID,
- DisplayName: workspace.DisplayName,
- State: workspace.State,
- Healthy: workspace.Healthy,
- })
- }
- bootstrapAccounts = append(bootstrapAccounts, BootstrapAccount{
- ID: account.ID,
- Kind: account.Kind,
- KindLabel: account.KindLabel,
- Name: account.Name,
- Role: account.Role,
- CanManage: account.CanManage,
- HasBilling: account.HasBilling,
- Workspaces: workspaces,
- })
- }
-
- return BootstrapData{
- Email: email,
- PublicSiteURL: defaultPublicSiteURL,
- SupportEmail: defaultSupportEmail,
- CommercialAPIBaseURL: defaultCommercialAPIBaseURL,
- PortalPath: defaultPortalPath,
- LogoutPath: defaultLogoutPath,
- AccountAPIBasePath: defaultAccountAPIBasePath,
- PortalAPIBasePath: defaultPortalAPIBasePath,
- Accounts: bootstrapAccounts,
- }
-}