The manifest validator refuses a delivery module's state, log or objects entry with no cap; the catalog reads them from the old sections and the requires entries alike, so the validator judges one list. Builds: design 47 H2 §814, §812
59 lines
2.0 KiB
Go
59 lines
2.0 KiB
Go
package catalogue
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strconv"
|
|
)
|
|
|
|
// Every kept store of a delivery module names its cap (design 47 H2 §812, §814): the manifest validator refuses a
|
|
// delivery module's state, log or objects entry with no cap. This is what it reads of a manifest; which module is a
|
|
// delivery module (one claiming a seat of the delivery system) and the foundation parts' old sections are its own to
|
|
// judge.
|
|
|
|
// Uncapped is one state, log or objects entry of a manifest that names no cap.
|
|
type Uncapped struct {
|
|
// Name is the entry's local name.
|
|
Name string `json:"name"`
|
|
// Kind is state, log or objects (the template's, or the old section's).
|
|
Kind string `json:"kind"`
|
|
// OldSection says the entry is in the old section of its kind (`state`, `logs`, `objects`), not an entry of
|
|
// `requires`.
|
|
OldSection bool `json:"old-section,omitempty"`
|
|
}
|
|
|
|
// UncappedStores is every state, log and objects entry of m that names no cap, the old sections' (max-mib) and the
|
|
// bus-state entries' (the option max-mib) alike, in the manifest's order. A log's default cap is not one it names.
|
|
func (m Manifest) UncappedStores() []Uncapped {
|
|
var out []Uncapped
|
|
for _, s := range m.State {
|
|
if s.MaxMiB == 0 {
|
|
out = append(out, Uncapped{Name: s.Name, Kind: TemplateState, OldSection: true})
|
|
}
|
|
}
|
|
for _, l := range m.Logs {
|
|
if l.MaxMiB == 0 {
|
|
out = append(out, Uncapped{Name: l.Name, Kind: TemplateLog, OldSection: true})
|
|
}
|
|
}
|
|
for _, o := range m.Objects {
|
|
if o.MaxMiB == 0 {
|
|
out = append(out, Uncapped{Name: o.Name, Kind: TemplateObjects, OldSection: true})
|
|
}
|
|
}
|
|
for _, e := range m.BusState {
|
|
switch e.Template {
|
|
case TemplateState, TemplateLog, TemplateObjects:
|
|
if !namesCap(e.Options[OptionCapMiB]) {
|
|
out = append(out, Uncapped{Name: e.Name, Kind: e.Template})
|
|
}
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// namesCap is whether an option's value is a cap above zero.
|
|
func namesCap(raw json.RawMessage) bool {
|
|
n, err := strconv.ParseFloat(string(raw), 64)
|
|
return err == nil && n > 0
|
|
}
|