diff --git a/internal/erpmock/server.go b/internal/erpmock/server.go
index e28b2ff..e415a14 100644
--- a/internal/erpmock/server.go
+++ b/internal/erpmock/server.go
@@ -70,7 +70,7 @@ type Server struct {
// DefaultSKUs mirrors the Phase-1 SKU sheet (ERP/02).
var DefaultSKUs = []string{
"PLT-CORE-CLD-STD", "PLT-CORE-CLD-BUS", "PLT-CORE-CLD-ENT", "PLT-BNDL-CLD-STD", "PLT-BNDL-CLD-ADD",
- "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-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",
"CRA-WBK-CLD-STD", "CRA-WBK-CLD-BUS", "CRA-WBK-CLD-ENT",
"DEV-WP-CLD-STD", "DEV-WP-CLD-BUS", "DEV-WP-CLD-ENT", "DEV-WP-OPR-STD", "DEV-WP-OPR-BUS", "DEV-WP-OPR-ENT",
"DEV-FWK-CLD-STD", "DEV-FWK-CLD-BUS", "DEV-FWK-CLD-ENT", "DEV-FWK-OPR-STD", "DEV-FWK-OPR-BUS", "DEV-FWK-OPR-ENT",
diff --git a/internal/erpsetup/branding.go b/internal/erpsetup/branding.go
index bd20ffd..c3b7d71 100644
--- a/internal/erpsetup/branding.go
+++ b/internal/erpsetup/branding.go
@@ -303,11 +303,11 @@ var documentHTML = brand.Replace(`{%- set is_inv = doc.doctype == "Sales Invoice
| {% if interval == "monatlich" %}Monatliche Vergütung{% else %}Vergütung{% endif %} | {{ doc.get_formatted("net_total") }} netto zzgl. gesetzlicher Umsatzsteuer.{% if total_discount > 0.005 %} Der darin enthaltene monatliche Nachlass von {{ frappe.utils.fmt_money(total_discount, currency=doc.currency) }} gilt dauerhaft, einschließlich etwaiger Verlängerungen.{% endif %} |
{#- Mehrverbrauch: for Prüfwerk the extra Prüfobjekte (CRA-CSA-CLD-TGT) and
Prüftage (CRA-CSA-CLD-DAY) at the rates on the quote's price list, except
- on an Enterprise quote (no limits); for Managed Git and the Starter bundle
+ on an Enterprise quote (no limits) and a Monitor-only one (neither); for Managed Git and the Starter bundle
the users beyond the included ones. A missing rate reads "gemäß der
jeweils gültigen Preisliste". -#}
{%- set item_codes = " " ~ ((doc.items or []) | map(attribute="item_code") | join(" ")) ~ " " -%}
-{%- set pw_overage = " CRA-CSA-" in item_codes and " CRA-CSA-CLD-ENT " not in item_codes -%}
+{%- set pw_overage = " CRA-CSA-" in item_codes and " CRA-CSA-CLD-ENT " not in item_codes and (" CRA-CSA-CLD-MON " not in item_codes or " CRA-CSA-CLD-STD " in item_codes or " CRA-CSA-CLD-BUS " in item_codes) -%}
{%- set more_users = " INF-GIT-CLD-STD " in item_codes or " INF-GIT-CLD-BUS " in item_codes or " INF-GIT-CLD-ENT " in item_codes or " PLT-BNDL-" in item_codes -%}
{%- if pw_overage or more_users %}
{%- set price_list = doc.selling_price_list or "Standard Selling" %}
diff --git a/internal/erpsetup/catalog.go b/internal/erpsetup/catalog.go
index 55c3b55..95ed83d 100644
--- a/internal/erpsetup/catalog.go
+++ b/internal/erpsetup/catalog.go
@@ -81,6 +81,7 @@ func skus() []sku {
{Code: "CRA-CSA-CLD-STD", Name: "Prüfwerk Cloud – Standard", UOM: "Monat", Description: "Automatisierte Sicherheitsanalyse von Quellcode, Firmware und SPS-Programmen mit SBOM und Codegraph: 5 enthaltene Prüfobjekte mit unbegrenzten Prüfungen nach Änderungen, dazu 100 weitere Prüfungen im Monat.", Price: 490},
{Code: "CRA-CSA-CLD-BUS", Name: "Prüfwerk Cloud – Business", UOM: "Monat", Description: "Prüfwerk mit 25 enthaltenen Prüfobjekten und 500 weiteren Prüfungen im Monat.", Price: 1290},
{Code: "CRA-CSA-CLD-ENT", Name: "Prüfwerk Cloud – Enterprise", UOM: "Monat", Description: "Prüfwerk ohne Begrenzung der Prüfobjekte und Prüfungen. Preis nach Vereinbarung.", Price: 0},
+ {Code: "CRA-CSA-CLD-MON", Name: "Prüfwerk Cloud – Monitor", UOM: "Monat", Description: "Überwachung eines Produkts auf neue Schwachstellen: 1 enthaltenes Prüfobjekt, täglicher Abgleich mit bekannten Schwachstellen und 10 Prüfungen im Monat. Keine zusätzlichen Prüfobjekte und keine Prüftage.", Price: 149},
{Code: "CRA-CSA-CLD-TGT", Name: "Prüfwerk – Zusätzliches Prüfobjekt", UOM: "Monat", Description: "Prüfobjekt über die im Leistungspaket enthaltenen hinaus; seine Prüfungen zählen zum Monatskontingent. Berechnet wird die höchste Zahl gleichzeitig angelegter zusätzlicher Prüfobjekte im Monat.", Price: 5.99},
{Code: "CRA-CSA-CLD-DAY", Name: "Prüfwerk – Prüftag", UOM: "Prüftag", Description: "Nach verbrauchtem Monatskontingent: bis zu 6 weitere Prüfungen eines Prüfobjekts am selben Kalendertag.", Price: 9.99},
// Replaced by CRA-CSA-CLD-TGT and -DAY.
diff --git a/internal/erpsetup/erpsetup_test.go b/internal/erpsetup/erpsetup_test.go
index 23f9365..f6baf89 100644
--- a/internal/erpsetup/erpsetup_test.go
+++ b/internal/erpsetup/erpsetup_test.go
@@ -306,7 +306,7 @@ func TestWebhookDocIsNamed(t *testing.T) {
// exists too, and the platform fee, Managed Git and its build runners are there for invoicing.
func TestCatalogueCoversTheRegistrySKUs(t *testing.T) {
want := []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-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",
"CRA-WBK-CLD-STD", "CRA-WBK-CLD-BUS", "CRA-WBK-CLD-ENT",
"DEV-WP-CLD-STD", "DEV-WP-CLD-BUS", "DEV-WP-CLD-ENT", "DEV-WP-OPR-STD", "DEV-WP-OPR-BUS", "DEV-WP-OPR-ENT",
"DEV-FWK-CLD-STD", "DEV-FWK-CLD-BUS", "DEV-FWK-CLD-ENT", "DEV-FWK-OPR-STD", "DEV-FWK-OPR-BUS", "DEV-FWK-OPR-ENT",
@@ -689,7 +689,7 @@ func TestQuoteOverageRow(t *testing.T) {
`"item_code": "CRA-CSA-CLD-TGT"`, `"item_code": "CRA-CSA-CLD-DAY"`,
"Zusätzliche Prüfobjekte werden ", " netto je Monat", "Prüftage nach verbrauchtem Monatskontingent ",
"gemäß der jeweils gültigen Preisliste", "(Leistungsbeschreibung Prüfwerk, Abschnitt 7).",
- `" INF-GIT-CLD-STD " in item_codes`, `" PLT-BNDL-" in item_codes`, `" CRA-CSA-CLD-ENT " not in item_codes`,
+ `" INF-GIT-CLD-STD " in item_codes`, `" PLT-BNDL-" in item_codes`, `" CRA-CSA-CLD-ENT " not in item_codes`, `" CRA-CSA-CLD-MON " not in item_codes`,
"Weitere Nutzer über die enthaltenen Nutzer hinaus werden je Modul nach Preisliste berechnet (Leistungsbeschreibung Breakpilot Plattform, Abschnitt 4).",
} {
if !strings.Contains(documentHTML, want) {
diff --git a/internal/server/monitor_test.go b/internal/server/monitor_test.go
new file mode 100644
index 0000000..bed365f
--- /dev/null
+++ b/internal/server/monitor_test.go
@@ -0,0 +1,91 @@
+package server
+
+import (
+ "context"
+ "testing"
+ "time"
+
+ "git.breakpilot.com/platform/tenant-registry/internal/store"
+)
+
+func TestPruefwerkLimitsMonitor(t *testing.T) {
+ seven := 7
+ // A saved cap and stray keys in the config change nothing.
+ got := pruefwerkLimits(map[string]interface{}{"skus": []string{"CRA-CSA-CLD-MON"}, "included_targets": 5}, &seven)
+ if got[limitIncludedTargets] != 1 || got[limitMonthlyPruefungen] != 10 || got[limitPrueftagCap] != 0 || got[limitExtraTargets] != 0 {
+ t.Errorf("monitor limits: %v", got)
+ }
+ if pruefwerkMonitorPlan.capApplies() {
+ t.Error("the saved cap applies on Monitor")
+ }
+ // The no-SKU default is still Standard, with extras billed.
+ for _, cfg := range []map[string]interface{}{{}, {"skus": []string{}}, {"source": "trial"}} {
+ got := pruefwerkLimits(cfg, nil)
+ if _, extra := got[limitExtraTargets]; got[limitIncludedTargets] != 5 || got[limitMonthlyPruefungen] != 100 || extra {
+ t.Errorf("default %v: %v", cfg, got)
+ }
+ }
+}
+
+// A Monitor order from the ERP grants the Monitor plan; Standard on top of it
+// wins; an entry grant is taken over by it.
+func TestMonitorFromERP(t *testing.T) {
+ f := newTeamFixture(t, portal, "portal-svc:*")
+ ctx := context.Background()
+ limitsOf := func(id string) map[string]interface{} {
+ t.Helper()
+ tps, err := f.s.Store.ListTenantProducts(ctx, id)
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, tp := range tps {
+ if tp.Product == pruefwerkProduct {
+ if !tp.Enabled || tp.Config["source"] != "erp" || tp.ExpiresAt != nil {
+ t.Fatalf("grant: %+v", tp)
+ }
+ return pruefwerkLimits(tp.Config, nil)
+ }
+ }
+ t.Fatal("no Prüfwerk grant")
+ return nil
+ }
+ book := func(tenant *store.Tenant, sku, so string) {
+ t.Helper()
+ if f.s.productForSKU(ctx, sku) == nil {
+ t.Fatalf("%s maps to no product", sku)
+ }
+ if _, err := f.s.Store.UpsertSubscription(ctx, store.Subscription{TenantID: tenant.ID, Product: pruefwerkProduct, SKU: sku,
+ Plan: planForSKU(sku), Seats: 1, Status: store.SubscriptionActive, ErpSalesOrder: so}); err != nil {
+ t.Fatal(err)
+ }
+ cur, _ := f.s.Store.GetTenant(ctx, tenant.ID)
+ if _, err := f.s.recomputeEntitlements(ctx, nil, cur, "test"); err != nil {
+ t.Fatal(err)
+ }
+ }
+
+ buyer, _ := f.s.Store.CreateTenant(ctx, store.TenantCreate{Slug: "k-00095", Name: "K-00095"})
+ book(buyer, monitorPlanSKU, "SO-M1")
+ if l := limitsOf(buyer.ID); l[limitIncludedTargets] != 1 || l[limitMonthlyPruefungen] != 10 || l[limitPrueftagCap] != 0 || l[limitExtraTargets] != 0 {
+ t.Fatalf("monitor from the ERP: %v", l)
+ }
+ book(buyer, "CRA-CSA-CLD-STD", "SO-M2")
+ if l := limitsOf(buyer.ID); l[limitIncludedTargets] != 5 || l[limitMonthlyPruefungen] != 100 {
+ t.Fatalf("standard on top of monitor: %v", l)
+ }
+ if _, extra := limitsOf(buyer.ID)[limitExtraTargets]; extra {
+ t.Fatal("standard on top of monitor refuses extras")
+ }
+
+ // Entry grant with three targets, then Monitor: the order's targets go.
+ staff := map[string]string{"X-Staff-Subject": "staff-1", "X-Staff-Email": "staff@breakpilot.test"}
+ upsell, _ := f.s.Store.CreateTenant(ctx, store.TenantCreate{Slug: "k-00094", Name: "K-00094"})
+ month := time.Now().Add(30 * 24 * time.Hour).UTC().Format(time.RFC3339)
+ if code, _, raw := f.call(t, "POST", "/v1/admin/tenants/"+upsell.ID+"/entry-offer", `{"included_targets":3,"expires_at":"`+month+`"}`, staff); code != 200 {
+ t.Fatalf("entry grant: %d %s", code, raw)
+ }
+ book(upsell, monitorPlanSKU, "SO-M3")
+ if l := limitsOf(upsell.ID); l[limitIncludedTargets] != 1 || l[limitMonthlyPruefungen] != 10 || l[limitExtraTargets] != 0 || l[entryOrderRefKey] != nil {
+ t.Fatalf("monitor after the entry plan: %v", l)
+ }
+}
diff --git a/internal/server/pruefwerk.go b/internal/server/pruefwerk.go
index e5b676e..3971a6b 100644
--- a/internal/server/pruefwerk.go
+++ b/internal/server/pruefwerk.go
@@ -63,17 +63,32 @@ type pruefwerkPlan struct {
}
// capApplies reports whether the workspace's saved Prüftag cap is the one
-// sent: not on Enterprise (no cap) and not on the entry plan (always 0).
+// sent: not on Enterprise (no cap) and not on Monitor or the entry plan
+// (always 0).
func (p pruefwerkPlan) capApplies() bool { return !p.Unlimited && !p.NoPrueftage }
// pruefwerkPlans, lowest first: a tenant holding several plan SKUs gets the
-// highest, one without any (trial, preview grant, SCAN-only order) the first.
+// highest, one without any (trial, preview grant, SCAN-only order) Standard.
+// Monitor and the entry plan sit below them and outside this list, so that
+// no-SKU default stays Standard.
var pruefwerkPlans = []pruefwerkPlan{
{Name: "standard", SKU: "CRA-CSA-CLD-STD", IncludedTargets: 5, MonthlyPruefungen: 100},
{Name: "business", SKU: "CRA-CSA-CLD-BUS", IncludedTargets: 25, MonthlyPruefungen: 500},
{Name: "enterprise", SKU: "CRA-CSA-CLD-ENT", Unlimited: true},
}
+// Monitor (CRA-CSA-CLD-MON, €149 per product per month, paid through
+// Stripe and booked in ERPNext as a subscription): one product watched for
+// new vulnerabilities. One included target, no extra targets, no Prüftage
+// and 10 counted Prüfungen a month (an updated bill of materials, say); the
+// daily re-match of known vulnerabilities runs on every plan. A Monitor
+// order arrives from the ERP like any subscription; any of Standard,
+// Business or Enterprise wins over it, and it wins over the entry plan.
+const monitorPlanSKU = "CRA-CSA-CLD-MON"
+
+var pruefwerkMonitorPlan = pruefwerkPlan{Name: "monitor", SKU: monitorPlanSKU, IncludedTargets: 1, MonthlyPruefungen: 10,
+ NoPrueftage: true, NoExtraTargets: true}
+
// Entry offers (CRA-Check, SBOM-Erstellung, CVE-Scan; LB Einstiegsangebote):
// one-off orders paid by card or SEPA at booking, delivered by Breakpilot in
// the customer's workspace, which stays open 90 days after delivery. Staff
@@ -100,8 +115,9 @@ var pruefwerkEntryPlan = pruefwerkPlan{Name: "einstieg", SKU: entryPlanSKU, Incl
// pruefwerkPlanFor resolves the plan from tenant_products.config["skus"]:
// []string as recomputeEntitlements writes it, []interface{} once it has
-// been through JSONB. Any subscription plan wins over the entry plan; no
-// plan SKU at all (trial, preview grant, SCAN-only order) is Standard.
+// been through JSONB. Standard, Business and Enterprise win over Monitor,
+// and any subscription plan over the entry plan; no plan SKU at all (trial,
+// preview grant, SCAN-only order) is Standard.
func pruefwerkPlanFor(skus interface{}) pruefwerkPlan {
var list []string
switch v := skus.(type) {
@@ -114,9 +130,12 @@ func pruefwerkPlanFor(skus interface{}) pruefwerkPlan {
}
}
}
- best, entry := -1, false
+ best, monitor, entry := -1, false, false
for _, sku := range list {
- if sku == entryPlanSKU {
+ switch sku {
+ case monitorPlanSKU:
+ monitor = true
+ case entryPlanSKU:
entry = true
}
for i, p := range pruefwerkPlans {
@@ -128,13 +147,16 @@ func pruefwerkPlanFor(skus interface{}) pruefwerkPlan {
switch {
case best >= 0:
return pruefwerkPlans[best]
+ case monitor:
+ return pruefwerkMonitorPlan
case entry:
return pruefwerkEntryPlan
}
return pruefwerkStandard()
}
-// pruefwerkStandard is the plan without any plan SKU.
+// pruefwerkStandard is the plan without any plan SKU (the first of
+// pruefwerkPlans; Monitor and the entry plan are kept out of the list).
func pruefwerkStandard() pruefwerkPlan { return pruefwerkPlans[0] }
// pruefwerkPlanOfConfig is the plan of a stored Prüfwerk entitlement: by
diff --git a/internal/server/pruefwerk_internal_test.go b/internal/server/pruefwerk_internal_test.go
index ea170c8..2884a40 100644
--- a/internal/server/pruefwerk_internal_test.go
+++ b/internal/server/pruefwerk_internal_test.go
@@ -37,6 +37,12 @@ func TestPruefwerkPlanFor(t *testing.T) {
{"entry with scan", []string{"CRA-CSA-CLD-SCAN", "CRA-CSA-CLD-EIN"}, "einstieg"},
{"standard beats entry", []string{"CRA-CSA-CLD-EIN", "CRA-CSA-CLD-STD"}, "standard"},
{"business beats entry", []string{"CRA-CSA-CLD-BUS", "CRA-CSA-CLD-EIN"}, "business"},
+ {"monitor", []string{"CRA-CSA-CLD-MON"}, "monitor"},
+ {"monitor from JSONB", []interface{}{"CRA-CSA-CLD-MON"}, "monitor"},
+ {"monitor with scan", []string{"CRA-CSA-CLD-SCAN", "CRA-CSA-CLD-MON"}, "monitor"},
+ {"standard beats monitor", []string{"CRA-CSA-CLD-MON", "CRA-CSA-CLD-STD"}, "standard"},
+ {"enterprise beats monitor", []string{"CRA-CSA-CLD-ENT", "CRA-CSA-CLD-MON"}, "enterprise"},
+ {"monitor beats entry", []string{"CRA-CSA-CLD-EIN", "CRA-CSA-CLD-MON"}, "monitor"},
} {
if got := pruefwerkPlanFor(c.skus).Name; got != c.want {
t.Errorf("%s: %s, want %s", c.name, got, c.want)
diff --git a/internal/store/products.go b/internal/store/products.go
index fb1b319..031131c 100644
--- a/internal/store/products.go
+++ b/internal/store/products.go
@@ -8,8 +8,8 @@ import (
)
// 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.
+// 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"}
@@ -20,7 +20,7 @@ func DefaultProducts() []Product {
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"},
+ 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,
},
diff --git a/migrations/0034_pruefwerk_monitor_sku.down.sql b/migrations/0034_pruefwerk_monitor_sku.down.sql
new file mode 100644
index 0000000..3a3d3a5
--- /dev/null
+++ b/migrations/0034_pruefwerk_monitor_sku.down.sql
@@ -0,0 +1,3 @@
+UPDATE products
+SET skus = skus - 'CRA-CSA-CLD-MON'
+WHERE key = 'pruefwerk';
diff --git a/migrations/0034_pruefwerk_monitor_sku.up.sql b/migrations/0034_pruefwerk_monitor_sku.up.sql
new file mode 100644
index 0000000..dd302e7
--- /dev/null
+++ b/migrations/0034_pruefwerk_monitor_sku.up.sql
@@ -0,0 +1,5 @@
+-- Prüfwerk Monitor (CRA-CSA-CLD-MON): one product watched for new
+-- vulnerabilities, booked in ERPNext as a subscription.
+UPDATE products
+SET skus = skus || '["CRA-CSA-CLD-MON"]'::jsonb
+WHERE key = 'pruefwerk' AND NOT skus @> '["CRA-CSA-CLD-MON"]'::jsonb;
diff --git a/openapi.yaml b/openapi.yaml
index 30360bb..171c62c 100644
--- a/openapi.yaml
+++ b/openapi.yaml
@@ -2895,10 +2895,11 @@ components:
Business 25/500, Enterprise null; no plan SKU counts as Standard)
and `prueftag_cap` (the workspace's monthly cap on Prüftage,
null when none is set and always null on Enterprise). null means
- unlimited. The entry plan (CRA-CSA-CLD-EIN) also sends
- `extra_targets: 0` (no target beyond the included ones, with
- `monthly_pruefungen` 0 and `prueftag_cap` 0); without the key,
- extra targets are allowed and billed.
+ unlimited. The entry plan (CRA-CSA-CLD-EIN) and Monitor
+ (CRA-CSA-CLD-MON: 1 target, 10 Prüfungen) also send
+ `extra_targets: 0` (no target beyond the included ones) and
+ `prueftag_cap` 0, the entry plan with `monthly_pruefungen` 0;
+ without the key, extra targets are allowed and billed.
expires_at: { type: string, format: date-time, nullable: true }
reason: { type: string, enum: [unknown_product, unknown_addon, tenant_not_found, tenant_archived, tenant_halted, entitlement_disabled, entitlement_expired, preview_expired, addon_not_purchased, not_entitled, member_blocked, user_unknown] }
preview: { type: boolean, description: "allowed through a staff preview grant; usage under it is not invoiced" }