Files
mesh-catalog/modules/mesh-build-image/cmd/mesh-build-image/tools.go
T

58 lines
2.2 KiB
Go

package main
import (
"context"
stdio "git.novox.be/novox/mesh-sdk/go"
)
// The tools this module serves. A tool name is the module's as build_image_ and its verb (a tool name has no dot).
const (
FetchTool = "build_image_fetch"
BuildTool = "build_image_build"
StatusTool = "build_image_status"
HealthTool = "build_image_health"
)
// StepTool is one step tool of the module: fetch or build. Long is a step that answers at once and ends on its key
// (ADR 0469 §2); the others answer in their call. Both run behind the readiness guard.
type StepTool struct {
Name string
Description string
Input map[string]any
Long bool
Run func(ctx context.Context, args map[string]any) (any, error)
}
// StepTools are the module's step tools.
func (m *Module) StepTools() []StepTool {
return []StepTool{m.fetchTool(), m.buildTool(), m.copyTool()}
}
// Tools is every tool the module serves: its step tools behind the guard, its read tools, its status and its health.
func (m *Module) Tools(steps []StepTool) []stdio.Tool {
tools := []stdio.Tool{}
for _, s := range steps {
t := stdio.Tool{Name: s.Name, Description: s.Description, Input: s.Input}
if s.Name == CopyTool {
t.Run = m.Plain(s.Name, s.Run) // a copy needs no buildah, so the buildah guard does not stand in front of it
} else if s.Long {
t.Run = m.Long(s.Name, s.Run)
} else {
t.Run = m.Short(s.Run)
}
tools = append(tools, t)
}
tools = append(tools, m.ReadTools()...)
return append(tools,
stdio.Tool{Name: StatusTool,
Description: "What the image build module is on this machine: the buildah installed, the account's subordinate " +
"user and group ranges, whether a user namespace can be made, and why it refuses to build if it does. Read-only.",
Run: func(map[string]any) (any, error) { return m.Status(m.Ctx), nil }},
stdio.Tool{Name: HealthTool,
Description: "How the image build module is: unhealthy while buildah cannot be run, while its account holds no " +
"subordinate user or group range, or while a user namespace cannot be made, saying which; healthy otherwise. Read-only.",
Run: func(map[string]any) (any, error) { return m.Health(m.Ctx), nil }},
)
}