aviation

package module
v0.0.0-...-a54c0c6 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: Apache-2.0 Imports: 24 Imported by: 4

README

=======================================
``aviation`` -- gRPC Middleware Helpers
=======================================

Overview
--------

Aviation is a set of tools for building services, as a kind of
analogue for what `gimlet <https://github.com/evergreen-ci/gimlet>`_
does for REST services.

Goals
-----

- provide middleware to support common logging, recovery, middleware.

- support basic authentication mechanism for interoperability with
  gimlet services.

Caveats
-------

- aviation does not (and should not!) attempt to support building
  client interceptors.

- aviation should not attempt to wrap gRPC in the way that gimlet
  wraps negroni and gorilla mux.

Documentation

Overview

Package avaiation is a collection of tools to support grpc middleware

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChainStreamServer

func ChainStreamServer(interceptors ...grpc.StreamServerInterceptor) grpc.StreamServerInterceptor

ChainStreamServer creates a single interceptor out of a chain of many interceptors.

Execution is done in left-to-right order, including passing of context. For example ChainUnaryServer(one, two, three) will execute one before two before three. If you want to pass context between interceptors, use WrapServerStream.

Implementation from https://github.com/grpc-ecosystem/go-grpc-middleware/blob/master/chain.go

func ChainUnaryServer

func ChainUnaryServer(interceptors ...grpc.UnaryServerInterceptor) grpc.UnaryServerInterceptor

ChainUnaryServer creates a single interceptor out of a chain of many interceptors.

Execution is done in left-to-right order, including passing of context. For example ChainUnaryServer(one, two, three) will execute one before two before three, and three will see context changes of one and two.

Implementation from https://github.com/grpc-ecosystem/go-grpc-middleware/blob/master/chain.go

func Dial

func Dial(ctx context.Context, opts DialOptions) (*grpc.ClientConn, error)

Dial creates a client connection to a RPC service via gRPC.

func GetCACertPool

func GetCACertPool(cas ...[]byte) (*x509.CertPool, error)

GetCACertPool is a convenience function that creates a cert pool with the given cas and, when possible, the system cert pool. On windows machines, the cert pool will be empty if no cas are passed in.

func GetClientTLSConfig

func GetClientTLSConfig(cas [][]byte, crt, key []byte) (*tls.Config, error)

GetClientTLSConfig creates a creates a client-side TLS configuration based on the given cas, cert, and key. If possible, the system cert pool is combined with the provided cas.

func GetClientTLSConfigFromFiles

func GetClientTLSConfigFromFiles(caFiles []string, crtFile, keyFile string) (*tls.Config, error)

GetClientTLSConfigFromFiles creates a creates a client-side TLS configuration based on the given ca, cert, and key files.

func GetRequestID

func GetRequestID(ctx context.Context) int

GetRequestID returns the unique (monotonically increaseing) ID of the request since startup

func GetRequestStartAt

func GetRequestStartAt(ctx context.Context) time.Time

func GetUser

func GetUser(ctx context.Context) gimlet.User

GetUser returns the user attached to the request. The User object is nil when

func MakeAuthenticationRequiredUnaryInterceptor

func MakeAuthenticationRequiredUnaryInterceptor(um gimlet.UserManager, conf gimlet.UserMiddlewareConfiguration, ignore ...string) grpc.UnaryServerInterceptor

func MakeCertificateUserValidationStreamInterceptor

func MakeCertificateUserValidationStreamInterceptor(um gimlet.UserManager) grpc.StreamServerInterceptor

Return a gRPC UnaryStreamInterceptor which checks the certifcate user's validity against the given user manager.

func MakeCertificateUserValidationUnaryInterceptor

func MakeCertificateUserValidationUnaryInterceptor(um gimlet.UserManager) grpc.UnaryServerInterceptor

Return a gRPC UnaryServerInterceptor which checks the certifcate user's validity against the given user manager.

func MakeConditionalGripStreamInterceptor

func MakeConditionalGripStreamInterceptor(logger grip.Journaler, when func() bool) grpc.StreamServerInterceptor

func MakeConditionalGripUnaryInterceptor

func MakeConditionalGripUnaryInterceptor(logger grip.Journaler, when func() bool) grpc.UnaryServerInterceptor

func MakeGripStreamInterceptor

func MakeGripStreamInterceptor(logger grip.Journaler) grpc.StreamServerInterceptor

func MakeGripUnaryInterceptor

func MakeGripUnaryInterceptor(logger grip.Journaler) grpc.UnaryServerInterceptor

func MakeRetryStreamClientInterceptor

func MakeRetryStreamClientInterceptor(maxRetries int) grpc.StreamClientInterceptor

func MakeRetryUnaryClientInterceptor

func MakeRetryUnaryClientInterceptor(maxRetries int) grpc.UnaryClientInterceptor

func SetRequestID

func SetRequestID(ctx context.Context, id int) context.Context

SetRequesID attaches a request id to a context.

func SetRequestStartAt

func SetRequestStartAt(ctx context.Context, startAt time.Time) context.Context

func SetRequestUser

func SetRequestUser(ctx context.Context, u gimlet.User) context.Context

SetRequestUser adds a user to a context. This function is public to support teasing workflows.

Types

type DialOptions

type DialOptions struct {
	// Address is the RPC address to connect to.
	Address string
	// Retries specifies the number of times the client connection retries
	// an operation before failing.
	Retries int
	// TLSConf is the config for TLS authentication. If TLSConf is
	// specified, CAFile, CrtFile, and KeyFile are ignored. If neither
	// TLSFile nor the certificate files are specified, the connection is
	// created without TLS. (Optional)
	TLSConf *tls.Config
	// CAFiles are the names of the file with the CA certificates for TLS.
	// If specified, CrtFile and KeyFile must also be specified. (Optional)
	CAFiles []string
	// CrtFile is the name of the file with the user certificate for TLS.
	// If specified, CAFiles and KeyFile must also be specified. (Optional)
	CrtFile string
	// KeyFile is the name of the file with the key certificate for TLS. If
	// specified, CAFiles and CrtFile must also be specified. (Optional)
	KeyFile string
	// Username is the username of the API user. If specified, APIKey must
	// also be specified. (Optional)
	Username string
	// APIKey is the API key for user authentication. If specified,
	// Username must also be specified. (Optional)
	APIKey string
	// APIUserHeader is the metadata key for the requester's username. This
	// must be specified if Username and APIKey are specified. (Optional)
	APIUserHeader string
	// APIKeyHeader is the metadata key for the requester's API key. This
	// must be specified if Username and APIKey are specified. (Optional)
	APIKeyHeader string
}

DialOptions describes the options for creating a client connection to a RPC service via gRPC.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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