109 lines
4.8 KiB
Go
109 lines
4.8 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, 0026_pruefwerk_tgt_day_skus.up.sql and
|
|
// 0034_pruefwerk_monitor_sku.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", "CRA-CSA-CLD-MON"},
|
|
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
|
|
}
|