Documentation
¶
Overview ¶
Package gateway is the control-plane gateway (FR-CORE-040): one listener serving every API over HTTP/1.1 REST and gRPC (h2c), routing by path prefix and Host, authenticating callers and recording the request log.
Index ¶
- Constants
- func NewServer(h http.Handler, log *slog.Logger) *http.Server
- type Gateway
- func (g *Gateway) CloseGate(ctx context.Context) error
- func (g *Gateway) GRPCOptions(service string) []grpc.ServerOption
- func (g *Gateway) HandleAdmin(h http.Handler)
- func (g *Gateway) HandleConsole(h http.Handler)
- func (g *Gateway) Hosts() []string
- func (g *Gateway) Middleware(service string, h http.Handler) http.Handler
- func (g *Gateway) OpenGate()
- func (g *Gateway) Register(s emu.Service) error
- func (g *Gateway) Router(service string) emu.Router
- func (g *Gateway) Serve(l net.Listener) error
- func (g *Gateway) ServeFrontend(ctx context.Context, c net.Conn) error
- func (g *Gateway) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (g *Gateway) SetAdminToken(tok string)
- func (g *Gateway) Shutdown(ctx context.Context) error
Constants ¶
const ( AdminTokenHeader = "X-Gcpemu-Admin-Token" AdminTokenCookie = "gcpemu_admin" // AdminTokenQuery is the console URL parameter that sets the cookie. AdminTokenQuery = "token" )
Admin token transport (FR-UI-009, ADR 0006).
const PathHost = "www.googleapis.com"
PathHost is Google's legacy shared API host. Its URLs carry the API in the path (www.googleapis.com/storage/v1/..., /oauth2/v3/certs, the compute selfLink base), which is exactly the gateway's path routing, so it is always served without a host mount.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Gateway ¶
type Gateway struct {
// Faults holds fault-injection rules applied to every request (FR-CORE-060).
Faults fault.Set
// contains filtered or unexported fields
}
Gateway multiplexes REST and gRPC for all services.
func (*Gateway) CloseGate ¶ added in v0.9.0
CloseGate refuses every new non-Admin request as UNAVAILABLE, cancels those in progress, streams included, and waits for their handlers to return, or returns ctx's error when it ends first. The gate stays closed until OpenGate, even on error. An Instance closes it for the length of a Reset or State snapshot restore (#302).
func (*Gateway) GRPCOptions ¶
func (g *Gateway) GRPCOptions(service string) []grpc.ServerOption
GRPCOptions returns interceptors that authenticate and log gRPC calls; service names the owner for per-service servers ("" = look up by method).
func (*Gateway) HandleAdmin ¶
HandleAdmin mounts the admin API (not request-logged; only the Admin token guards it, see SetAdminToken).
func (*Gateway) HandleConsole ¶ added in v0.2.0
HandleConsole mounts the Web console at /console and /console/ (not request-logged; FR-UI-002). Only the Admin token guards it.
func (*Gateway) Hosts ¶
Hosts returns the sorted real hostnames mounted with host routing (e.g. "storage.googleapis.com") plus PathHost; the Google frontend (FR-CORE-043, FR-INT-007) serves exactly these names.
func (*Gateway) Middleware ¶
Middleware authenticates, recovers from panics and logs each HTTP request.
func (*Gateway) OpenGate ¶ added in v0.9.0
func (g *Gateway) OpenGate()
OpenGate serves requests again after CloseGate.
func (*Gateway) ServeFrontend ¶ added in v0.10.0
ServeFrontend serves c, a connection whose TLS the Google front end (internal/frontend) terminated, as plain HTTP/1.1 or prior-knowledge h2c like the API gateway's port. Requests on it arrive with X-Forwarded-Proto: https, so links services render (GCS session URIs, selfLink, mediaLink) use the scheme the client used (#440). The hand-off is in process: no listener exists that a client could reach to claim the marker, and a client-sent X-Forwarded-Proto on the API gateway's port is left as it was.
ServeFrontend returns once the API gateway has closed c, with net.ErrClosed after Shutdown, or with ctx's error if ctx ends before the API gateway accepts c.
func (*Gateway) ServeHTTP ¶
func (g *Gateway) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP dispatches gRPC, host-mode and path-routed requests.
func (*Gateway) SetAdminToken ¶ added in v0.6.0
SetAdminToken makes every Admin API and Web console request present tok (the API gateway is bound beyond loopback); "" turns the guard off. Call it before Serve.