Documentation
¶
Index ¶
- Constants
- Variables
- type ConfigProvider
- type Handler
- func (h *Handler) API() apigatewaypb.ApiGatewayServiceServer
- func (h *Handler) Addr() string
- func (h *Handler) ExtractOperation(*echo.Context) string
- func (h *Handler) ExtractResource(*echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- func (h *Handler) MatchPriority() int
- func (h *Handler) Name() string
- func (h *Handler) OperationsAPI() longrunningpb.OperationsServer
- func (h *Handler) Reset()
- func (h *Handler) Restore(ctx context.Context, data []byte) error
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) Shutdown(ctx context.Context)
- func (h *Handler) Snapshot(ctx context.Context) []byte
- func (h *Handler) StartWorker(ctx context.Context) error
- type InMemoryBackend
- func (b *InMemoryBackend) CancelOperation(name string) (*emptypb.Empty, error)
- func (b *InMemoryBackend) CloseIdleConnections()
- func (b *InMemoryBackend) CreateAPI(in *apigatewaypb.CreateApiRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) CreateAPIConfig(in *apigatewaypb.CreateApiConfigRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) CreateGateway(in *apigatewaypb.CreateGatewayRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) DataPlane() http.Handler
- func (b *InMemoryBackend) DeleteAPI(in *apigatewaypb.DeleteApiRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) DeleteAPIConfig(in *apigatewaypb.DeleteApiConfigRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) DeleteGateway(in *apigatewaypb.DeleteGatewayRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) DeleteOperation(name string) (*emptypb.Empty, error)
- func (b *InMemoryBackend) GetAPI(name string) (*apigatewaypb.Api, error)
- func (b *InMemoryBackend) GetAPIConfig(in *apigatewaypb.GetApiConfigRequest) (*apigatewaypb.ApiConfig, error)
- func (b *InMemoryBackend) GetGateway(name string) (*apigatewaypb.Gateway, error)
- func (b *InMemoryBackend) GetIamPolicy(resource string, version int32) (*iampb.Policy, error)
- func (b *InMemoryBackend) GetLocation(name string) (*location.Location, error)
- func (b *InMemoryBackend) GetOperation(name string) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) ListAPIConfigs(in *apigatewaypb.ListApiConfigsRequest) (*apigatewaypb.ListApiConfigsResponse, error)
- func (b *InMemoryBackend) ListApis(in *apigatewaypb.ListApisRequest) (*apigatewaypb.ListApisResponse, error)
- func (b *InMemoryBackend) ListGateways(in *apigatewaypb.ListGatewaysRequest) (*apigatewaypb.ListGatewaysResponse, error)
- func (b *InMemoryBackend) ListLocations(in *location.ListLocationsRequest) (*location.ListLocationsResponse, error)
- func (b *InMemoryBackend) ListOperations(in *longrunningpb.ListOperationsRequest) (*longrunningpb.ListOperationsResponse, error)
- func (b *InMemoryBackend) MatchesDataPlane(r *http.Request) bool
- func (b *InMemoryBackend) ProjectIDs() []string
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) SetAllowExternal(allow bool)
- func (b *InMemoryBackend) SetClock(now func() time.Time)
- func (b *InMemoryBackend) SetIamPolicy(in *iampb.SetIamPolicyRequest) (*iampb.Policy, error)
- func (b *InMemoryBackend) SetTiming(t Timing)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) TestIamPermissions(in *iampb.TestIamPermissionsRequest) (*iampb.TestIamPermissionsResponse, error)
- func (b *InMemoryBackend) UpdateAPI(in *apigatewaypb.UpdateApiRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) UpdateAPIConfig(in *apigatewaypb.UpdateApiConfigRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) UpdateGateway(in *apigatewaypb.UpdateGatewayRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) WaitOperation(ctx context.Context, in *longrunningpb.WaitOperationRequest) (*longrunningpb.Operation, error)
- type Provider
- type Settings
- type Timing
Constants ¶
const DefaultPort = 8146
DefaultPort is the dedicated API Gateway listener's default TCP port: control plane (gRPC and REST) and data plane.
const (
// PathPrefix fronts the path-style data-plane URL: /_apigateway/{project}/{location}/{gateway}/{path}.
PathPrefix = "/_apigateway/"
)
Variables ¶
var ErrDestinationNotPermitted = errors.New(
"gcpapigateway: destination is outside loopback and external backends are not allowed",
)
ErrDestinationNotPermitted is returned when a backend or JWKS host resolves outside loopback.
var ErrNilAppContext = errors.New("gcpapigateway: nil app context")
ErrNilAppContext is returned when Init is called with a nil AppContext.
Functions ¶
This section is empty.
Types ¶
type ConfigProvider ¶
type ConfigProvider interface {
GetGCPAPIGatewaySettings() Settings
}
ConfigProvider extracts API Gateway configuration from the AppContext Config.
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
Port int
// contains filtered or unexported fields
}
Handler serves the API Gateway control plane (gRPC and REST) and the gateway data plane on a dedicated listener.
func NewHandler ¶
func NewHandler(backend *InMemoryBackend) *Handler
NewHandler creates a Handler; callers override Port from Settings.
func (*Handler) API ¶
func (h *Handler) API() apigatewaypb.ApiGatewayServiceServer
API returns the control-plane server for in-process callers such as the dashboard proxy.
func (*Handler) ExtractOperation ¶
ExtractOperation is unused: requests never reach the shared router.
func (*Handler) ExtractResource ¶
ExtractResource is unused: requests never reach the shared router.
func (*Handler) GetSupportedOperations ¶
GetSupportedOperations lists the supported gRPC methods.
func (*Handler) Handler ¶
func (h *Handler) Handler() echo.HandlerFunc
Handler returns a 404 handler; the real API is on the dedicated port.
func (*Handler) MatchPriority ¶
MatchPriority is irrelevant because RouteMatcher never matches.
func (*Handler) OperationsAPI ¶
func (h *Handler) OperationsAPI() longrunningpb.OperationsServer
OperationsAPI returns the long-running operations server for in-process callers.
func (*Handler) RouteMatcher ¶
RouteMatcher never matches: API Gateway runs on its own listener.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend holds all API Gateway state under one lock.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend creates an empty backend on the wall clock.
func (*InMemoryBackend) CancelOperation ¶
func (b *InMemoryBackend) CancelOperation(name string) (*emptypb.Empty, error)
CancelOperation cancels a running operation: a create is rolled back, a delete is undone and an update keeps its change. Cancelling a finished operation has no effect.
func (*InMemoryBackend) CloseIdleConnections ¶
func (b *InMemoryBackend) CloseIdleConnections()
CloseIdleConnections releases pooled backend connections.
func (*InMemoryBackend) CreateAPI ¶
func (b *InMemoryBackend) CreateAPI(in *apigatewaypb.CreateApiRequest) (*longrunningpb.Operation, error)
CreateAPI creates an API in the global location.
func (*InMemoryBackend) CreateAPIConfig ¶
func (b *InMemoryBackend) CreateAPIConfig(in *apigatewaypb.CreateApiConfigRequest) (*longrunningpb.Operation, error)
CreateAPIConfig creates an API config; an invalid OpenAPI document leaves it FAILED with the operation failed.
func (*InMemoryBackend) CreateGateway ¶
func (b *InMemoryBackend) CreateGateway(in *apigatewaypb.CreateGatewayRequest) (*longrunningpb.Operation, error)
CreateGateway creates a gateway in a region.
func (*InMemoryBackend) DataPlane ¶
func (b *InMemoryBackend) DataPlane() http.Handler
DataPlane serves requests to gateways.
func (*InMemoryBackend) DeleteAPI ¶
func (b *InMemoryBackend) DeleteAPI(in *apigatewaypb.DeleteApiRequest) (*longrunningpb.Operation, error)
DeleteAPI deletes an API that has no API configs left.
func (*InMemoryBackend) DeleteAPIConfig ¶
func (b *InMemoryBackend) DeleteAPIConfig(in *apigatewaypb.DeleteApiConfigRequest) (*longrunningpb.Operation, error)
DeleteAPIConfig deletes an API config that no gateway serves.
func (*InMemoryBackend) DeleteGateway ¶
func (b *InMemoryBackend) DeleteGateway(in *apigatewaypb.DeleteGatewayRequest) (*longrunningpb.Operation, error)
DeleteGateway deletes a gateway.
func (*InMemoryBackend) DeleteOperation ¶
func (b *InMemoryBackend) DeleteOperation(name string) (*emptypb.Empty, error)
DeleteOperation removes a finished operation.
func (*InMemoryBackend) GetAPI ¶
func (b *InMemoryBackend) GetAPI(name string) (*apigatewaypb.Api, error)
GetAPI returns one API.
func (*InMemoryBackend) GetAPIConfig ¶
func (b *InMemoryBackend) GetAPIConfig(in *apigatewaypb.GetApiConfigRequest) (*apigatewaypb.ApiConfig, error)
GetAPIConfig returns one API config; the full view includes the OpenAPI documents.
func (*InMemoryBackend) GetGateway ¶
func (b *InMemoryBackend) GetGateway(name string) (*apigatewaypb.Gateway, error)
GetGateway returns one gateway.
func (*InMemoryBackend) GetIamPolicy ¶
GetIamPolicy returns the policy of a resource at the requested version.
func (*InMemoryBackend) GetLocation ¶
func (b *InMemoryBackend) GetLocation(name string) (*location.Location, error)
GetLocation returns the global location or a gateway region.
func (*InMemoryBackend) GetOperation ¶
func (b *InMemoryBackend) GetOperation(name string) (*longrunningpb.Operation, error)
GetOperation returns one operation.
func (*InMemoryBackend) ListAPIConfigs ¶
func (b *InMemoryBackend) ListAPIConfigs(in *apigatewaypb.ListApiConfigsRequest) ( *apigatewaypb.ListApiConfigsResponse, error, )
ListAPIConfigs lists the configs of an API.
func (*InMemoryBackend) ListApis ¶
func (b *InMemoryBackend) ListApis(in *apigatewaypb.ListApisRequest) (*apigatewaypb.ListApisResponse, error)
ListApis lists the APIs of a project.
func (*InMemoryBackend) ListGateways ¶
func (b *InMemoryBackend) ListGateways(in *apigatewaypb.ListGatewaysRequest) ( *apigatewaypb.ListGatewaysResponse, error, )
ListGateways lists the gateways of a location, or of every location for "-".
func (*InMemoryBackend) ListLocations ¶
func (b *InMemoryBackend) ListLocations(in *location.ListLocationsRequest) (*location.ListLocationsResponse, error)
ListLocations lists the global location and the gateway regions.
func (*InMemoryBackend) ListOperations ¶
func (b *InMemoryBackend) ListOperations(in *longrunningpb.ListOperationsRequest) ( *longrunningpb.ListOperationsResponse, error, )
ListOperations lists the operations of one location, ordered by name.
func (*InMemoryBackend) MatchesDataPlane ¶
func (b *InMemoryBackend) MatchesDataPlane(r *http.Request) bool
MatchesDataPlane reports whether a request addresses a gateway, by default hostname or by path prefix.
func (*InMemoryBackend) ProjectIDs ¶
func (b *InMemoryBackend) ProjectIDs() []string
ProjectIDs lists the projects that own at least one API, config, gateway or operation, sorted.
func (*InMemoryBackend) Restore ¶
func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
Restore loads a snapshot, replacing all state.
func (*InMemoryBackend) SetAllowExternal ¶
func (b *InMemoryBackend) SetAllowExternal(allow bool)
SetAllowExternal lets gateway backends and remote JWKS URIs reach hosts outside loopback.
func (*InMemoryBackend) SetClock ¶
func (b *InMemoryBackend) SetClock(now func() time.Time)
SetClock replaces the clock lifecycle states, quotas and token validation derive from.
func (*InMemoryBackend) SetIamPolicy ¶
func (b *InMemoryBackend) SetIamPolicy(in *iampb.SetIamPolicyRequest) (*iampb.Policy, error)
SetIamPolicy replaces a policy; a stale etag aborts the call.
func (*InMemoryBackend) SetTiming ¶
func (b *InMemoryBackend) SetTiming(t Timing)
SetTiming replaces the operation durations.
func (*InMemoryBackend) Snapshot ¶
func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
Snapshot serialises APIs, API configs, gateways, policies and operations. Quota counters and cached signing keys are not kept.
func (*InMemoryBackend) TestIamPermissions ¶
func (b *InMemoryBackend) TestIamPermissions( in *iampb.TestIamPermissionsRequest, ) (*iampb.TestIamPermissionsResponse, error)
TestIamPermissions reports the requested API Gateway permissions as granted: the emulator authorises all callers.
func (*InMemoryBackend) UpdateAPI ¶
func (b *InMemoryBackend) UpdateAPI(in *apigatewaypb.UpdateApiRequest) (*longrunningpb.Operation, error)
UpdateAPI updates the display name and labels of an API.
func (*InMemoryBackend) UpdateAPIConfig ¶
func (b *InMemoryBackend) UpdateAPIConfig(in *apigatewaypb.UpdateApiConfigRequest) (*longrunningpb.Operation, error)
UpdateAPIConfig updates the display name and labels of an API config.
func (*InMemoryBackend) UpdateGateway ¶
func (b *InMemoryBackend) UpdateGateway(in *apigatewaypb.UpdateGatewayRequest) (*longrunningpb.Operation, error)
UpdateGateway updates the display name, labels and API config of a gateway.
func (*InMemoryBackend) WaitOperation ¶
func (b *InMemoryBackend) WaitOperation(ctx context.Context, in *longrunningpb.WaitOperationRequest) ( *longrunningpb.Operation, error, )
WaitOperation returns once the operation is done or the timeout passes, whichever comes first.
type Provider ¶
type Provider struct{}
Provider implements service.Provider for API Gateway. It serves gRPC, REST and the gateway data plane on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.
func (*Provider) Init ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init creates the backend and handler; the port is bound in StartWorker.
type Settings ¶
type Settings struct {
Port int `` //nolint:lll // config struct tags are intentionally verbose
/* 256-byte string literal not displayed */
AllowExternalBackend bool `` //nolint:lll // config struct tags are intentionally verbose
/* 308-byte string literal not displayed */
}
Settings holds service-level configuration, embedded in the root CLI as CLI.GCPAPIGateway.
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings returns the settings used when no ConfigProvider is available.
type Timing ¶
Timing controls how long create, update and delete operations take on the backend clock.
func DefaultTiming ¶
func DefaultTiming() Timing
DefaultTiming returns the operation durations used unless a test overrides them.