clconnect

package
v0.32.7 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package clconnect provides generic fx dependency for standard ConnectRPC services.

Index

Constants

This section is empty.

Variables

View Source
var ErrServerPanic = errors.New("server panic")

ErrServerPanic is returned when the server panicked.

Functions

func IdentityFromContext added in v0.21.4

func IdentityFromContext(ctx context.Context) openid.Token

IdentityFromContext returns the identity from context as an OpenID token. If there is no token in the context it returns an empty (anonymous) openid token.

func New

func New[RO, RW any](
	cfg Config,
	logs *zap.Logger,
	ro RO, roc ConstructHandler[RO],
	rw RW, rwc ConstructHandler[RW],
	rcvr *Recoverer,

	logr *Logger,
	valr *validate.Interceptor,

	roTx ROTransacter,
	rwTx RWTransacter,
	joAuth *JWTOPAAuth,
	oryAuth *OryAuth,
) http.Handler

New inits an http handler for the full RPC api.

func Provide

func Provide[RO, RW any](name string) fx.Option

Provide the package components for the DI container.

func ProvideEntTransactors added in v0.19.1

func ProvideEntTransactors[TX EntModelTx, MC EntModelClient[TX]]() fx.Option

ProvideEntTransactors provides the RO transactor.

func ProvideOryAuth added in v0.26.2

func ProvideOryAuth() fx.Option

ProvideOryAuth provides injector for ory-based auth.

func ProvidePgxTransactors added in v0.19.1

func ProvidePgxTransactors() fx.Option

ProvidePgxTransactors provides transactors for pgx transactions.

func TestProvide

func TestProvide[RO, RW, ROC, ROW any](name string) fx.Option

TestProvide provides dependencies for testing.

func WithIdentity added in v0.21.4

func WithIdentity(ctx context.Context, tok openid.Token) context.Context

WithIdentity returns a context with the openid token.

Types

type AuthzInput added in v0.21.0

type AuthzInput struct {
	// Input from the process environment
	Env map[string]any `json:"env"`
	// OpenID token as claims
	Claims openid.Token `json:"claims"`
	// Procedure encodes the full RPC procedure name. e.g: /acme.foo.v1.FooService/Bar
	Procedure string `json:"procedure"`
}

AuthzInput encodes the full input into the authorization (AuthZ) policy system OPA. It should provide ALL data required to make authorization decisions. It should be fully serializable to JSON.

type Config

type Config struct {
	// disables stack trace information in error details
	DisableStackTraceErrorDetails bool `env:"DISABLE_STACK_TRACE_ERROR_DETAILS"`
	// allows configuring the 'env' input field send to the policy, allows for configuring input
	// invariant to the environment
	AuthzPolicyEnvInput string `env:"AUTHZ_POLICY_ENV_INPUT,expand" envDefault:"{}"`

	// PublicRPCProcedures configures the ConnectRPC methods that are plublic. For these procedures a special
	// "anonymous" session will be passed to other middleware.
	PublicRPCProcedures map[string]bool `env:"PUBLIC_RPC_PROCEDURES"`
}

Config configures the components.

type ConstructClient

type ConstructClient[SC any] func(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) SC

ConstructClient is a funct signature that constructs a client.

type ConstructHandler

type ConstructHandler[SH any] func(svc SH, opts ...connect.HandlerOption) (string, http.Handler)

ConstructHandler defines the type for constructing a connectrpc service handler.

type EntModelClient added in v0.19.1

type EntModelClient[TX EntModelTx] interface {
	BeginTx(ctx context.Context, opts *entsql.TxOptions) (TX, error)
}

EntModelClient is a generic type to constraint the model client to those generated by Ent.

type EntModelTx added in v0.19.1

type EntModelTx interface {
	Commit() error
	Rollback() error
}

EntModelTx is a generic type to constraint the tx to those generated by Ent.

type EntROTransactor added in v0.19.1

type EntROTransactor[TX EntModelTx, MC EntModelClient[TX]] struct {
	connect.Interceptor
	// contains filtered or unexported fields
}

EntROTransactor provides an ent tx to the context.

func NewEntROTransactor added in v0.19.1

