behaviordsl

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package behaviordsl is the behavior group: the commands that list, describe, scaffold, teach and check the behaviors of this binary. The package is not named behavior, which is the DSL itself.

Index

Constants

This section is empty.

Variables

View Source
var Group = command.Register(command.Define(
	"behavior",
	"List, describe and validate the behaviors this binary has",
	command.Long("A behavior is one thing that osapi manages on a host, for example kernel\n"+
		"parameters. [Behaviors](../../../../architecture/behaviors.md) tells more.\n"+
		"These commands read the definitions in the binary. Thus they need no config\n"+
		"file and no controller. What they print always agrees with the build that\n"+
		"you run."),
	command.Under(command.ParentDSL),
	command.Uses[Deps](),
	command.SubDoc("method", "Show one method of a behavior in full"),
	command.SubDoc("openapi", "Print a served behavior's part of the OpenAPI spec"),
	command.SubDoc(
		"spec",
		"Print the behavior DSL: each option, method, example part and field tag",
	),
	command.Method[ListInput, ListOutput]("list").
		Short("List the behaviors this binary has").
		Long("An internal behavior has no API or CLI of its own. Only other behaviors\n"+
			"use it.").
		Example("").
		Prints(sampleList).
		Example("--json").
		Handle(List),
	command.Method[GetInput, GetOutput]("get").
		Short("Show a behavior: its surfaces, chain, methods, types and telemetry").
		Long("It shows where osapi serves the behavior, its platforms, the programs that\n"+
			"it runs with sudo, the behaviors that it uses and that use it, its methods\n"+
			"with their routes and permissions, its types, its settings and its\n"+
			"telemetry.\n\n"+
			"**Uses** lists the behaviors this one is built on. The agent builds their\n"+
			"providers first, and the methods of this behavior call theirs on the same\n"+
			"host, in the same job. If a behavior that it uses cannot run on a\n"+
			"platform, this one reports `skipped` there too. **Used by** lists the\n"+
			"behaviors built on this one. A behavior with `Internal: yes` has no route,\n"+
			"no command and no permission. Only the behaviors under **Used by** call\n"+
			"it. `osapi dsl behavior method get` shows one method in full: its fields with\n"+
			"their constraints, its output and its examples.").
		Example("--name sysctl").
		Prints(sampleGet).
		Example("--name sysctl --json").
		Fails("no name", GetInput{}).
		Handle(Get),
	command.Method[MethodInput, MethodOutput]("get").
		Sub("method").
		Short("Show one method of a behavior: its fields, constraints, output and examples").
		Long("Each input field is a flag of its command and a field of its request.\n"+
			"`--json` has the JSON Schema of the input and the output, with each\n"+
			"constraint that osapi checks before it queues the job.").
		Example("--name sysctl --method update").
		Prints(sampleMethod).
		Example("--name sysctl --method update --json").
		Fails("no name", MethodInput{Method: "get"}).
		Fails("no method", MethodInput{Name: "sysctl"}).
		Handle(MethodGet),
	command.Method[GetInput, OpenAPIOutput]("get").
		Sub("openapi").
		Short("Print a served behavior's part of the OpenAPI spec, as YAML").
		Long("It prints the spec as the definition makes it: the part that go generate\n"+
			"writes to the behavior's gen/api.yaml, and puts in the full spec of the\n"+
			"API. An internal behavior serves no route, so it has none.").
		Example("--name sysctl").
		Prints(sampleOpenAPI).
		Fails("no name", GetInput{}).
		Handle(OpenAPIGet),
	command.Method[CreateInput, CreateOutput]("create").
		Short("Write a new behavior's standard layout in an osapi checkout").
		Long("Before you change anything, the result builds, validates and passes every\n"+
			"test. Then change the types, the provider and the examples to what the\n"+
			"behavior manages. Writes nothing when the name is taken. The behavior is\n"+
			"directly under node: its routes are `/api/node/{hostname}/<name>` and its\n"+
			"commands `osapi client node <name>`. To nest it under a parent, add\n"+
			"`behavior.Of` or `behavior.Under` to its definition.\n"+
			"[Your first behavior](../../../../development/your-first-behavior.md) walks\n"+
			"through the rest.\n\n"+
			"A new behavior is one an operator calls, with an API and commands. Work\n"+
			"that two behaviors share, such as writing a file, becomes an internal\n"+
			"behavior that the two require: add `behavior.Internal` to it then, and\n"+
			"`behavior.Requires` to each user. `osapi dsl behavior validate` fails an\n"+
			"internal behavior that no behavior requires.\n\n"+
			"`--requires` names the behaviors that the new one is built on. For each,\n"+
			"it writes `behavior.Requires`, the `host.Require` in the builder and a\n"+
			"field of the provider. You write each `behavior.Call`: until an example\n"+
			"calls a required behavior, the tests fail the rule `used`.").
		Example(`--name motd --description "The message shown at login"`).
		Prints(sampleCreate).
		Example(`--name motd --description "The message shown at login" --root ~/src/osapi`).
		Example(`--name ntpconf --description "The NTP config" --requires managedfile`).
		Fails("no name", CreateInput{Description: "x"}).
		Fails("no description", CreateInput{Name: "x"}).
		Handle(Create),
	command.Method[SpecInput, SpecOutput]("get").
		Sub("spec").
		Short("Print the behavior DSL: each option, method, example part and field tag").
		Long("Print each part of the behavior DSL, what it makes osapi do and when to use\n"+
			"it. The list comes from this binary. Thus it agrees with the build that you\n"+
			"run. Read it before you write a behavior, then check the result with\n"+
			"`osapi dsl behavior validate`.").
		Example("").
		Prints(sampleSpec).
		Example("--json").
		Handle(Spec),
	command.Method[ValidateInput, ValidateOutput]("validate").
		Short("Check every behavior against the rules the platform relies on").
		Long("It prints each problem with its behavior, method, rule and message, then\n"+
			"the fix of each rule, and exits 1 when a rule fails. `osapi dsl behavior spec\n"+
			"get` describes each part of a behavior.\n\n"+
			"The rules:\n\n"+behavior.Checks.Help()+"\n"+
			"`go test` runs the examples and refusals of each behavior on a fake host,\n"+
			"and checks these. Each failure ends with its fix:\n\n"+behavior.TestChecks.Help()+
			"\n`go test` also checks the chain rules that need a run of the examples.\n"+
			"`osapi dsl chain validate` checks them too:\n\n"+runChainChecks().Help()).
		Example("").
		Prints(sampleValidate).
		Example("--json").
		Handle(Validate),
))

