275 lines
9.0 KiB
Go
275 lines
9.0 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 (
|
|
"bytes"
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// Seat is the seat's name.
|
|
const Seat = "mesh-node-enroller"
|
|
|
|
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}
|
|
}
|
|
|
|
// 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>", refusing a field EnrolmentsByNodeNodeValue does not know and any text after the value.
|
|
func DecodeEnrolmentsByNodeNodeValue(raw []byte) (EnrolmentsByNodeNodeValue, error) {
|
|
var v EnrolmentsByNodeNodeValue
|
|
dec := json.NewDecoder(bytes.NewReader(raw))
|
|
dec.DisallowUnknownFields()
|
|
if err := dec.Decode(&v); err != nil {
|
|
return v, err
|
|
}
|
|
if dec.More() {
|
|
return v, errors.New("text after the value")
|
|
}
|
|
return v, 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>", refusing a field EnrolmentsByAddressAddressValue does not know and any text after the value.
|
|
func DecodeEnrolmentsByAddressAddressValue(raw []byte) (EnrolmentsByAddressAddressValue, error) {
|
|
var v EnrolmentsByAddressAddressValue
|
|
dec := json.NewDecoder(bytes.NewReader(raw))
|
|
dec.DisallowUnknownFields()
|
|
if err := dec.Decode(&v); err != nil {
|
|
return v, err
|
|
}
|
|
if dec.More() {
|
|
return v, errors.New("text after the value")
|
|
}
|
|
return v, 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"`
|
|
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"`
|
|
// 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"`
|
|
Issued *time.Time `json:"issued,omitempty"`
|
|
Node string `json:"node"`
|
|
V int64 `json:"v,omitempty"`
|
|
}
|