Files
mesh-delivery/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/reservedverb.go
T
jschoubben 5e76fdf725 H-A-328: the seat mesh-builds answers published; the builder serves it
A package published before a pipeline existed is in no record of the
runner, so the builder, which owns publishes, answers whether an
artifact built at a fingerprint is published, from its reservations
(marked from the registries' record) and its releases.

Builds: design 47 H H-A-328, H-A-326 (1), H-A-274
2026-11-21 21:25:03 +01:00

78 lines
3.4 KiB
Go

package main
import (
"context"
"encoding/json"
"fmt"
"strings"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-sdk/go/process"
"mesh-delivery-builder/internal/versions"
)
// The seat mesh-builds' verb reserved is answered by the builder's own process (design 47 G A-115, A-127; A-87: builder_build stays
// its tools bundle's): a module's reserved version with each artifact's digest once built, for a registry holder deciding whether to
// publish. Given a name it finds the module from the catalog half the process follows (carriers) and, for a version no reservation
// holds, asks the seat mesh-catalog's verb versions. The process's manifest declares the verb in `serves` beside its process.
// reservedReader is the state reserved read through its store, as the verb's answers read it.
func reservedReader(ctx context.Context, store versions.Store) versions.Reader {
return versions.Reader{
Keys: func() ([]string, error) { return store.KeysOf(ctx, versions.AllFilter) },
Get: func(key string) (json.RawMessage, bool, error) {
v, _, found, err := store.Get(ctx, key)
return v, found, err
}}
}
// reservedVerb is the handler of the verb reserved; missed is told each name no entry carries, for the builder's log (design 47 G
// A-418).
func reservedVerb(ctx context.Context, rr versions.Reader, carriers func(context.Context, string) ([]versions.Built, error), released versions.CatalogVersions, missed func(name string)) process.SeatHandler {
return func(_ string, body json.RawMessage) (any, error) {
var in meshbuilds.ReservedInput
if len(body) > 0 {
if err := json.Unmarshal(body, &in); err != nil {
return nil, fmt.Errorf("the arguments do not fit the verb reserved: %w", err)
}
}
if name := strings.TrimSpace(in.Name); name != "" {
a, err := versions.AnswerReservedByName(ctx, rr, carriers, released, name, in.Version)
if err == nil && missed != nil && strings.HasPrefix(a.Error, versions.NoEntryCarries) {
missed(name)
}
return a, err
}
return versions.AnswerReservedVerb(rr, in.Module, in.Version)
}
}
// publishedVerb is the handler of the verb published (design 47 H-A-328): whether an artifact built at a fingerprint is
// published, from the reservations and the releases the builder keeps.
func publishedVerb(ctx context.Context, of func(ctx context.Context, module, artifact, fingerprint string) (meshbuilds.PublishedAnswer, error)) process.SeatHandler {
return func(_ string, body json.RawMessage) (any, error) {
var in meshbuilds.PublishedInput
if err := json.Unmarshal(body, &in); err != nil {
return nil, fmt.Errorf("the arguments do not fit the verb published: %w", err)
}
return of(ctx, in.Module, in.Artifact, in.Fingerprint)
}
}
// catalogReleased are a module's released versions, asked of the seat mesh-catalog's verb versions through call.
func catalogReleased(call toolCaller) versions.CatalogVersions {
return func(_ context.Context, module string) ([]meshcatalog.VersionEntry, error) {
raw, err := call("seat:"+meshcatalog.Seat+".versions", meshcatalog.VersionsInput{Module: module})
if err != nil {
return nil, err
}
var a meshcatalog.VersionsAnswer
if err := json.Unmarshal(raw, &a); err != nil {
return nil, fmt.Errorf("the seat mesh-catalog's versions answered what does not read: %w", err)
}
return a.Versions, nil
}
}