Group is the behavior group's definition.

Functions

This section is empty.

Types

type CreateInput

type CreateInput struct {
	Name        string   `json:"name"        validate:"required"  doc:"The behavior's name: lowercase letters and digits"`
	Description string   `json:"description" validate:"required"  doc:"What it manages, in one line"`
	Package     string   `` /* 162-byte string literal not displayed */
	Requires    []string `` /* 162-byte string literal not displayed */
	Root        string   `` /* 174-byte string literal not displayed */
}

CreateInput is the behavior to create, and where.

type CreateOutput

type CreateOutput struct {
	Name  string `                 json:"name"`
	Files []File `                 json:"files"`
	Next  []Step `                 json:"next"`
	// contains filtered or unexported fields
}

CreateOutput is the files that create wrote, and the steps after it.

func Create

func Create(
	_ context.Context,
	_ Deps,
	in CreateInput,
) (CreateOutput, error)

Create writes a new behavior's layout in the checkout, and is its files and the steps after it.

type Deps

type Deps struct {
	Behaviors func() []*behavior.Behavior
	Validate  func() []behavior.Problem
	Keys      func() []config.Key
	Spec      func() guide.Spec
	OpenAPI   func(b *behavior.Behavior) (any, error)
}

Deps is what the methods use: the behaviors, their problems, the config keys their settings are, the spec of the DSL, and what makes a served behavior's part of the OpenAPI spec.

type ExampleRow

type ExampleRow struct {
	Example string `json:"example"`
	Input   string `json:"input"`
	Output  string `json:"output"`
}

ExampleRow is one example of a method: its input and output, as fields.

type Field

type Field struct {
	Field       string `json:"field"`
	Type        string `json:"type"`
	Required    bool   `json:"required"`
	Constraints string `json:"constraints"`
	Description string `json:"description"`
}

Field is one input field: its flag and request field.

