Documentation
¶
Overview ¶
Package oracle defines a simple system for http middleware built around functions with the following signature:
func Wrap(h http.Handler) http.Handler
The middleware are chained together using the middlewareChain type which can wrap the grpc-gateway to augment how it serves the API.
Package oracle is a framework that provides a REST/JSON API defined using a GRPC spec, that communicates with the phylum.
Index ¶
- func AuthCall[K proto.Message, R proto.Message](s *Oracle, ctx context.Context, methodName string, req K, resp R, ...) (R, error)
- func Call[K proto.Message, R proto.Message](s *Oracle, ctx context.Context, methodName string, req K, resp R, ...) (R, error)
- func GetIncomingHeader(ctx context.Context, key string) string
- func MakeTestContext(_ *testing.T) context.Context
- type Config
- func (c *Config) AddAuthCookieForwarder(cookieName string, maxAge int, secure, httpOnly bool) *CookieForwarder
- func (c *Config) AddCookieForwarder(cookieName string, maxAge int, secure, httpOnly bool) *CookieForwarder
- func (c *Config) AddDepTxCookieForwarder(cookieName string, maxAge int, secure, httpOnly bool) *CookieForwarder
- func (c *Config) AddFakeIDP(t *testing.T) (*FakeIDP, error)
- func (c *Config) AddHeaderForwarder(httpHeaderName string) *HeaderForwarder
- func (c *Config) AddJWKOptions(opt ...jwk.Option)
- func (c *Config) SetOTLPEndpoint(endpoint string)
- func (c *Config) SetPublicContentHandlerOrPanic(publicFS embed.FS, prefix string)
- func (c *Config) SetSwaggerHandler(h http.Handler)
- func (c *Config) Valid() error
- type CookieForwarder
- type FakeIDP
- type GrpcGatewayConfig
- type HeaderForwarder
- type Oracle
- func (orc *Oracle) GetClaims(ctx context.Context) (*jwt.Claims, error)
- func (orc *Oracle) GetHealthCheck(ctx context.Context, req *healthcheck.GetHealthCheckRequest) (*healthcheck.GetHealthCheckResponse, error)
- func (orc *Oracle) GetPhylumConfigJSON(ctx context.Context) (string, error)
- func (orc *Oracle) Log(ctx context.Context) *logrus.Entry
- func (orc *Oracle) MakeTestAuthContext(t *testing.T, claims *jwt.Claims) context.Context
- func (orc *Oracle) Snapshot(t *testing.T) []byte
- func (orc *Oracle) StartGateway(ctx context.Context, grpcConfig GrpcGatewayConfig) error
- func (orc *Oracle) TraceContext(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, TraceContextDefer)
- func (orc *Oracle) Tracer() *opttrace.Tracer
- type TestOpt
- type TraceContextDefer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthCall ¶ added in v0.14.4
func AuthCall[K proto.Message, R proto.Message](s *Oracle, ctx context.Context, methodName string, req K, resp R, config ...shiroclient.Config) (R, error)
AuthCall authenticates the request and calls the phylum.
func Call ¶
func Call[K proto.Message, R proto.Message](s *Oracle, ctx context.Context, methodName string, req K, resp R, config ...shiroclient.Config) (R, error)
Call calls the phylum.
func GetIncomingHeader ¶ added in v0.14.4
GetIncomingHeader returns the first value of a specific metadata key from the incoming gRPC context, or an empty string if not found.
Types ¶
type Config ¶
type Config struct { // ListenAddress is an address the oracle HTTP listens on. ListenAddress string `yaml:"listen-address"` // PhylumPath is the the path for the business logic when testing. PhylumPath string `yaml:"phylum-path"` // TODO: PhylumConfigPath is the the path for the bootstrap yaml for when testing. PhylumConfigPath string `yaml:"phylum-config-path"` // GatewayEndpoint is an address to the shiroclient gateway. GatewayEndpoint string `yaml:"gateway-endpoint"` // PhylumServiceName is the app-specific name of the conneted phylum. PhylumServiceName string `yaml:"phylum-service-name"` // ServiceName is the app-specific name of the Oracle. ServiceName string `yaml:"service-name"` // RequestIDHeader is the HTTP header encoding the request ID. RequestIDHeader string `yaml:"request-id-header"` // Version is the oracle version. Version string `yaml:"version"` // TraceOpts are tracing options. TraceOpts []opttrace.Option // Verbose increases logging. Verbose bool `yaml:"verbose"` // EmulateCC emulates chaincode in memory (for testing). EmulateCC bool `yaml:"emulate-cc"` // ForwardedHeaders are user-defined HTTP headers that the gateway passes to the app. ForwardedHeaders []string // InsecureCookies InsecureCookies bool `yaml:"insecure-cookies"` // DiscardUnknown will ignore unknown fields (not throw an error). DiscardUnknown bool `yaml:"discard-unknown"` // contains filtered or unexported fields }
Config configures an oracle.
func (*Config) AddAuthCookieForwarder ¶ added in v0.14.4
func (c *Config) AddAuthCookieForwarder(cookieName string, maxAge int, secure, httpOnly bool) *CookieForwarder
AddAuthCookieForwarder adds cookie authentication.
func (*Config) AddCookieForwarder ¶ added in v0.14.4
func (c *Config) AddCookieForwarder(cookieName string, maxAge int, secure, httpOnly bool) *CookieForwarder
AddCookieForwarder configures a bridge from a gRPC metadata key to an HTTP response cookie. The returned CookieForwarder can be used within your gRPC server methods to set the cookie value by calling its SetValue(ctx, val) method. That value will then appear as an HTTP cookie named cookieName in the final HTTP response.
func (*Config) AddDepTxCookieForwarder ¶ added in v0.14.4
func (c *Config) AddDepTxCookieForwarder(cookieName string, maxAge int, secure, httpOnly bool) *CookieForwarder
AddDepTxCookieForwarder adds dependent transaction cookie..
func (*Config) AddFakeIDP ¶ added in v0.14.4
AddFakeIDP lets you fake an IDP for testing.
func (*Config) AddHeaderForwarder ¶ added in v0.14.4
func (c *Config) AddHeaderForwarder(httpHeaderName string) *HeaderForwarder
AddHeaderForwarder configures a bridge from a gRPC metadata key to an HTTP response header. The returned HeaderForwarder can be used within your gRPC server methods to set the header value by calling its SetValue(ctx, val) method. That value will then appear as an HTTP response header of name httpHeaderName in the final HTTP response.
func (*Config) AddJWKOptions ¶ added in v0.14.4
WithJWKOption adds auth options.
func (*Config) SetOTLPEndpoint ¶
SetOTLPEndpoint is a helper to set the OTLP trace endpoint.
func (*Config) SetPublicContentHandlerOrPanic ¶ added in v0.14.13
SetPublicContentHandler sets the handler for /public/ routes. URL prefix should begin and end with "/" e.g. /v1/public/
func (*Config) SetSwaggerHandler ¶
SetSwaggerHandler configures an endpoint to serve the swagger API.
type CookieForwarder ¶ added in v0.14.4
type CookieForwarder struct {
// contains filtered or unexported fields
}
CookieForwarder holds all the parameters for bridging a gRPC header into an HTTP cookie via the gRPC-Gateway.
type FakeIDP ¶ added in v0.14.4
type FakeIDP struct {
// contains filtered or unexported fields
}
FakeIDP creates fake tokens for authentication.
type GrpcGatewayConfig ¶
type GrpcGatewayConfig interface { // RegisterServiceServer is required to be overidden by the implementation. RegisterServiceServer(grpcServer *grpc.Server) // RegisterServiceClient is required to be overidden by the implementation. RegisterServiceClient(ctx context.Context, grpcCon *grpc.ClientConn, mux *runtime.ServeMux) error }
GrpcGatewayConfig configures the grpc gateway used by the oracle.
type HeaderForwarder ¶ added in v0.14.4
type HeaderForwarder struct {
// contains filtered or unexported fields
}
HeaderForwarder holds parameters for bridging a single gRPC metadata key → one HTTP response header.
type Oracle ¶
type Oracle struct {
// contains filtered or unexported fields
}
Oracle provides services.
func NewTestOracle ¶
NewTestOracle is used to create an oracle for testing.
func (*Oracle) GetClaims ¶ added in v0.14.4
GetClaims returns authenticated claims from the context.
func (*Oracle) GetHealthCheck ¶
func (orc *Oracle) GetHealthCheck(ctx context.Context, req *healthcheck.GetHealthCheckRequest) (*healthcheck.GetHealthCheckResponse, error)
GetHealthCheck checks this service and all dependent services to construct a health report. Returns a grpc error code if a service is down.
func (*Oracle) GetPhylumConfigJSON ¶ added in v0.14.4
GetPhylumConfigJSON retrieves the current phylum configuration.
func (*Oracle) MakeTestAuthContext ¶ added in v0.14.4
MakeTestAuthContext creates a context for testing the oracle, where you can inject an authenticated user context.
func (*Oracle) StartGateway ¶
func (orc *Oracle) StartGateway(ctx context.Context, grpcConfig GrpcGatewayConfig) error
func (*Oracle) TraceContext ¶ added in v0.14.9
func (orc *Oracle) TraceContext(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, TraceContextDefer)
TraceContext adds tracing to a request context.
type TestOpt ¶
type TestOpt func(*testCfg)
TestOpt configures a test oracle.
func WithSnapshot ¶
WithSnapshot restores the test oracle from a snapshot.
type TraceContextDefer ¶ added in v0.14.9
type TraceContextDefer func()
TraceContextDefer is a fuction that must be called to stop the span.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
testservice
|
|
gen/go/proto/hello/v1
Package hellov1 is a reverse proxy.
|
Package hellov1 is a reverse proxy. |