api

package
v0.0.5-0...-8e55a6f Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: Apache-2.0 Imports: 29 Imported by: 26

Documentation

Index

Constants

View Source
const (
	InternalKeyPrefix = "internal-"
	TenantKey         = InternalKeyPrefix + "tenant"
	TenantInfoKey     = InternalKeyPrefix + "tenant-info"
	TenantFilterKey   = InternalKeyPrefix + "tenant-data-filter"
	TenantAutoSetKey  = InternalKeyPrefix + "tenant-data-autoset"
	UserKey           = InternalKeyPrefix + "user"
	ClientKey         = InternalKeyPrefix + "client"
)

Variables

Functions

func ClientPropagation

func ClientPropagation(client *conf.Client, opt *Option, tokenMgr TokenManager, logger log.Logger) middleware.Middleware

func ErrIfUntrusted

func ErrIfUntrusted(ctx context.Context, t TrustedContextValidator) error

func FromTrustedContext

func FromTrustedContext(ctx context.Context) (bool, bool)

func NewClientCfg

func NewClientCfg(clientName ClientName, services *conf.Services) *conf.Client

func NewDiscovery

func NewDiscovery(services *conf.Services, container *di.Container) (registry.Discovery, error)

func NewGrpcConn

func NewGrpcConn(
	clientCfg *conf.Client,
	serviceName string,
	services *conf.Services,
	dis registry.Discovery,
	opt *Option,
	tokenMgr TokenManager,
	logger log.Logger,
	opts []grpc.ClientOption,
) (grpcx.ClientConnInterface, func())

NewGrpcConn create new grpc client from name

func NewHttpClient

func NewHttpClient(
	clientCfg *conf.Client,
	serviceName string,
	services *conf.Services,
	dis registry.Discovery,
	opt *Option,
	tokenMgr TokenManager,
	logger log.Logger,
	opts []http.ClientOption,
) (*http.Client, func())

NewHttpClient create new http client from name

func NewTrustedContext

func NewTrustedContext(ctx context.Context, trust ...bool) context.Context

NewTrustedContext create a trusted (or not) context without propaganda to other services

func ServerPropagation

func ServerPropagation(opt *Option, validator TrustedContextValidator, logger log.Logger) middleware.Middleware

func WithDiscovery

func WithDiscovery(name string) string

Types

type ClientName

type ClientName string

type ClientPropagator

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

func NewClientPropagator

func NewClientPropagator(extractOnly bool, logger log.Logger) *ClientPropagator

func (*ClientPropagator) Extract

func (u *ClientPropagator) Extract(ctx context.Context, headers Header) (context.Context, error)

func (*ClientPropagator) Fields

func (u *ClientPropagator) Fields() []string

func (*ClientPropagator) Inject

func (u *ClientPropagator) Inject(ctx context.Context, carrier Header) error

type ClientTrustedContextValidator

type ClientTrustedContextValidator struct {
}

func (*ClientTrustedContextValidator) Trusted

type Header interface {
	Get(key string) string
	Set(key, value string)
	HasKey(key string) bool
	Keys() []string
}

type HeaderCarrier

type HeaderCarrier map[string]string

func (HeaderCarrier) Get

func (h HeaderCarrier) Get(key string) string

func (HeaderCarrier) HasKey

func (h HeaderCarrier) HasKey(key string) bool

func (HeaderCarrier) Keys

func (h HeaderCarrier) Keys() []string

func (HeaderCarrier) Set

func (h HeaderCarrier) Set(key, value string)

type InMemoryTokenManager

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

InMemoryTokenManager TODO should use centralize authorization server to get jwt

func NewInMemoryTokenManager

func NewInMemoryTokenManager(tokenizer jwt.Tokenizer, logger log.Logger) *InMemoryTokenManager

func (*InMemoryTokenManager) GetOrGenerateToken

func (i *InMemoryTokenManager) GetOrGenerateToken(ctx context.Context, client *conf.Client) (string, error)

type Option

type Option struct {
	Propagators []Propagator
	BypassToken bool
	Insecure    bool
	Subset      *int
}

func NewDefaultOption

func NewDefaultOption(logger log.Logger) *Option

func NewOption

func NewOption(bypassToken bool, propagators ...Propagator) *Option

func (*Option) WithInsecure

func (o *Option) WithInsecure() *Option

func (*Option) WithSubset

func (o *Option) WithSubset(size int) *Option

WithSubset with client disocvery subset size. zero value means subset filter disabled

type Propagator

type Propagator interface {
	Extract(ctx context.Context, carrier Header) (context.Context, error)
	Inject(ctx context.Context, carrier Header) error
	Fields() []string
}

Propagator propagates cross-cutting concerns as key-value text pairs within a carrier that travels in-band across process boundaries to keep same state across services

type SaasPropagator

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

func NewSaasPropagator

func NewSaasPropagator(logger log.Logger) *SaasPropagator

func (*SaasPropagator) Extract

func (s *SaasPropagator) Extract(ctx context.Context, headers Header) (context.Context, error)

func (*SaasPropagator) Fields

func (s *SaasPropagator) Fields() []string

func (*SaasPropagator) Inject

func (s *SaasPropagator) Inject(ctx context.Context, headers Header) error

type TokenManager

type TokenManager interface {
	GetOrGenerateToken(ctx context.Context, client *conf.Client) (token string, err error)
}

type TrustedContextValidator

type TrustedContextValidator interface {
	Trusted(ctx context.Context) (bool, error)
}

TrustedContextValidator validate whether the communication is behind authed gateway or server to server communication

func NewClientTrustedContextValidator

func NewClientTrustedContextValidator() TrustedContextValidator

type UserPropagator

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

func NewUserPropagator

func NewUserPropagator(logger log.Logger) *UserPropagator

func (*UserPropagator) Extract

func (u *UserPropagator) Extract(ctx context.Context, headers Header) (context.Context, error)

func (*UserPropagator) Fields

func (u *UserPropagator) Fields() []string

func (*UserPropagator) Inject

func (u *UserPropagator) Inject(ctx context.Context, carrier Header) error

Jump to

Keyboard shortcuts

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