Files
tenant-registry/internal/legal/contractdocs/contractdocs.go
Sharang ParnerkarandClaude Opus 5.5 116bb83ddf
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 7m45s
ci / image (pull_request) Skipped
feat(contractdocs): release the AVV 1.0.0 master
The owner released the AVV on 19.11.2026: Arbeitsstand 06, without a signature block (it is concluded with the main contract, § 12(1)), Stand 17.11.2026. The PDF is byte for byte the one in its release record FREIGABE_1.0.0.json (sha256 623aa518…). It is listed between AGB and TOM for every workspace; a workspace's own filled AVV still takes its place. The AVV contract status stays "not_concluded": listing the master concludes nothing.

Tests: released set and order, the master in the overview and as PDF, and the own-AVV-without-master path now on a catalogue without the master.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 10:02:11 +01:00

218 lines
9.4 KiB
Go

// Package contractdocs holds the released contract documents a workspace sees
// in its Vertragsunterlagen: AGB, AVV (the master, with blank lines for the
// customer's details), TOM and the Leistungsbeschreibungen. Each is a fixed
// PDF committed under files/ with its SHA-256 pinned in the table below; the
// pins are checked at startup and by a test, and a PDF is only ever served
// byte for byte. Never replace the PDF of a released version: a new text is a
// new version, i.e. a new PDF and its line in the table.
//
// Releasing a document is one line in released plus its PDF in files/. A
// document not released yet is simply not in the table, and the overview
// does not list it.
package contractdocs
import (
"crypto/sha256"
"embed"
"encoding/hex"
"fmt"
"regexp"
)
//go:embed files/*.pdf
var files embed.FS
// Kinds of contract documents.
const (
KindAGB = "agb" // Allgemeine Geschäftsbedingungen
KindAVV = "avv" // Auftragsverarbeitungsvertrag
KindTOM = "tom" // Technische und organisatorische Maßnahmen
KindLB = "lb" // Leistungsbeschreibung (one per module)
)
// Doc is one released contract document.
type Doc struct {
// ID names the document across versions ("agb", "lb-pruefwerk"); it is
// the path segment of the PDF route. AGB, AVV and TOM have their kind as
// ID, so a workspace's own filled AVV takes the master's place.
ID string
Kind string
Title string
Version string // "1.0.3"
Date string // the "Stand" printed in the document, DD.MM.YYYY
SHA256 string // pinned digest of the PDF
// Which workspaces a Leistungsbeschreibung applies to: Product (a product
// key) when the workspace holds that product, ManagedService (a managed
// service kind) when it has that service, neither: every workspace.
Product string
ManagedService string
File string // file name under files/
PDF []byte
}
// released is the table of released documents, in the order the overview
// lists them. Title is the title shown in the portal (the Plattform LB's PDF
// is headed "Leistungsbeschreibung Breakpilot"). AGB and TOM were released by
// the owner on 16.11.2026 (AGB SaaS AS06 and TOM AS08), the AVV on 19.11.2026
// (AS06: no signature block, it is concluded with the main contract), each
// byte for byte as in its release record FREIGABE_1.0.0.json. The AVV is the
// master with blank lines for the customer's details; a workspace's own filled
// AVV takes its place in that workspace's overview.
var released = []Doc{
{ID: "agb", Kind: KindAGB, Title: "Allgemeine Geschäftsbedingungen", Version: "1.0.0", Date: "09.11.2026",
File: "Breakpilot_AGB_SaaS_1.0.0.pdf", SHA256: "7014a6fb5d0386f07df6a50162af3eea68196e1f585ea6c80414f018f03bc40e"},
{ID: "avv", Kind: KindAVV, Title: "Auftragsverarbeitungsvertrag", Version: "1.0.0", Date: "17.11.2026",
File: "Breakpilot_AVV_1.0.0.pdf", SHA256: "623aa518fdaaa3c8a7e5aa2f15a97ac3b853c8d49d83e41f371b8cf2370a4040"},
{ID: "tom", Kind: KindTOM, Title: "Technische und organisatorische Maßnahmen", Version: "1.0.0", Date: "09.11.2026",
File: "Breakpilot_TOM_1.0.0.pdf", SHA256: "71eb02c884329facf16b8f98e247d579fe17c072e6736b6397d3bfa0952516b9"},
{ID: "lb-plattform", Kind: KindLB, Title: "Leistungsbeschreibung Breakpilot Plattform", Version: "1.0.0", Date: "06.11.2026",
File: "Breakpilot_Leistungsbeschreibung_Plattform_1.0.0.pdf", SHA256: "29205b6b8db23f6e0c213e0f2f6b28b13aaf36656c991789b43dd0610079c65b"},
{ID: "lb-pruefwerk", Kind: KindLB, Title: "Leistungsbeschreibung Prüfwerk", Version: "1.0.3", Date: "09.11.2026", Product: "pruefwerk",
File: "Breakpilot_Leistungsbeschreibung_Pruefwerk_1.0.3.pdf", SHA256: "59672ea23c17621fac767cef27250d0b14b18a2d881da19408d03287628e6731"},
{ID: "lb-werkpilot", Kind: KindLB, Title: "Leistungsbeschreibung Werkpilot", Version: "1.0.0", Date: "06.11.2026", Product: "werkpilot",
File: "Breakpilot_Leistungsbeschreibung_Werkpilot_1.0.0.pdf", SHA256: "b57197b60c7fdb15d2ea234cbd522941ae8ed6c4f581be2ae34055380f97aee3"},
{ID: "lb-firmwerk", Kind: KindLB, Title: "Leistungsbeschreibung Firmwerk", Version: "1.0.0", Date: "06.11.2026", Product: "firmwerk",
File: "Breakpilot_Leistungsbeschreibung_Firmwerk_1.0.0.pdf", SHA256: "7b7e70a426283c75a277ca7983ade0463267c17f99088100ef0cad642df56e0c"},
{ID: "lb-werkmeister", Kind: KindLB, Title: "Leistungsbeschreibung Werkmeister", Version: "1.0.0", Date: "06.11.2026", Product: "werkmeister",
File: "Breakpilot_Leistungsbeschreibung_Werkmeister_1.0.0.pdf", SHA256: "284b9b00f9649d39a1960e056b9dcbccf48ed2fcfb1f84fba052d8cba3ade1a0"},
{ID: "lb-managed-git", Kind: KindLB, Title: "Leistungsbeschreibung Managed Git", Version: "1.0.0", Date: "06.11.2026", ManagedService: "git",
File: "Breakpilot_Leistungsbeschreibung_ManagedGit_1.0.0.pdf", SHA256: "d529c510577371d0223a8466434dd89aafbc07335803a6a91cac43223b569c92"},
{ID: "lb-build-runner", Kind: KindLB, Title: "Leistungsbeschreibung Build-Runner", Version: "1.0.0", Date: "06.11.2026", ManagedService: "ci-runner",
File: "Breakpilot_Leistungsbeschreibung_BuildRunner_1.0.0.pdf", SHA256: "b71909f2177fc2aeb2542f9fad7b3f1ec59d4df8c621a6e4bf66667f9a735638"},
}
// titles are the document titles per kind; a workspace's own filled AVV
// carries the AVV title whether or not the master is released.
var titles = map[string]string{
KindAGB: "Allgemeine Geschäftsbedingungen",
KindAVV: "Auftragsverarbeitungsvertrag",
KindTOM: "Technische und organisatorische Maßnahmen",
KindLB: "Leistungsbeschreibung",
}
// Title is the title of a kind of document ("" for an unknown kind).
func Title(kind string) string { return titles[kind] }
// Catalogue is a set of released documents.
type Catalogue struct {
docs []*Doc
byID map[string]*Doc
}
var def = mustDefault()
func mustDefault() *Catalogue {
docs := make([]Doc, len(released))
for i, d := range released {
b, err := files.ReadFile("files/" + d.File)
if err != nil {
panic(fmt.Sprintf("contractdocs: %s: %v", d.ID, err))
}
d.PDF = b
docs[i] = d
}
return NewCatalogue(docs...)
}
// Default is the catalogue of committed documents.
func Default() *Catalogue { return def }
// NewCatalogue builds a catalogue of docs (with their PDFs), in that order.
// It does not check them; Check does.
func NewCatalogue(docs ...Doc) *Catalogue {
c := &Catalogue{byID: map[string]*Doc{}}
for i := range docs {
d := docs[i]
c.docs = append(c.docs, &d)
c.byID[d.ID] = &d
}
return c
}
// All returns every document in table order.
func (c *Catalogue) All() []*Doc { return c.docs }
// Get returns the document with that ID, or nil.
func (c *Catalogue) Get(id string) *Doc { return c.byID[id] }
// Holdings is what a workspace has that decides which Leistungsbeschreibungen
// apply: product keys and managed service kinds.
type Holdings struct {
Products map[string]bool
ManagedServices map[string]bool
}
// Applies reports whether d applies to a workspace with holdings h. AGB, AVV
// and TOM apply to every workspace, and so does a Leistungsbeschreibung bound
// to neither a product nor a managed service (the platform's).
func (d *Doc) Applies(h Holdings) bool {
switch {
case d.Product != "":
return h.Products[d.Product]
case d.ManagedService != "":
return h.ManagedServices[d.ManagedService]
}
return true
}
// For returns the documents that apply to a workspace with holdings h.
func (c *Catalogue) For(h Holdings) []*Doc {
out := make([]*Doc, 0, len(c.docs))
for _, d := range c.docs {
if d.Applies(h) {
out = append(out, d)
}
}
return out
}
var (
versionRe = regexp.MustCompile(`^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$`)
dateRe = regexp.MustCompile(`^(0[1-9]|[12][0-9]|3[01])\.(0[1-9]|1[0-2])\.20[0-9]{2}$`)
idRe = regexp.MustCompile(`^[a-z][a-z0-9-]{1,39}$`)
)
// ValidVersion reports whether v is a document version ("1.0.0").
func ValidVersion(v string) bool { return versionRe.MatchString(v) }
// Check verifies every document: its PDF matches the pinned SHA-256 and is a
// PDF, and its table entry is well-formed (unique ID, known kind, version,
// Stand, at most one condition).
func (c *Catalogue) Check() error {
seen := map[string]bool{}
for _, d := range c.docs {
switch {
case !idRe.MatchString(d.ID) || seen[d.ID]:
return fmt.Errorf("contractdocs: id %q is malformed or used twice", d.ID)
case titles[d.Kind] == "":
return fmt.Errorf("contractdocs %s: unknown kind %q", d.ID, d.Kind)
case d.Kind != KindLB && d.ID != d.Kind:
return fmt.Errorf("contractdocs %s: the %s is listed under the id %q", d.ID, d.Kind, d.Kind)
case d.Kind != KindLB && (d.Product != "" || d.ManagedService != ""):
return fmt.Errorf("contractdocs %s: only a Leistungsbeschreibung is bound to a product or service", d.ID)
case d.Product != "" && d.ManagedService != "":
return fmt.Errorf("contractdocs %s: bound to both a product and a managed service", d.ID)
case !ValidVersion(d.Version):
return fmt.Errorf("contractdocs %s: version %q", d.ID, d.Version)
case !dateRe.MatchString(d.Date):
return fmt.Errorf("contractdocs %s: date %q is not DD.MM.YYYY", d.ID, d.Date)
case len(d.PDF) < 5 || string(d.PDF[:5]) != "%PDF-":
return fmt.Errorf("contractdocs %s: not a PDF", d.ID)
}
if got := Sum(d.PDF); got != d.SHA256 {
return fmt.Errorf("contractdocs %s %s: pdf sha256 %s, pinned %s", d.ID, d.Version, got, d.SHA256)
}
seen[d.ID] = true
}
return nil
}
// Check verifies the committed documents (see Catalogue.Check).
func Check() error { return def.Check() }
// Sum is the hex SHA-256 of b.
func Sum(b []byte) string {
h := sha256.Sum256(b)
return hex.EncodeToString(h[:])
}