func Fields

func Fields(
	s *behavior.Schema,
) []Field

Fields are the fields of an input schema in declared order, with their constraints. The method get of the endpoint and the command DSLs uses it too, so the three show a method the same way.

type File

type File struct {
	Path string `json:"path"`
}

File is a file that create wrote.

type GetInput

type GetInput struct {
	Name string `json:"name" validate:"required" doc:"The behavior, from osapi dsl behavior list"`
}

GetInput names the behavior.

type GetOutput

type GetOutput struct {
	Name       string             `                 json:"name"`
	Doc        string             `                 json:"doc"             label:"Description"`
	Placement  behavior.Placement `                 json:"placement"`
	Under      string             `                 json:"under,omitempty"`
	Of         string             `                 json:"of,omitempty"`
	Area       area.Name          `                 json:"area,omitempty"`
	Internal   bool               `                 json:"internal"`
	API        bool               `                 json:"api"             label:"API"`
	CLI        bool               `                 json:"cli"             label:"CLI"`
	Next       bool               `                 json:"next"`
	Platforms  []string           `                 json:"platforms"                           none:"none"`
	Sudo       []string           `                 json:"sudo"                                none:"none"`
	Runs       []string           `                 json:"runs"                                none:"none"`
	Writes     []string           `                 json:"writes"                              none:"none"`
	KeepsState bool               `                 json:"keeps_state"`
	Uses       []string           `                 json:"uses"                                none:"none"`
	UsedBy     []string           `                 json:"used_by"         label:"Used by"     none:"none"`
	Methods    []Method           `                 json:"methods"`
	Types      []Type             `                 json:"types"`
	Settings   []Setting          `                 json:"settings"                                        empty:"Declare them with behavior.Config."`
	Telemetry  Telemetry          `                 json:"telemetry"`
	// contains filtered or unexported fields
}

GetOutput is a behavior: where osapi serves it, where it runs, what it is built on, its methods, types and settings, and what its calls record.

func Get

func Get(
	_ context.Context,
	d Deps,
	in GetInput,
) (GetOutput, error)

Get is the behavior with the name.

type ListInput

type ListInput struct{}

ListInput is the input of list, which has none.

type ListOutput

type ListOutput struct {
	Items []Summary `                  json:"items"`
	// contains filtered or unexported fields
}

ListOutput is each behavior.

func List

func List(
	_ context.Context,
	d Deps,
	_ ListInput,
) (ListOutput, error)

List is each behavior, with the names of its methods.

type Method

type Method struct {
	Name       string     `json:"name"`
	Verb       types.Verb `json:"verb"`
	HTTPMethod string     `json:"http_method,omitempty" label:"HTTP"`
	Route      string     `json:"route,omitempty"                           none:"-"`
	Permission string     `json:"permission,omitempty"                      none:"-"`
	Command    string     `json:"command,omitempty"                                  table:"-"`
	Doc        string     `json:"doc"                   label:"Description"`
}

Method is one method of a behavior: where it is served and run.

type MethodInput

type MethodInput struct {
	Name   string `json:"name"   validate:"required" doc:"The behavior, from osapi dsl behavior list"`
	Method string `json:"method" validate:"required" doc:"The method, from osapi dsl behavior get"`
}

MethodInput is the behavior and the method to show.

type MethodOutput

type MethodOutput struct {
	Name       string             `               json:"name"`
	Verb       types.Verb         `               json:"verb"`
	Doc        string             `               json:"doc"                   label:"Description"`
	Long       string             `               json:"long,omitempty"        label:"Detail"`
	HTTPMethod string             `               json:"http_method,omitempty" label:"HTTP"`
	Route      string             `               json:"route,omitempty"                           none:"other behaviors only; it is not served"`
	Permission string             `               json:"permission,omitempty"`
	Command    string             `               json:"command,omitempty"`
	InputType  string             `               json:"input_type"            label:"Input type"`
	OutputType string             `               json:"output_type"           label:"Output type"`
	Fields     []Field            `` /* 177-byte string literal not displayed */
	Results    []Result           `               json:"results"               label:"Output"`
	Examples   []ExampleRow       `               json:"example_rows"          label:"Examples"`
	Input      *behavior.Schema   `` /* 188-byte string literal not displayed */
	Output     *behavior.Schema   `` /* 188-byte string literal not displayed */
	Calls      []behavior.Example `` /* 188-byte string literal not displayed */
	Refusals   []behavior.Refusal `` /* 188-byte string literal not displayed */
	// contains filtered or unexported fields
}

