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
- func DiscoverHandlers(r any) map[string]any
- func WrapHandler(hf HandlerFunc) echo.HandlerFunc
- func WrapWebSocket(wf WebSocketHandlerFunc) func(echo.Context, *websocket.Conn) error
- type CORSConfig
- type CertificateCAResponse
- type CertificateCreateResponse
- type CertificateDownloadRequest
- type CertificateGenerateRequest
- type CertificateSignRequest
- type CertificateSignResponse
- type CertificateUpdateRequest
- type CertificateUploadRequest
- type Context
- type HandlerFunc
- type HelloWorldCreateRequest
- type LoginRequest
- type LoginResponse
- type ReadyzResponse
- type ServiceReadiness
- type SessionResponse
- type ThrottleConfig
- type UserChangePasswordRequest
- type UserCreateRequest
- type UserCreateResponse
- type UserProfileUpdateRequest
- type UserResetPasswordRequest
- type UserUpdateRequest
- type WebSocketHandlerFunc
Constants ¶
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 ¶
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 ¶
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 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 CertificateUpdateRequest ¶
type CertificateUpdateRequest struct {
Comments string `json:"comments"`
}
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 ¶
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 HelloWorldCreateRequest ¶
type HelloWorldCreateRequest struct {
Message string `json:"message" form:"message" query:"message" validate:"required"`
}
type LoginRequest ¶
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 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 ¶
ThrottleConfig: zeros mean unthrottled.
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.