api

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2022 License: Apache-2.0 Imports: 27 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 FromTrustedContext

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

func NewDiscovery

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

func NewGrpcConn

func NewGrpcConn(
	clientName ClientName,
	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(
	clientName ClientName,
	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

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
}

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) 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
}

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

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 Transport

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

Transport is a gRPC transport.

func (*Transport) Endpoint

func (tr *Transport) Endpoint() string

Endpoint returns the transport endpoint.

func (*Transport) Kind

func (tr *Transport) Kind() transport.Kind

Kind returns the transport kind.

func (*Transport) Operation

func (tr *Transport) Operation() string

Operation returns the transport operation.

func (*Transport) ReplyHeader

func (tr *Transport) ReplyHeader() transport.Header

ReplyHeader returns the reply header.

func (*Transport) RequestHeader

func (tr *Transport) RequestHeader() transport.Header

RequestHeader returns the request header.

func (*Transport) SelectFilters

func (tr *Transport) SelectFilters() []selector.Filter

SelectFilters returns the client select filters.

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