Files
mesh-catalog/modules/mesh-delivery-gate/manifest.go
T

47 lines
1.5 KiB
Go

// Package gate holds the delivery gate's own manifest, so its code takes from the manifest's declarations what it hears,
// never another module's name written in code.
package gate
import (
_ "embed"
"encoding/json"
"fmt"
)
//go:embed module.json
var manifest []byte
// Consumes is what the gate's manifest consumes, in its order.
func Consumes() ([]string, error) {
var m struct {
Consumes []string `json:"consumes"`
}
if err := json.Unmarshal(manifest, &m); err != nil {
return nil, fmt.Errorf("the gate's own manifest is not readable: %w", err)
}
return m.Consumes, nil
}
// RecordsDays are the days the manifest's ledger `records` keeps its history (`max-age-days`) and an ended instance's state
// (`ended-days`), as its `configuration` says them (design 47 H2 H-A-634 (7)); the gate's read tools say them beside the records.
func RecordsDays() (keeping, ended int, err error) {
var m struct {
Requires []struct {
Name string `json:"name"`
Configuration map[string]any `json:"configuration"`
} `json:"requires"`
}
if err := json.Unmarshal(manifest, &m); err != nil {
return 0, 0, fmt.Errorf("the gate's own manifest is not readable: %w", err)
}
for _, r := range m.Requires {
if r.Name != "records" {
continue
}
k, _ := r.Configuration["max-age-days"].(float64)
e, _ := r.Configuration["ended-days"].(float64)
return int(k), int(e), nil
}
return 0, 0, fmt.Errorf("the gate's own manifest asks for no ledger records")
}