Add identity: whois resolver, checker, header mode, middleware; config for wake, peers, identity
Implemented-By: OpenCode session (model recorded in docs/implementer-log.md)
This commit is contained in:
@@ -68,12 +68,15 @@ type Host struct {
|
||||
BaseURL string `toml:"base_url"`
|
||||
Weight float64 `toml:"weight"`
|
||||
Models map[string]Model `toml:"models"`
|
||||
Wake *Wake `toml:"wake"`
|
||||
}
|
||||
|
||||
// Route is an ordered list of hosts to try, with an optional default model.
|
||||
// Route is an ordered list of hosts to try, with an optional default model and
|
||||
// the peers allowed to reach it.
|
||||
type Route struct {
|
||||
Hosts []string `toml:"hosts"`
|
||||
DefaultModel string `toml:"default_model"`
|
||||
Peers []string `toml:"peers"`
|
||||
}
|
||||
|
||||
// Config is the whole file: what to listen on, tuning, hosts and routes.
|
||||
@@ -84,6 +87,7 @@ type Config struct {
|
||||
DB string `toml:"db"`
|
||||
LeaseIdle Duration `toml:"lease_idle"`
|
||||
Retention Duration `toml:"retention"`
|
||||
Identity string `toml:"identity"`
|
||||
Hosts map[string]Host `toml:"hosts"`
|
||||
Routes map[string]Route `toml:"routes"`
|
||||
}
|
||||
@@ -109,6 +113,8 @@ const (
|
||||
|
||||
MinLeaseIdle = time.Minute
|
||||
MinRetention = 24 * time.Hour
|
||||
|
||||
DefaultIdentity = "off"
|
||||
)
|
||||
|
||||
var routeName = regexp.MustCompile(`^[a-z0-9][a-z0-9-]*$`)
|
||||
@@ -157,7 +163,10 @@ func Parse(r io.Reader) (*Config, error) {
|
||||
if c.QueueMax == 0 {
|
||||
c.QueueMax = DefaultQueueMax
|
||||
}
|
||||
if e := c.validate(); e != nil {
|
||||
if c.Identity == "" {
|
||||
c.Identity = DefaultIdentity
|
||||
}
|
||||
if e := c.validate(md); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return &c, nil
|
||||
@@ -184,7 +193,14 @@ func IsError(err error) (*Error, bool) {
|
||||
|
||||
// validate checks the config in a fixed order and writes defaults back into c.
|
||||
// The first problem wins; every problem is an *Error with a precise field.
|
||||
func (c *Config) validate() *Error {
|
||||
func (c *Config) validate(md toml.MetaData) *Error {
|
||||
peersDefined := make(map[string]bool, len(c.Routes))
|
||||
for name := range c.Routes {
|
||||
if md.IsDefined("routes", name, "peers") {
|
||||
peersDefined[name] = true
|
||||
}
|
||||
}
|
||||
identityDefined := md.IsDefined("identity")
|
||||
if e := c.checkListen(); e != nil {
|
||||
return e
|
||||
}
|
||||
@@ -206,7 +222,13 @@ func (c *Config) validate() *Error {
|
||||
if e := c.checkHosts(); e != nil {
|
||||
return e
|
||||
}
|
||||
return c.checkRoutes()
|
||||
if e := c.checkWake(); e != nil {
|
||||
return e
|
||||
}
|
||||
if e := c.checkRoutes(peersDefined, identityDefined); e != nil {
|
||||
return e
|
||||
}
|
||||
return c.checkIdentity()
|
||||
}
|
||||
|
||||
func (c *Config) checkListen() *Error {
|
||||
@@ -324,7 +346,7 @@ func (c *Config) checkHosts() *Error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) checkRoutes() *Error {
|
||||
func (c *Config) checkRoutes(peersDefined map[string]bool, identityDefined bool) *Error {
|
||||
if len(c.Routes) == 0 {
|
||||
return &Error{Field: "routes", Msg: "at least one required"}
|
||||
}
|
||||
@@ -367,6 +389,10 @@ func (c *Config) checkRoutes() *Error {
|
||||
return &Error{Field: fmt.Sprintf("routes.%s.default_model", name), Msg: "not served by any host in route"}
|
||||
}
|
||||
}
|
||||
|
||||
if e := checkPeers(name, r.Peers, peersDefined[name], identityDefined, c.Identity); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user