package view // The view reads the catalog half of the delivery through the seat mesh-catalog (design 47, Two graphs; ADR 0656 §6): // a first view of its verb `revision`, then each trunk revision its event `catalog-revision` says, never the indexer's // state `modules`. The model keeps the picture it always kept (one value per module, its history for the reach), so each // entry of a revision is handed to it in the form of that value. import ( "encoding/json" "fmt" "strings" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" ) // CatalogSeat is the seat whose verb `revision` and event `catalog-revision` the view reads the modules from, as its // manifest's `invokes` and `consumes` name them. const CatalogSeat = meshcatalog.Seat // ModulesBucket names the model's picture of the catalog half's modules (and its history): the model's label, no // bucket of anybody's. const ModulesBucket = CatalogSeat + "_modules" // ModuleValue is the value of one module of the model, as the model decodes it, made from the catalog entry (its JSON): // the fingerprint is the entry's `fp` (the only form there is), the manifest's digest the entry's `manifest-digest`, the // source revisions are the entry's inputs'. A manifest // held for unknown fields has no verdict here: the model reads the fingerprint and the commit. func ModuleValue(entry json.RawMessage) (json.RawMessage, error) { var e meshcatalog.CatalogEntry if err := json.Unmarshal(entry, &e); err != nil || e.Module == "" { return nil, fmt.Errorf("a catalog entry does not read: %v", err) } v := meshcatalog.ModulesByModuleValue{Commit: e.Commit, Fp2: e.Fp, None2: e.None, Path: e.Path, Repository: e.Repository, Packages: e.Packages} // The entry carries the digest of its manifest's bytes as the indexer read them, `sha256:` and the 64 hex digits; the // model keeps the bare digits, as the value it always kept, and computes none (design 47 G §506, §578). v.Manifest = strings.TrimPrefix(e.ManifestDigest, "sha256:") if e.Verdict == meshcatalogclient.VerdictAccepted || e.Verdict == meshcatalogclient.VerdictRefused { v.Verdict = e.Verdict } if in := e.Inputs; in != nil { v.Src, v.FpSrc, v.Toolchains, v.Paths, v.Warnings = in.Src, in.FpSrc, in.Toolchains, in.Paths, in.Warnings if f := in.From; f != nil && v.Manifest != "" { v.Inputs2 = &meshcatalog.ModulesByModuleValueInputs2{Bases: f.Bases, Builder: f.Builder, Contexts: f.Contexts, ImportForm: f.ImportForm, Imports: f.Imports, Locks: f.Locks, Packages: f.Packages, Paths: f.Paths, Tree: f.Tree} } if v.Verdict == meshcatalogclient.VerdictRefused { v.Problems = in.Problems } } if v.Verdict == meshcatalogclient.VerdictRefused && len(v.Problems) == 0 { v.Verdict = "" } if v.Verdict != meshcatalogclient.VerdictRefused { v.Warnings = nil } return meshcatalogclient.EncodeModule(v) }