join

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: 18 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 join is the join group under osapi controller: osapi controller join token create, list and revoke, which make, show and remove the tokens that admit an agent at its join (osapi-io/osapi#1313). They are local commands: they connect to NATS as the controller does, and the API does not give a token.

Index

Constants

This section is empty.

Variables

View Source
var Group = command.Register(command.Define(
	"join", "Make and remove the tokens that admit an agent at its join",
	command.Under(command.ParentController),
	command.Uses[Deps](),
	command.SubDoc("token", "Make, list and revoke the join tokens"),
	command.Method[CreateInput, CreateOutput]("create").
		Sub("token").
		Short("Make a join token, and print it with the join string").
		Long("The token admits an agent at its join, until it expires or its uses are\n"+
			"gone. The controller keeps a hash of it, not the token: this command prints\n"+
			"the token one time.\n\n"+
			"By default the agent joins over NATS, and needs to reach NATS only. The join\n"+
			"string has the address of NATS (`controller.join.url`, or else\n"+
			"`nats.server.url`), the bootstrap user, which can only send the join request,\n"+
			"and for a `tls://` server the fingerprint of its certificate, which the agent\n"+
			"pins. The controller gives the agent its own NATS user at the join.\n\n"+
			"With `--transport https`, the agent joins over the controller's API: the join\n"+
			"string has `controller.api.url` and the fingerprint of the API's certificate.\n"+
			"It needs `controller.api.tls.enabled`.").
		Example("").
		Prints(sampleCreate).
		Check("controller join token list", "", "items.[id={out.id}].uses_left", 1).
		Example("--expires 24h --uses 10 --labels group=web").
		Check("controller join token list", "",
			"items.[id={out.id}].uses_left", 10, "items.[id={out.id}].labels.group", "web").
		Example("--transport https").
		Check("controller join token list", "", "items.[id={out.id}].uses_left", 1).
		Fails("no expiry", CreateInput{Uses: 1, Transport: "nats"}).
		Fails("a duration that is not one", CreateInput{Expires: "soon", Uses: 1, Transport: "nats"}).
		Fails("no use", CreateInput{Expires: "1h", Uses: 0, Transport: "nats"}).
		Fails("no transport", CreateInput{Expires: "1h", Uses: 1}).
		Fails("a transport that osapi does not have", CreateInput{Expires: "1h", Uses: 1, Transport: "ssh"}).
		Handle(Create),
	command.Method[ListInput, ListOutput]("list").
		Sub("token").
		Short("List the join tokens, with their expiry and uses left").
		Example("").
		Prints(sampleList).
		Example("--json").
		Handle(List),
	command.Method[RevokeInput, RevokeOutput]("revoke").
		Sub("token").
		Short("Revoke a join token, so it admits no agent").
		Example("--id 1a2b3c4d").
		Prints(sampleRevoke).
		Check("controller join token list", "", "items.[id=1a2b3c4d]", command.Absent).
		Fails("no id", RevokeInput{}).
		Handle(Revoke),
))

Group is the join group's definition.

Functions

This section is empty.

Types

type CreateInput

type CreateInput struct {
	Expires string            `` /* 133-byte string literal not displayed */
	Uses    int               `` /* 132-byte string literal not displayed */
	Labels  map[string]string `json:"labels"  validate:"omitempty"            doc:"Labels that each agent that joins with the token gets, as key=value"`
	// Transport is how the agent joins: over NATS, or over HTTPS to the API.
	Transport string `` /* 159-byte string literal not displayed */
}

CreateInput is the input of token create.

type CreateOutput

type CreateOutput struct {
	ID        string            `                   json:"id"`
	Token     string            `                   json:"token"`
	Join      string            `                   json:"join"             label:"Join string"`
	ExpiresAt time.Time         `                   json:"expires_at"       label:"Expires"     render:"time"`
	Uses      int               `                   json:"uses"`
	Labels    map[string]string `                   json:"labels,omitempty"`
	// contains filtered or unexported fields
}

CreateOutput is a new token: printed one time, with its join string.

func Create

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

Create makes a token and prints it one time, with its join string.

type Deps

type Deps struct {
	Config config.Config
	Dial   func(ctx context.Context) (jointoken.KV, func(), error)
	Now    func() time.Time
	// Audit writes an entry to the audit log of the controller, or is nil
	// when the controller keeps none.
	Audit func(ctx context.Context, e audit.Entry) error
}

Deps is what the join token commands use: the config, what connects to NATS as the controller does, with a function that closes the connection, and the time.

type ListInput

type ListInput struct{}

ListInput is the input of token list, which has none.

type ListOutput

type ListOutput struct {
	Items []Row `                    json:"items" empty:"No join token admits an agent."`
	// contains filtered or unexported fields
}

ListOutput is each join token.

func List

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

List is each join token, with no secret.

type RevokeInput

type RevokeInput struct {
	ID string `json:"id" validate:"required" doc:"The token, as token list shows it"`
}

RevokeInput names the token to revoke.

type RevokeOutput

type RevokeOutput struct {
	ID string `                   json:"id"`
	// contains filtered or unexported fields
}

RevokeOutput is the revoked token.

func Revoke

func Revoke(
	ctx context.Context,
	d Deps,
	in RevokeInput,
) (RevokeOutput, error)

Revoke removes the token, so it admits no agent.

type Row

type Row struct {
	ID        string            `json:"id"`
	CreatedAt time.Time         `json:"created_at"       label:"Created"   render:"age"`
	ExpiresAt time.Time         `json:"expires_at"       label:"Expires"   render:"time"`
	UsesLeft  int               `json:"uses_left"        label:"Uses left"`
	Labels    map[string]string `json:"labels,omitempty"`
}

Row is one token of list, with no secret.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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