Files
tenant-registry/internal/store/products.go
T
Sharang Parnerkar a4fb318773 feat(onprem): APP_ENV=onprem for a customer's own node
The registry on a customer's node must never reach a Breakpilot host and
must not run the cloud's commercial machinery.

- APP_ENV=onprem: no ERP (nothing queued, webhook off), no trial (new
  workspaces start active, the ladder never escalates by time), and the
  trial-offer, trial-terms, catalog/trial request and admin trial routes
  answer 404 not_available.
- PRODUCTS, PRODUCT_LAUNCH_URLS, PRODUCT_PROVISION_URLS: one store
  decorator applies the product list and URLs to every catalog read
  (catalog, activation, provisioning, entitlement checks). On-prem has no
  seeded URLs, so provisioning goes only to the local products. Checked at
  start ({id} in provision URLs, absolute http(s)).
- On-prem start fails when the values leave something to a cloud or dev
  default (auth off, no authz rules, ephemeral licence key, portal, invite,
  sender, LLM gateway) or set an ERP or contract documents.
- SMTP_TLS=starttls|tls|none: a plain relay inside the customer's network;
  no AUTH without encryption.
- Migration 0032: the Werkpilot text no longer names our LLM host.

Cloud behaviour is unchanged without the new variables (tested).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 2f6fa5f3e8)
2026-11-20 17:08:42 +01:00

109 lines
4.7 KiB
Go

package store
import (
"fmt"
"strconv"
"strings"
"time"
)
// DefaultProducts mirrors the seed rows of migrations/0003_products.up.sql,
// 0014_werkmeister_product.up.sql and 0026_pruefwerk_tgt_day_skus.up.sql
// for the Memory store. Keep the two in sync.
func DefaultProducts() []Product {
now := time.Now().UTC()
plans := []string{"standard", "business", "enterprise"}
return []Product{
{
Key: "pruefwerk", Name: "Prüfwerk", Type: "standalone",
Description: "Compliance scanner for CRA / IEC 62443 style assessments: SBOM, DAST, pentest orchestration, PLC provisioning tests.",
LaunchURLs: map[string]string{"stage": "https://pruefwerk-stage.breakpilot.com", "prod": "https://pruefwerk.breakpilot.com"},
ProvisionURLs: map[string]string{},
// SCAN is no longer sold (TGT and DAY replace it) but old orders still map.
SKUs: []string{"CRA-CSA-CLD-STD", "CRA-CSA-CLD-BUS", "CRA-CSA-CLD-ENT", "CRA-CSA-CLD-SCAN", "CRA-CSA-CLD-TGT", "CRA-CSA-CLD-DAY"},
Addons: []ProductAddon{{ID: "werkbank", Name: "Werkbank runner", LimitKey: "runners", SKUs: []string{"CRA-WBK-CLD-STD", "CRA-WBK-CLD-BUS", "CRA-WBK-CLD-ENT"}}},
PlansRequired: plans, SupportsTrial: true, TrialDays: 14, Enabled: true, SortOrder: 10, CreatedAt: now, UpdatedAt: now,
},
{
Key: "werkpilot", Name: "Werkpilot", Type: "cli",
Description: "On-prem AI coding agent for machine and plant manufacturers (CLI). Licensed per named user; talks to the platform's language-model gateway.",
LaunchURLs: map[string]string{"stage": "https://git.breakpilot.com/platform/werkpilot/releases", "prod": "https://git.breakpilot.com/platform/werkpilot/releases"},
ProvisionURLs: map[string]string{},
SKUs: []string{"DEV-WP-CLD-STD", "DEV-WP-CLD-BUS", "DEV-WP-CLD-ENT", "DEV-WP-OPR-STD", "DEV-WP-OPR-BUS", "DEV-WP-OPR-ENT"},
Addons: []ProductAddon{},
PlansRequired: plans, SupportsTrial: true, TrialDays: 14, Enabled: true, SortOrder: 20, CreatedAt: now, UpdatedAt: now,
},
{
Key: "firmwerk", Name: "Firmwerk", Type: "cli",
Description: "Reproducible firmware builds with SBOM / VEX / attestation (CLI + cloud control plane).",
LaunchURLs: map[string]string{"stage": "https://firmwerk-stage.breakpilot.com", "prod": "https://firmwerk.breakpilot.com"},
ProvisionURLs: map[string]string{},
SKUs: []string{"DEV-FWK-CLD-STD", "DEV-FWK-CLD-BUS", "DEV-FWK-CLD-ENT", "DEV-FWK-OPR-STD", "DEV-FWK-OPR-BUS", "DEV-FWK-OPR-ENT"},
Addons: []ProductAddon{},
PlansRequired: plans, SupportsTrial: true, TrialDays: 14, Enabled: true, SortOrder: 30, CreatedAt: now, UpdatedAt: now,
},
{
// Draft, not for sale (platform/werkmeister ADR 0001): no SKUs until pricing.
Key: "werkmeister", Name: "Werkmeister", Type: "standalone",
Description: "Visual workflow builder: blocks for the booked BreakPilot products, composable and versioned.",
LaunchURLs: map[string]string{"stage": "https://werkmeister-stage.breakpilot.com", "prod": "https://werkmeister.breakpilot.com"},
ProvisionURLs: map[string]string{},
SKUs: []string{}, Addons: []ProductAddon{},
PlansRequired: plans, SupportsTrial: true, TrialDays: 14, Enabled: false, SortOrder: 40, CreatedAt: now, UpdatedAt: now,
},
{
Key: "compliance", Name: "Compliance", Type: "standalone",
Description: "DSFA / TOM / VVT generation; evidence capture.",
LaunchURLs: map[string]string{}, ProvisionURLs: map[string]string{},
SKUs: []string{}, Addons: []ProductAddon{},
PlansRequired: plans, SupportsTrial: true, TrialDays: 14, Enabled: false, SortOrder: 90, CreatedAt: now, UpdatedAt: now,
},
}
}
// Catalog projects a Product onto the /v1/catalog shape for one environment.
func (p Product) Catalog(env string) CatalogEntry {
return CatalogEntry{
Key: p.Key, Name: p.Name, Description: p.Description, Type: p.Type,
LaunchURL: p.LaunchURLs[env], SKUs: nonNil(p.SKUs), Addons: p.Addons,
PlansRequired: nonNil(p.PlansRequired), SupportsTrial: p.SupportsTrial, TrialDays: p.TrialDays,
}
}
// HasAddon reports whether the product sells the named add-on.
func (p Product) HasAddon(id string) bool {
for _, a := range p.Addons {
if a.ID == id {
return true
}
}
return false
}
func nonNil(s []string) []string {
if s == nil {
return []string{}
}
return s
}
// tenant list cursor: "<unix-nanos>_<id>" — keyset on (created_at, id).
func encodeTenantCursor(t Tenant) string {
return fmt.Sprintf("%d_%s", t.CreatedAt.UnixNano(), t.ID)
}
func decodeTenantCursor(c string) (time.Time, string, bool) {
if c == "" {
return time.Time{}, "", true
}
i := strings.IndexByte(c, '_')
if i <= 0 {
return time.Time{}, "", false
}
n, err := strconv.ParseInt(c[:i], 10, 64)
if err != nil {
return time.Time{}, "", false
}
return time.Unix(0, n).UTC(), c[i+1:], true
}