Documentation
¶
Overview ¶
Package natswebgateway implements the NATS Web Gateway Caddy HTTP handler.
Index ¶
- type CoreSSE
- type DownstreamIdentity
- type Handler
- func (Handler) CaddyModule() caddy.ModuleInfo
- func (h *Handler) Cleanup() error
- func (h *Handler) Provision(ctx caddy.Context) error
- func (h *Handler) Ready() bool
- func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error
- func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
- func (h Handler) Validate() error
- type NATSConnection
- type Parameter
- type Response
- type Route
- type RouteExtensions
- type RouteProfile
- type SecurityContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CoreSSE ¶
type CoreSSE struct {
BufferMessages int `json:"buffer_messages"`
BufferBytes int64 `json:"buffer_bytes"`
HeartbeatInterval caddy.Duration `json:"heartbeat_interval"`
MaxDuration caddy.Duration `json:"max_duration"`
MaxConnections int `json:"max_connections"`
}
CoreSSE declares bounded runtime policy for an ephemeral Core NATS stream.
type DownstreamIdentity ¶
type DownstreamIdentity struct {
Source string `json:"source"`
Header string `json:"header"`
MaxValueBytes int `json:"max_value_bytes"`
}
DownstreamIdentity declares a NATS-authenticated attribute to add to service requests. The configured header is generated by the gateway and can never be populated from the HTTP request.
type Handler ¶
type Handler struct {
NATS NATSConnection `json:"nats"`
RouteProfiles []RouteProfile `json:"route_profiles,omitempty"`
Routes []Route `json:"routes"`
// contains filtered or unexported fields
}
Handler is the NATS Web Gateway Caddy HTTP middleware.
Routes are validated before Caddy begins serving. HTTP-to-NATS execution is introduced by later tasks.
func (Handler) CaddyModule ¶
func (Handler) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information for Handler.
func (*Handler) Cleanup ¶
Cleanup drains and closes only this handler instance's connection. This permits old and new Caddy configurations to overlap safely during reloads.
func (*Handler) Provision ¶
Provision compiles routes and establishes this handler instance's operator connection when at least one route uses it. Protected-only handlers connect lazily with each request's adapted security context.
func (*Handler) Ready ¶
Ready reports whether this instance currently has a usable NATS connection. It is deliberately separate from process liveness.
func (Handler) ServeHTTP ¶
ServeHTTP executes the first matching declared request/reply route. Requests outside this handler's declared surface continue through the Caddy chain.
func (*Handler) UnmarshalCaddyfile ¶
UnmarshalCaddyfile adapts nats_web_gateway route blocks into JSON-equivalent configuration.
type NATSConnection ¶
type NATSConnection struct {
URLs []string `json:"urls"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
ConnectTimeout caddy.Duration `json:"connect_timeout,omitempty"`
ReconnectWait caddy.Duration `json:"reconnect_wait,omitempty"`
MaxReconnects int `json:"max_reconnects,omitempty"`
DrainTimeout caddy.Duration `json:"drain_timeout,omitempty"`
}
NATSConnection declares the operator-owned connection used by routes which do not carry an end-user security context. Protected-route connections are introduced separately with credential adapters.
type Parameter ¶
type Parameter struct {
Source string `json:"source"`
Name string `json:"name"`
Pattern string `json:"pattern"`
}
Parameter declares the sole HTTP source and accepted grammar for a template value.
type Response ¶
type Response struct {
Mode string `json:"mode"`
Headers []string `json:"headers,omitempty"`
ContentType string `json:"content_type,omitempty"`
Representations []string `json:"representations,omitempty"`
NegotiateAccept bool `json:"negotiate_accept,omitempty"`
ServiceErrorStatuses map[string]int `json:"service_error_statuses,omitempty"`
}
Response declares safe HTTP behavior for a NATS reply.
type Route ¶
type Route struct {
Name string `json:"name"`
Path string `json:"path"`
Methods []string `json:"methods"`
Profile string `json:"profile,omitempty"`
Clear []string `json:"clear,omitempty"`
Extend *RouteExtensions `json:"extend,omitempty"`
Subject string `json:"subject"`
Parameters map[string]Parameter `json:"parameters,omitempty"`
RequestHeaders []string `json:"request_headers,omitempty"`
Timeout caddy.Duration `json:"timeout"`
MaxRequestBodyBytes int64 `json:"max_request_body_bytes"`
MaxReplyBytes int64 `json:"max_reply_bytes"`
Response Response `json:"response"`
StreamMode string `json:"stream_mode"`
CoreSSE *CoreSSE `json:"core_sse,omitempty"`
SecurityContext *SecurityContext `json:"security_context,omitempty"`
}
Route declares one bounded HTTP-to-NATS operation.
type RouteExtensions ¶
type RouteExtensions struct {
Parameters map[string]Parameter `json:"parameters,omitempty"`
RequestHeaders []string `json:"request_headers,omitempty"`
ResponseHeaders []string `json:"response_headers,omitempty"`
Representations []string `json:"representations,omitempty"`
ServiceErrorStatuses map[string]int `json:"service_error_statuses,omitempty"`
}
RouteExtensions adds entries to inherited collection fields. Ordinary route fields replace inherited collections; clear removes them before validation.
type RouteProfile ¶
type RouteProfile struct {
Name string `json:"name"`
Extends string `json:"extends,omitempty"`
Route
}
RouteProfile is a named, reusable collection of route policy. Identity and HTTP matching fields deliberately cannot be inherited.
type SecurityContext ¶
type SecurityContext struct {
Mechanism credentials.Mechanism `json:"mechanism"`
MaxCredentialBytes int `json:"max_credential_bytes,omitempty"`
MaxConnections int `json:"max_connections"`
IdleTimeout caddy.Duration `json:"idle_timeout"`
MaxLifetime caddy.Duration `json:"max_lifetime"`
DownstreamIdentity *DownstreamIdentity `json:"downstream_identity,omitempty"`
}
SecurityContext declares credential adaptation and bounded connection ownership for a protected route.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
adr32-example
command
Command adr32-example runs the non-production NATS service used by the local integration environment.
|
Command adr32-example runs the non-production NATS service used by the local integration environment. |
|
auth-callout
command
Command auth-callout is a test-only NATS Auth Callout service backed by OAuth2 token introspection.
|
Command auth-callout is a test-only NATS Auth Callout service backed by OAuth2 token introspection. |
|
auth-echo
command
Command auth-echo is the least-privilege application fixture for OSS-020.
|
Command auth-echo is the least-privilege application fixture for OSS-020. |
|
examples
|
|
|
images-service
command
Command images-service demonstrates a binary NATS service for the gateway configuration in docs/configuration.md.
|
Command images-service demonstrates a binary NATS service for the gateway configuration in docs/configuration.md. |
|
orders-service
command
Command orders-service is a small stateful NATS request/reply service for the gateway configuration shown in docs/configuration.md.
|
Command orders-service is a small stateful NATS request/reply service for the gateway configuration shown in docs/configuration.md. |
|
pets-service
command
Command pets-service runs the non-production REST-style and RPC-style Pets services used by the example and integration environment.
|
Command pets-service runs the non-production REST-style and RPC-style Pets services used by the example and integration environment. |
|
internal
|
|
|
credentials
Package credentials contains mechanism-specific adapters that translate supported HTTP credential presentations into NATS client authentication options.
|
Package credentials contains mechanism-specific adapters that translate supported HTTP credential presentations into NATS client authentication options. |
|
routes
Package routes contains declared-route enforcement and subject construction.
|
Package routes contains declared-route enforcement and subject construction. |
|
translation
Package translation contains the transport-independent HTTP-to-NATS translation core.
|
Package translation contains the transport-independent HTTP-to-NATS translation core. |