clientinfo

package
v0.1.0-alpha4 Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package clientinfo provides gRPC interceptors for acquiring client information from inbound gRPC requests and making that information available via context keys.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StreamClientInterceptor

func StreamClientInterceptor(clientID string) grpc.StreamClientInterceptor

StreamClientInterceptor returns a grpc.StreamClientInterceptor implementation that appends the client identifier to outgoing gRPC metadata under the X-Client-ID key.

func StreamServerInterceptor

func StreamServerInterceptor(fn Extractor) grpc.StreamServerInterceptor

StreamServerInterceptor is a grpc.StreamServerInterceptor implementation that adds a ClientInfo to inbound contexts via the provided Extractor implementation.

func ToContext

func ToContext(ctx context.Context, info ClientInfo) context.Context

ToContext adds the provided ClientInfo to the parent context, returning a new context. It can be retrieved from the context using FromContext.

func UnaryClientInterceptor

func UnaryClientInterceptor(clientID string) grpc.UnaryClientInterceptor

UnaryClientInterceptor returns a grpc.UnaryClientInterceptor implementation that appends the client identifier to outgoing gRPC metadata under the X-Client-ID key.

func UnaryServerInterceptor

func UnaryServerInterceptor(fn Extractor) grpc.UnaryServerInterceptor

UnaryServerInterceptor is a grpc.UnaryServerInterceptor implementation that adds a ClientInfo to inbound contexts via the provided Extractor implementation.

Types

type ClientInfo

type ClientInfo struct {
	ID string
}

The ClientInfo type describes the client as obtained via the inbound gRPC context.

func FromContext

func FromContext(ctx context.Context) ClientInfo

FromContext obtains a ClientInfo instance from the provided context.Context. Returns a zero-value ClientInfo if one does not exist in the context.

func MetadataExtractor

func MetadataExtractor(ctx context.Context) (ClientInfo, error)

MetadataExtractor is an Extractor implementation that attempts to generate a ClientInfo using the inbound context's metadata fields. The client identifier will be taken from the X-Client-ID metadata field.

func TLSExtractor

func TLSExtractor(ctx context.Context) (ClientInfo, error)

TLSExtractor is an Extractor implementation that attempts to generate a ClientInfo using the client's TLS certificate. The client identifier will be the peer's SPIFFE identifier.

type Extractor

type Extractor func(ctx context.Context) (ClientInfo, error)

The Extractor type is a function that generates a ClientInfo based on the content of the provided context. The context should be that of a gRPC request, so details can be obtained via metadata, tls certificates etc.

Jump to

Keyboard shortcuts

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