MethodOutput is one method in full: where it is served, its fields with their constraints, its output and its examples. --json has the JSON Schema of its input and output.

func MethodGet

func MethodGet(
	_ context.Context,
	d Deps,
	in MethodInput,
) (MethodOutput, error)

MethodGet is one method of the behavior in full.

type OpenAPIOutput

type OpenAPIOutput struct {
	Name string `json:"name"`
	YAML string `json:"yaml" render:"body"`
}

OpenAPIOutput is a served behavior's part of the OpenAPI spec, as YAML, which prints as it is.

func OpenAPIGet

func OpenAPIGet(
	_ context.Context,
	d Deps,
	in GetInput,
) (OpenAPIOutput, error)

OpenAPIGet is the served behavior's part of the OpenAPI spec, as YAML: the part that go generate writes to its gen/api.yaml and puts in the full spec of the API.

type Result

type Result struct {
	Field       string `json:"field"`
	Type        string `json:"type"`
	Description string `json:"description"`
}

Result is one field of the output.

func Results

func Results(
	s *behavior.Schema,
) []Result

Results are the fields of an output schema in declared order. A list is described by its element, since each element is one result row. The method get of the endpoint and the command DSLs uses it too.

type Setting

type Setting struct {
	Key     string `json:"key"`
	Flag    string `json:"flag"    label:"Agent flag" prefix:"--"`
	Type    string `json:"type"`
	Default string `json:"default"`
}

Setting is one of a behavior's config keys, and the agent start flag that sets it.

type SpecInput

type SpecInput struct{}

SpecInput is the input of spec get, which has none.

type SpecOutput

type SpecOutput struct {
	Kinds []guide.Section `json:"kinds" table:"sections"`
}

SpecOutput is each kind of term of the DSL, with its terms.

func Spec

func Spec(
	_ context.Context,
	d Deps,
	_ SpecInput,
) (SpecOutput, error)

Spec is each part of the behavior DSL, by kind.

type Step

type Step struct {
	Step string `json:"step"`
}

Step is a step after create.

type Summary

type Summary struct {
	Name     string    `json:"name"`
	Under    string    `json:"under,omitempty"`
	Of       string    `json:"of,omitempty"`
	Area     area.Name `json:"area,omitempty"`
	Methods  []string  `json:"methods"`
	Doc      string    `json:"doc"                label:"Description"`
	Internal bool      `json:"internal,omitempty"`
}

Summary is one behavior and the names of its methods.

type Telemetry

type Telemetry struct {
	Span       string              `json:"span"`
	ChildSpans []string            `json:"child_spans" label:"Child spans"     none:"none"`
	Metrics    []string            `json:"metrics"`
	Attributes []string            `json:"attributes"`
	Recorded   string              `json:"recorded"    label:"Recorded inputs" none:"none"`
	Inputs     map[string][]string `json:"inputs"                                          render:"-"`
}

Telemetry is what a behavior's calls record: the span and metrics every method gets, and the input fields each method records on the span.

type Type

type Type struct {
	Name   string `json:"name"`
	Input  string `json:"input"`
	Output string `json:"output"`
}

Type is the input and the output type of one method, with their fields: CreateInput { key*, value* }, a required input field marked *.

type ValidateInput

type ValidateInput struct{}

ValidateInput is the input of validate, which has none.

type ValidateOutput

type ValidateOutput struct {
	Behaviors int                `                   json:"behaviors"`
	Valid     bool               `                   json:"valid"`
	Problems  []behavior.Problem `                   json:"problems,omitempty"`
	Fixes     map[string]any     `                   json:"fixes,omitempty"`
	// contains filtered or unexported fields
}

ValidateOutput is each problem of each behavior, and the fix of each rule that one breaks.

func Validate

func Validate(
	_ context.Context,
	d Deps,
	_ ValidateInput,
) (ValidateOutput, error)

Validate checks each behavior. When a rule fails, it is the report with command.Fail: the report prints, then the command exits 1.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL