api

package
v0.0.0-...-b2ef401 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 8 Imported by: 1 module, 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 api wraps echo.Context in a Context that is also a context.Context, and adapts handlers taking it to the framework's echo signatures.

Index

Constants

View Source
const (
	CertFormatPEM = "pem" // the certificate alone
	CertFormatTar = "tar" // the certificate and its key, as <name>.crt and <name>.key
	CertFormatP12 = "p12" // the certificate, its key and chain, encrypted with Password
)

The formats a certificate downloads as, whatever it was uploaded as.

Variables

This section is empty.

Functions

func DiscoverHandlers

func DiscoverHandlers(r any) map[string]any

DiscoverHandlers wraps r's methods with a known handler signature, keyed by name; Handlers itself is skipped.

func WrapHandler

func WrapHandler(hf HandlerFunc) echo.HandlerFunc

func WrapWebSocket

func WrapWebSocket(wf WebSocketHandlerFunc) func(echo.Context, *websocket.Conn) error

Types

type CORSConfig

type CORSConfig struct {
	AllowOrigins     []string `yaml:"allow_origins"`
	AllowMethods     []string `yaml:"allow_methods"`
	AllowHeaders     []string `yaml:"allow_headers"`
	AllowCredentials bool     `yaml:"allow_credentials"`
	MaxAge           int      `yaml:"max_age"`
}

CORSConfig: empty fields keep echo's permissive defaults; AllowCredentials requires explicit AllowOrigins, since browsers reject credentials against a wildcard.

type CertificateCAResponse

type CertificateCAResponse struct {
	ServerCA string `json:"server_ca"` // PEM
	AgentCA  string `json:"agent_ca"`  // PEM
}

CertificateCAResponse is GET /certificates/ca: the system CAs' certificates, for whatever verifies against them - nginx checking agents, a trust store.

type CertificateCreateResponse

type CertificateCreateResponse struct {
	CertificateID int32 `json:"certificate_id"`
}

type CertificateDownloadRequest

type CertificateDownloadRequest struct {
	Format   string `json:"format" validate:"omitempty,oneof=pem tar p12"`
	Password string `json:"password" validate:"required_if=Format p12"` // the caller's: nothing stores it
}

CertificateDownloadRequest is POST /certificates/:id/download. No format is tar for a certificate with its key, pem for one without.

type CertificateGenerateRequest

type CertificateGenerateRequest struct {
	Name           string `json:"name" validate:"required"`
	CommonName     string `json:"common_name" validate:"required"`
	SubjectAltName string `json:"subject_alt_name"`
	CAID           int32  `json:"ca_id"` // empty: the server CA
}

type CertificateSignRequest

type CertificateSignRequest struct {
	Name           string `json:"name" validate:"required"`
	CSR            string `json:"csr" validate:"required"` // PEM
	CommonName     string `json:"common_name" validate:"required"`
	SubjectAltName string `json:"subject_alt_name"`
	Usage          string `json:"usage" validate:"omitempty,oneof=client server"`
	ValidPeriod    string `json:"valid_period"` // a Go duration, e.g. 720h; empty is the default
}

CertificateSignRequest is POST /certificates/csr: the requester sends a CSR and keeps its private key; the manager's agent CA signs it.

type CertificateSignResponse

type CertificateSignResponse struct {
	CertificateID int32  `json:"certificate_id"`
	Certificate   string `json:"certificate"` // PEM
	ServerCA      string `json:"server_ca"`   // PEM: what the requester trusts the manager by
}

type CertificateUpdateRequest

type CertificateUpdateRequest struct {
	Comments string `json:"comments"`
}

type CertificateUploadRequest

type CertificateUploadRequest struct {
	Type     string `json:"type" form:"type" validate:"required"`
	IsCA     bool   `json:"is_ca" form:"is_ca"`
	Name     string `json:"name" form:"name" validate:"required"`
	Password string `json:"password" form:"password"`
}

type Context

type Context interface {
	echo.Context
	context.Context
	BindQuery() *echo.ValueBinder
	BindPath() *echo.ValueBinder
	BindForm() *echo.ValueBinder
	BindAny(i any) error

	Credential() (*entity.Credential, bool)
	Session() (*entity.Session, bool)
	TraceID() (string, bool)
}

func WrapContext

func WrapContext(c echo.Context) Context

WrapContext adapts an echo.Context into a Context. WrapHandler and WrapWebSocket call it; call it yourself only to serve a handler on a bare echo instance, as a test does.

Deadline, Done and Err, and Value for any key but a string, answer from the request's context as it is at the call, after the middlewares: a goroutine the request started, database/sql's once a query's rows close, may still ask them after the handler returned. The echo half, Value's string keys, Param, Bind and the rest, must not outlive the handler: echo pools its contexts and resets one for the next request. context.WithoutCancel(c) drops the cancellation, not the echo half; work that outlives the request takes what it needs as arguments.

type HandlerFunc

type HandlerFunc func(Context) error

type HelloWorldCreateRequest

type HelloWorldCreateRequest struct {
	Message string `json:"message" form:"message" query:"message" validate:"required"`
}

type LoginRequest

type LoginRequest struct {
	Username string `json:"username" form:"username" validate:"required"`
	Password string `json:"password" form:"password" validate:"required"`
}

type LoginResponse

type LoginResponse struct {
	RequirePasswordReset bool `json:"require_password_reset"`
}

type ReadyzResponse

type ReadyzResponse struct {
	Ready    bool               `json:"ready"`
	Services []ServiceReadiness `json:"services,omitempty"`
}

type ServiceReadiness

type ServiceReadiness struct {
	Name  string `json:"name"`
	Error string `json:"error,omitempty"`
}

type SessionResponse

type SessionResponse struct {
	Metadata             labels.Set `json:"metadata,omitempty"`
	Source               string     `json:"source"`
	Role                 string     `json:"role"`
	APIToken             string     `json:"api_token,omitempty"`
	AgentID              string     `json:"agent_id,omitempty"`
	UserID               int32      `json:"user_id,omitempty"`
	UserName             string     `json:"user_name,omitempty"`
	RequirePasswordReset bool       `json:"require_password_reset"`
	Permissions          []string   `json:"permissions"`
}

type ThrottleConfig

type ThrottleConfig struct {
	RPS       float64 `yaml:"rps"`
	BurstSize int     `yaml:"burst_size"`
}

ThrottleConfig: zeros mean unthrottled.

type UserChangePasswordRequest

type UserChangePasswordRequest struct {
	Password    string `json:"password" validate:"required"`
	OldPassword string `json:"old_password" validate:"required"`
}

type UserCreateRequest

type UserCreateRequest struct {
	Username       string `json:"username" validate:"required"`
	Password       string `json:"password" validate:"required"`
	Title          string `json:"title"`
	FirstName      string `json:"first_name"`
	LastName       string `json:"last_name"`
	Email          string `json:"email"`
	Role           string `json:"role" validate:"required"`
	ChangePassword bool   `json:"change_password"`
}

type UserCreateResponse

type UserCreateResponse struct {
	UserID int32 `json:"user_id"`
}

type UserProfileUpdateRequest

type UserProfileUpdateRequest struct {
	Title     *string `json:"title,omitempty"`
	FirstName *string `json:"first_name,omitempty"`
	LastName  *string `json:"last_name,omitempty"`
	Email     *string `json:"email,omitempty"`
}

UserProfileUpdateRequest has no username or role: the caller cannot change who they are through it.

type UserResetPasswordRequest

type UserResetPasswordRequest struct {
	Password string `json:"password" validate:"required"`
}

type UserUpdateRequest

type UserUpdateRequest struct {
	Username       *string `json:"username,omitempty"`
	Title          *string `json:"title,omitempty"`
	FirstName      *string `json:"first_name,omitempty"`
	LastName       *string `json:"last_name,omitempty"`
	Email          *string `json:"email,omitempty"`
	Role           *string `json:"role,omitempty"`
	ChangePassword *bool   `json:"change_password,omitempty"`
}

UserUpdateRequest: a field left out is left as it is, hence the pointers.

type WebSocketHandlerFunc

type WebSocketHandlerFunc func(Context, *websocket.Conn) error

Jump to

Keyboard shortcuts

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