oracle

package
v0.14.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2025 License: BSD-3-Clause Imports: 46 Imported by: 2

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

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

func GetIncomingHeader(ctx context.Context, key string) string

GetIncomingHeader returns the first value of a specific metadata key from the incoming gRPC context, or an empty string if not found.

func MakeTestContext added in v0.14.4

func MakeTestContext(_ *testing.T) context.Context

MakeTestContext creates a context used for testing the oracle. There is no autentication injected.

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 DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default config.

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

func (c *Config) AddFakeIDP(t *testing.T) (*FakeIDP, error)

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

func (c *Config) AddJWKOptions(opt ...jwk.Option)

WithJWKOption adds auth options.

func (*Config) SetOTLPEndpoint

func (c *Config) SetOTLPEndpoint(endpoint string)

SetOTLPEndpoint is a helper to set the OTLP trace endpoint.

func (*Config) SetPublicContentHandlerOrPanic added in v0.14.13

func (c *Config) SetPublicContentHandlerOrPanic(publicFS embed.FS, prefix string)

SetPublicContentHandler sets the handler for /public/ routes. URL prefix should begin and end with "/" e.g. /v1/public/

func (*Config) SetSwaggerHandler

func (c *Config) SetSwaggerHandler(h http.Handler)

SetSwaggerHandler configures an endpoint to serve the swagger API.

func (*Config) Valid

func (c *Config) Valid() error

Valid validates an oracle configuration.

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.

func (*CookieForwarder) GetValue added in v0.14.4

func (cf *CookieForwarder) GetValue(ctx context.Context) (string, error)

GetValue retrieves the given value from the gRPC metadata for the forwarder's configured header.

func (*CookieForwarder) SetValue added in v0.14.4

func (cf *CookieForwarder) SetValue(ctx context.Context, val string) context.Context

SetValue sets the given value into gRPC metadata with the forwarder's configured header. The gRPC-Gateway can then turn it into a cookie on the response.

type FakeIDP added in v0.14.4

type FakeIDP struct {
	// contains filtered or unexported fields
}

FakeIDP creates fake tokens for authentication.

func (*FakeIDP) MakeFakeIDPAuthToken added in v0.14.4

func (f *FakeIDP) MakeFakeIDPAuthToken(claims *jwt.Claims) (string, error)

MakeFakeIDPAuthToken generates a token given a set of claims. *IMPORTANT*: only use for testing!

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.

func (*HeaderForwarder) GetValue added in v0.14.4

func (hf *HeaderForwarder) GetValue(ctx context.Context) (string, error)

GetValue retrieves the header. It first returns the cached value (if set) to support "read your own writes", and falls back to reading the incoming header otherwise.

func (*HeaderForwarder) SetValue added in v0.14.4

func (hf *HeaderForwarder) SetValue(ctx context.Context, val string) context.Context

SetValue places the given value in the gRPC metadata under the grpcHeaderKey and also caches it in the context for "read your own write" behavior.

type Oracle

type Oracle struct {
	// contains filtered or unexported fields
}

Oracle provides services.

func NewOracle

func NewOracle(config *Config) (*Oracle, error)

NewOracle allocates an oracle

func NewTestOracle

func NewTestOracle(t *testing.T, cfg *Config, testOpts ...TestOpt) (*Oracle, func())

NewTestOracle is used to create an oracle for testing.

func (*Oracle) GetClaims added in v0.14.4

func (orc *Oracle) GetClaims(ctx context.Context) (*jwt.Claims, error)

GetClaims returns authenticated claims from the context.

func (*Oracle) GetHealthCheck

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

func (orc *Oracle) GetPhylumConfigJSON(ctx context.Context) (string, error)

GetPhylumConfigJSON retrieves the current phylum configuration.

func (*Oracle) Log added in v0.14.4

func (orc *Oracle) Log(ctx context.Context) *logrus.Entry

Log returns a logger for the oracle.

func (*Oracle) MakeTestAuthContext added in v0.14.4

func (orc *Oracle) MakeTestAuthContext(t *testing.T, claims *jwt.Claims) context.Context

MakeTestAuthContext creates a context for testing the oracle, where you can inject an authenticated user context.

func (*Oracle) Snapshot

func (orc *Oracle) Snapshot(t *testing.T) []byte

Snapshot takes a snapshot of the current oracle.

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.

func (*Oracle) Tracer added in v0.14.4

func (orc *Oracle) Tracer() *opttrace.Tracer

Tracer traces requests.

type TestOpt

type TestOpt func(*testCfg)

TestOpt configures a test oracle.

func WithSnapshot

func WithSnapshot(b []byte) TestOpt

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.

Directories

Path Synopsis
testservice
gen/go/proto/hello/v1
Package hellov1 is a reverse proxy.
Package hellov1 is a reverse proxy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL