interceptors

package
v0.0.0-...-b9c5443 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CtxMSPIDKey is the identifier of the MSPID in context.
	// Prefer the convenient ExtractMSPID method to retrieve the MSPID from context.
	CtxMSPIDKey = &ctxMSPIDMarker{}
)
View Source
var IgnoredMethods = [...]string{
	"grpc.health",
}
View Source
var RequestIDMarker = &requestIDMarker{}

RequestIDMarker is the identifier of the RequestID in context.

Functions

func ExtractChannel

func ExtractChannel(ctx context.Context) (string, error)

ExtractChannel retrieves channel from request context channel is expected to be set by InterceptChannel

func ExtractMSPID

func ExtractMSPID(ctx context.Context) (string, error)

ExtractMSPID retrieves MSPID from request context MSPID is expected to be set by InterceptMSPID

func GetLastError

func GetLastError(ctx context.Context) error

GetLastError returns the last error in a retry context

func GetRequestID

func GetRequestID(ctx context.Context) string

GetRequestID extracts the request ID from context. Returns an empty string if context does not contain an ID.

func InterceptRequestID

func InterceptRequestID(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

InterceptRequestID adds a unique identifier to the context. This identifier is retrieved from query header "reqid" and is generated if there is no such header.

func InterceptStandaloneErrors

func InterceptStandaloneErrors(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

InterceptStandaloneErrors is a gRPC interceptor which converts orchestration errors into nice gRPC ones. This allows clients to properly take action based on the returned status.

func StreamServerLoggerInterceptor

func StreamServerLoggerInterceptor(
	srv interface{},
	stream grpc.ServerStream,
	info *grpc.StreamServerInfo,
	handler grpc.StreamHandler,
) error

StreamServerLoggerInterceptor adds a logger to the context.

func StreamServerRequestLogger

func StreamServerRequestLogger(
	srv interface{},
	stream grpc.ServerStream,
	info *grpc.StreamServerInfo,
	handler grpc.StreamHandler,
) error

StreamServerRequestLogger logs gRPC responses

func UnaryServerLoggerInterceptor

func UnaryServerLoggerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

UnaryServerLoggerInterceptor adds a logger to the context.

func UnaryServerRequestLogger

func UnaryServerRequestLogger(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

UnaryServerRequestLogger log every gRPC response

func WithChannel

func WithChannel(ctx context.Context, channel string) context.Context

WithChannel add channel information to a context

func WithLastError

func WithLastError(ctx context.Context, err error) context.Context

WithLastError adds last error to the context

Types

type ChannelInterceptor

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

ChannelInterceptor intercepts gRPC requests and makes the channel from headers available to request context. It will return an error if a caller attempts to call the orchestrator for a channel it is not part of.

func NewChannelInterceptor

func NewChannelInterceptor(config *common.OrchestratorConfiguration) *ChannelInterceptor

NewChannelInterceptor creates a ChannelInterceptor which will enforce organization & channel consistency. ChannelInterceptor MUST come after the mspid interceptor.

func (*ChannelInterceptor) StreamServerInterceptor

func (i *ChannelInterceptor) StreamServerInterceptor(
	srv interface{},
	stream grpc.ServerStream,
	info *grpc.StreamServerInfo,
	handler grpc.StreamHandler,
) error

StreamServerInterceptor will make the channel from headers available from the request context.

func (*ChannelInterceptor) UnaryServerInterceptor

func (i *ChannelInterceptor) UnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

UnaryServerInterceptor will make the channel from headers available from the request context.

type MSPIDInterceptor

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

func NewMSPIDInterceptor

func NewMSPIDInterceptor() (*MSPIDInterceptor, error)

NewMSPIDInterceptor instanciate a new interceptor

func (*MSPIDInterceptor) StreamServerInterceptor

func (i *MSPIDInterceptor) StreamServerInterceptor(
	srv interface{},
	stream grpc.ServerStream,
	info *grpc.StreamServerInfo,
	handler grpc.StreamHandler,
) error

StreamServerInterceptor enforces MSPID presence in context

func (*MSPIDInterceptor) UnaryServerInterceptor

func (i *MSPIDInterceptor) UnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

UnaryServerInterceptor enforces MSPID presence in context

type RetryChecker

type RetryChecker = func(error) bool

RetryChecker determines if a request should be retried. It receives the returned error and elapsed time since first attempt.

type RetryInterceptor

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

RetryInterceptor will retry a failed request according to its checker decision and time budget.

func NewRetryInterceptor

func NewRetryInterceptor(retryBudget time.Duration, checker RetryChecker) *RetryInterceptor

func (*RetryInterceptor) UnaryServerInterceptor

func (ri *RetryInterceptor) UnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

Jump to

Keyboard shortcuts

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