func NewEntROTransactor[TX EntModelTx, MC EntModelClient[TX]](logs *zap.Logger, mc MC) *EntROTransactor[TX, MC]

NewEntROTransactor its a RO transactor for the model client type.

type EntRWTransactor added in v0.19.1

type EntRWTransactor[TX EntModelTx, MC EntModelClient[TX]] struct {
	connect.Interceptor
	// contains filtered or unexported fields
}

EntRWTransactor provides an ent tx to the context.

func NewEntRWTransactor added in v0.19.1

func NewEntRWTransactor[TX EntModelTx, MC EntModelClient[TX]](logs *zap.Logger, mc MC) *EntRWTransactor[TX, MC]

NewEntRWTransactor its a RW transactor for the model client type.

type JWTOPAAuth added in v0.26.0

type JWTOPAAuth struct {
	connect.Interceptor
	// contains filtered or unexported fields
}

JWTOPAAuth provides authn and authz as an injector.

func NewJWTOPAAuth added in v0.26.0

func NewJWTOPAAuth(
	cfg Config, logs *zap.Logger, authn *clauthn.Authn, authz *clauthz.Authz,
) (lgr *JWTOPAAuth, err error)

NewJWTOPAAuth inits an interceptor that uses JWT for Authn and OPA for Authz.

type Logger added in v0.18.1

type Logger struct {
	connect.Interceptor
	// contains filtered or unexported fields
}

Logger logs RPC calls as an interceptor.

func NewLogger added in v0.18.1

func NewLogger(cfg Config, logs *zap.Logger) *Logger

NewLogger inits the logger.

type Ory added in v0.26.0

type Ory interface {
	// Authenticate implements the authentication logic.
	Authenticate(ctx context.Context, cookie string, allowAnonymous bool) (*orysdk.Session, error)
}

Ory interface provides our interface onto ory.

type OryAuth added in v0.26.0

type OryAuth struct {
	connect.Interceptor
	// contains filtered or unexported fields
}

OryAuth provides authn and authz as an injector.

func NewOryAuth added in v0.26.0

func NewOryAuth(
	cfg Config, logs *zap.Logger, ory Ory,
) (inj *OryAuth, err error)

NewOryAuth inits an interceptor that uses JWT for Authn and OPA for Authz.

func (OryAuth) IsPublicRPCMethod added in v0.26.0

func (l OryAuth) IsPublicRPCMethod(spec connect.Spec) bool

IsPublicRPCProcedure returns true if a request is done to public rpc method.

type PgxROTransacter added in v0.19.1

type PgxROTransacter struct {
	connect.Interceptor
	// contains filtered or unexported fields
}

PgxROTransacter provides a database transaction in the context.

func NewPgxROTransacter added in v0.19.1

func NewPgxROTransacter(cfg Config, logs *zap.Logger, ro *pgxpool.Pool) *PgxROTransacter

NewPgxROTransacter inits the Transacter.

type PgxRWTransacter added in v0.19.1

type PgxRWTransacter struct {
	connect.Interceptor
	// contains filtered or unexported fields
}

PgxRWTransacter provides a database transaction in the context.

func NewPgxRWTransacter added in v0.19.1

func NewPgxRWTransacter(cfg Config, logs *zap.Logger, rw *pgxpool.Pool) *PgxRWTransacter

NewPgxRWTransacter inits the Transacter.

type ROTransacter added in v0.18.2

type ROTransacter interface {
	connect.Interceptor
	// contains filtered or unexported methods
}

ROTransacter is an interceptor that add read-only transactions to the context.

type RWTransacter added in v0.18.2

type RWTransacter interface {
	connect.Interceptor
	// contains filtered or unexported methods
}

RWTransacter is an interceptor that add read-write transactions to the context.

type Recoverer added in v0.18.1

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

Recoverer allows recovering from panics.

func NewRecoverer added in v0.18.1

func NewRecoverer(cfg Config, logs *zap.Logger) *Recoverer

NewRecoverer inits the recoverer.

type TestMiddleware added in v0.25.1

type TestMiddleware func(next http.Handler) http.Handler

TestMiddleware can be provided in tests to wrap the test http.Handler with middleware.

Directories

Path Synopsis
v1

Jump to

Keyboard shortcuts

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