Files
mesh-contracts/identity-and-access/go/seats/meshnodeenroller/contract.go
T
jschoubben 2dfdcc3316 H2: every seat contract says each verb's description
A tools program that serves a seat's verbs as tools reads a verb's
description from the generated contract, one copy taken from seat.json,
instead of writing it again. Generated again in all five folders by
mesh-delivery's seatgen (feat/47-H2 b65b6173), which now writes
VerbDescription; seatgen -check clean, every package's vet and tests green.

Builds: design 47 H2 H-A-449
2026-11-22 02:36:36 +01:00

410 lines
17 KiB
Go

// Code generated by seatgen from the seat definitions; DO NOT EDIT.
// Package meshnodeenroller is the contract of the seat "mesh-node-enroller", defined whole (seats/mesh-node-enroller/seat.json): The seat that enrols a new machine on the operator's Approve and a one-time token (ADR 0587). Renamed from mesh-enrolment (ADR 0634 §9).
package meshnodeenroller
import (
"encoding/json"
"strings"
"time"
)
// Seat is the seat's name.
const Seat = "mesh-node-enroller"
// Form is the form of the seat's values, events and answers this contract was generated at (design 47 H2 §780):
// a reader of a value of another form says "form N, this reader knows M".
const Form = 1
// The forms and the digest of the fields this contract was generated from: the generator's compare fails a definition
// whose fields changed while its forms did not (design 47 H2 §780).
const (
generatedForms = "1"
generatedFieldsDigest = "AgainAnswer=7538f2f5e68e ConfirmAnswer=7538f2f5e68e Enrolment=ce9d7d79b28a EnrolmentExpiredEvent=4dde8efb6998 EnrolmentIssuedEvent=4dde8efb6998 EnrolmentRefusedEvent=4dde8efb6998 EnrolmentRevokedEvent=4dde8efb6998 EnrolmentsByAddressAddressValue=524d3056537d EnrolmentsByNodeNodeValue=4dde8efb6998 IssueAnswer=7538f2f5e68e NodeEnrolledEvent=4dde8efb6998 RedeemAnswer=1aa043e59eac RevokeAnswer=7538f2f5e68e TokensAnswer=7538f2f5e68e"
)
const (
VerbIssue = "issue"
VerbRedeem = "redeem"
VerbConfirm = "confirm"
VerbRevoke = "revoke"
VerbTokens = "tokens"
VerbAgain = "again"
)
const (
EventEnrolmentIssued = "enrolment-issued"
EventNodeEnrolled = "node-enrolled"
EventEnrolmentRefused = "enrolment-refused"
EventEnrolmentRevoked = "enrolment-revoked"
EventEnrolmentExpired = "enrolment-expired"
)
// Verbs is every verb the seat serves, in its definition's order: a new copy each call.
func Verbs() []string {
return []string{VerbIssue, VerbRedeem, VerbConfirm, VerbRevoke, VerbTokens, VerbAgain}
}
// VerbDescription is a verb's description as the seat's definition says it, "" for a verb the seat does not serve or
// does not describe (design 47 H2 H-A-449).
func VerbDescription(verb string) string {
switch verb {
case VerbIssue:
return "Issue a one-time token for a new machine, on the operator's Approve: refused at once, naming every finding, for a name that is not a node name or that a node record, a placement key or an open enrolment holds, and for every call before the controller's lease is handed away. Otherwise reserves the lowest free private-network address, asks the operator under the seat's own name and, on the warrant, adds the node to placement with its tunnel key, asks the vault for the token and says enrolment-issued. The token itself is read only through tokens."
case VerbRedeem:
return "Spend a token: asked by a joining node-engine dialled as enrol.<node> alone, with the public halves of its keys and its identity key's proof over them. Spends the token, asks the vault for the node's account and certificate, writes the node into placement, and answers the account sealed to the node, its certificate and the vault's public half, signed by the vault. Asked again with the same keys it finishes what is not done and answers the same; with other keys it is refused."
case VerbConfirm:
return "Confirm an enrolment: asked by the node-engine dialled as its own node login alone, the runtime's proof of that caller being the confirmation. Says node-enrolled and ends the enrolment."
case VerbRevoke:
return "End an enrolment at any stage, with why, without an Approve: withdraws an open ask, deletes the node's key and its address, has the vault retire an account it already minted for it, records the act as a hand act and says enrolment-revoked."
case VerbTokens:
return "Read every open enrolment, or one: its stage, expiry, ask and revision, the bucket's fill against its cap. For a node at live, its token sealed to the operator key, asked of the vault at that moment and relayed as the vault sealed it. With history, the ended enrolments from the seat's events, as far back as the events are kept."
case VerbAgain:
return "Raise an issue's ask again when the operator's channel does not hold it, and nothing more."
}
return ""
}
// Events is every event published on the seat's subject: a new copy each call.
func Events() []string {
return []string{EventEnrolmentIssued, EventNodeEnrolled, EventEnrolmentRefused, EventEnrolmentRevoked, EventEnrolmentExpired}
}
// Family is where the seat's events are kept: the shared events stream, filtered to the seat's subjects.
const (
Family = "mesh-node-enroller.events"
FamilyMaxAgeDays = 7
)
// SubjectEnrolmentIssued is where enrolment-issued is published.
const SubjectEnrolmentIssued = "mesh.seat.mesh-node-enroller.event.enrolment-issued"
// SubjectNodeEnrolled is where node-enrolled is published.
const SubjectNodeEnrolled = "mesh.seat.mesh-node-enroller.event.node-enrolled"
// SubjectEnrolmentRefused is where enrolment-refused is published.
const SubjectEnrolmentRefused = "mesh.seat.mesh-node-enroller.event.enrolment-refused"
// SubjectEnrolmentRevoked is where enrolment-revoked is published.
const SubjectEnrolmentRevoked = "mesh.seat.mesh-node-enroller.event.enrolment-revoked"
// SubjectEnrolmentExpired is where enrolment-expired is published.
const SubjectEnrolmentExpired = "mesh.seat.mesh-node-enroller.event.enrolment-expired"
const (
StateEnrolments = "enrolments"
)
// EnrolmentsByNodeNodeKey is the key of one value of the state enrolments under the form "node.<node>".
func EnrolmentsByNodeNodeKey(node string) string { return "node." + node }
// ParseEnrolmentsByNodeNodeKey reads the parts of a key of the form "node.<node>", in the order of the form; the last result is false for a key of another form.
func ParseEnrolmentsByNodeNodeKey(key string) (string, bool) {
rest := key
if !strings.HasPrefix(rest, "node.") {
return "", false
}
rest = rest[5:]
if rest == "" {
return "", false
}
v1 := rest
rest = ""
if rest != "" {
return "", false
}
return v1, true
}
// DecodeEnrolmentsByNodeNodeValue reads one value of the state enrolments under the form "node.<node>" as another part wrote it: a field EnrolmentsByNodeNodeValue does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeEnrolmentsByNodeNodeValue(raw []byte) (EnrolmentsByNodeNodeValue, int, error) {
var v EnrolmentsByNodeNodeValue
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// EnrolmentsByAddressAddressKey is the key of one value of the state enrolments under the form "address.<address>".
func EnrolmentsByAddressAddressKey(address string) string { return "address." + address }
// ParseEnrolmentsByAddressAddressKey reads the parts of a key of the form "address.<address>", in the order of the form; the last result is false for a key of another form.
func ParseEnrolmentsByAddressAddressKey(key string) (string, bool) {
rest := key
if !strings.HasPrefix(rest, "address.") {
return "", false
}
rest = rest[8:]
if rest == "" {
return "", false
}
v1 := rest
rest = ""
if rest != "" {
return "", false
}
return v1, true
}
// DecodeEnrolmentsByAddressAddressValue reads one value of the state enrolments under the form "address.<address>" as another part wrote it: a field EnrolmentsByAddressAddressValue does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeEnrolmentsByAddressAddressValue(raw []byte) (EnrolmentsByAddressAddressValue, int, error) {
var v EnrolmentsByAddressAddressValue
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// Enrolment is one open enrolment.
type Enrolment struct {
Address string `json:"address"`
Ask string `json:"ask,omitempty"`
Caller string `json:"caller,omitempty"`
Expires *time.Time `json:"expires,omitempty"`
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
Form int64 `json:"form,omitempty"`
Issued *time.Time `json:"issued,omitempty"`
KeysDigest string `json:"keys-digest,omitempty"`
Node string `json:"node"`
OverlayKey string `json:"overlay-key,omitempty"`
// asked, live or redeeming
Stage string `json:"stage"`
V int64 `json:"v,omitempty"`
Why string `json:"why,omitempty"`
}
// IssueInput is what issue takes.
type IssueInput struct {
// how long the token lasts, a duration such as 1h or 24h: one hour when not given, at most 24 hours
Expires string `json:"expires,omitempty"`
// the new machine's name in the mesh
Node string `json:"node"`
// the new machine's private network (tunnel) public key, as `nox-mesh-host key` prints it
OverlayKey string `json:"overlay_key"`
// why it joins, shown to the operator with the ask
Why string `json:"why"`
}
// IssueAnswer is what issue answers.
type IssueAnswer = map[string]any
// RedeemInput is what redeem takes.
type RedeemInput struct {
// the node the token was issued for
Node string `json:"node"`
// the private network key's public half
OverlayKey string `json:"overlay_key,omitempty"`
// what the machine is, as its record says it
Profile map[string]any `json:"profile,omitempty"`
// the identity key's signature over the redeem's proof bytes (delivery.RedeemProof), base64
Proof string `json:"proof"`
// the identity key's public half, base64
PublicKey string `json:"public_key"`
// the sealing key's public half, which the account is sealed to
SealingKey string `json:"sealing_key"`
// the serving key's public half, which the certificate binds
ServingKey string `json:"serving_key,omitempty"`
// a tunnel found on the machine: everything but its private key
Tunnel map[string]any `json:"tunnel,omitempty"`
}
// RedeemAnswer is what redeem answers.
type RedeemAnswer struct {
// its account sealed to the sealing key it presented, base64
Account string `json:"account"`
// its certificate, PEM
Certificate string `json:"certificate"`
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
Form int64 `json:"form,omitempty"`
// the login it dials as next
Login string `json:"login"`
// the node
Node string `json:"node"`
// the vault's signature over the answer without it, under the context of the enrolment kind, base64
Signature string `json:"signature,omitempty"`
// the vault's public signing half, base64
Signer string `json:"signer"`
}
// ConfirmInput is what confirm takes.
type ConfirmInput struct {
}
// ConfirmAnswer is what confirm answers.
type ConfirmAnswer = map[string]any
// RevokeInput is what revoke takes.
type RevokeInput struct {
// the node
Node string `json:"node"`
// why, recorded with the hand act
Why string `json:"why"`
}
// RevokeAnswer is what revoke answers.
type RevokeAnswer = map[string]any
// TokensInput is what tokens takes.
type TokensInput struct {
// "true": the ended enrolments too
History string `json:"history,omitempty"`
// one node
Node string `json:"node,omitempty"`
}
// The values of TokensInput's history.
const (
TokensInputHistoryTrue = "true"
TokensInputHistoryFalse = "false"
)
// TokensAnswer is what tokens answers.
type TokensAnswer = map[string]any
// AgainInput is what again takes.
type AgainInput struct {
// the node whose ask is raised again
Node string `json:"node"`
}
// AgainAnswer is what again answers.
type AgainAnswer = map[string]any
// EnrolmentIssuedEvent is the body of the event enrolment-issued.
type EnrolmentIssuedEvent = Enrolment
// NodeEnrolledEvent is the body of the event node-enrolled.
type NodeEnrolledEvent = Enrolment
// EnrolmentRefusedEvent is the body of the event enrolment-refused.
type EnrolmentRefusedEvent = Enrolment
// EnrolmentRevokedEvent is the body of the event enrolment-revoked.
type EnrolmentRevokedEvent = Enrolment
// EnrolmentExpiredEvent is the body of the event enrolment-expired.
type EnrolmentExpiredEvent = Enrolment
// EnrolmentsByNodeNodeValue is one value of the state enrolments under the key node.<node>.
type EnrolmentsByNodeNodeValue = Enrolment
// EnrolmentsByAddressAddressValue is one value of the state enrolments under the key address.<address>.
type EnrolmentsByAddressAddressValue struct {
Ask string `json:"ask,omitempty"`
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
Form int64 `json:"form,omitempty"`
Issued *time.Time `json:"issued,omitempty"`
Node string `json:"node"`
V int64 `json:"v,omitempty"`
}
// DecodeIssueAnswer reads a IssueAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeIssueAnswer(raw []byte) (IssueAnswer, int, error) {
var v IssueAnswer
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeRedeemAnswer reads a RedeemAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeRedeemAnswer(raw []byte) (RedeemAnswer, int, error) {
var v RedeemAnswer
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeConfirmAnswer reads a ConfirmAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeConfirmAnswer(raw []byte) (ConfirmAnswer, int, error) {
var v ConfirmAnswer
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeRevokeAnswer reads a RevokeAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeRevokeAnswer(raw []byte) (RevokeAnswer, int, error) {
var v RevokeAnswer
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeTokensAnswer reads a TokensAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeTokensAnswer(raw []byte) (TokensAnswer, int, error) {
var v TokensAnswer
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeAgainAnswer reads a AgainAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeAgainAnswer(raw []byte) (AgainAnswer, int, error) {
var v AgainAnswer
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeEnrolmentIssuedEvent reads a EnrolmentIssuedEvent as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeEnrolmentIssuedEvent(raw []byte) (EnrolmentIssuedEvent, int, error) {
var v EnrolmentIssuedEvent
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeNodeEnrolledEvent reads a NodeEnrolledEvent as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeNodeEnrolledEvent(raw []byte) (NodeEnrolledEvent, int, error) {
var v NodeEnrolledEvent
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeEnrolmentRefusedEvent reads a EnrolmentRefusedEvent as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeEnrolmentRefusedEvent(raw []byte) (EnrolmentRefusedEvent, int, error) {
var v EnrolmentRefusedEvent
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeEnrolmentRevokedEvent reads a EnrolmentRevokedEvent as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeEnrolmentRevokedEvent(raw []byte) (EnrolmentRevokedEvent, int, error) {
var v EnrolmentRevokedEvent
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeEnrolmentExpiredEvent reads a EnrolmentExpiredEvent as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeEnrolmentExpiredEvent(raw []byte) (EnrolmentExpiredEvent, int, error) {
var v EnrolmentExpiredEvent
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// formRead is the form a value says on the wire: 1 when it says none, or is no object.
func formRead(raw []byte) int {
var f struct {
Form int `json:"form"`
}
if json.Unmarshal(raw, &f) != nil || f.Form < 1 {
return 1
}
return f.Form
}