utils

package
v0.0.0-...-2bb1cf3 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2021 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPortKratos is the default port of the Kratos authentication service by ORY
	DefaultPortKratos = 4434
	// DefaultPortKeto is the default port of the Keto autorisation service by ORY
	DefaultPortKeto = 4466

	// DefaultPortCommon is the default port used to hast the service.
	// This is also the configuration expected by the docker image.
	DefaultPortCommon = 6000

	// DefaultPortMonitoring is the default port used for clear-text HTTP
	// serving the /metrics route dedicated to Prometheus exporters.
	DefaultPortMonitoring = 6001
)

Variables

View Source
var (
	// LoggerContext is the builder of a zerolog.Logger that is exposed to the application so that
	// options at the CLI might alter the formatting and the output of the logs.
	LoggerContext = zerolog.
					New(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}).
					With().Timestamp()

	// Logger is a zerolog logger, that can be safely used from any part of the application.
	// It gathers the format and the output.
	Logger = LoggerContext.Logger()
)
View Source
var DefaultDiscovery = NewStaticConfig()

DefaultDiscovery is the default implementation of a discovery. Valued by default to the discovery of test services, all located on localhost and serving default ports.

Functions

func AddLogFlagsToCommand

func AddLogFlagsToCommand(cmd *cobra.Command)

AddLogFlagsToCommand add to cmd a set of persistent flags that will alter the logging behavior of the current process.

func ApplyLogModifiers

func ApplyLogModifiers()

func Connect

func Connect(ctx context.Context, endpoint string, action ActionFunc) error

Connect establishes a connection to the given service and then call the action.

func Dial

func Dial(ctx context.Context, endpoint string) (*grpc.ClientConn, error)

Dial establishes a gRPC connection to the given endpoint using all the mandatory options on the connection (security, behavior)

func DumpJSON

func DumpJSON(x interface{}) error

DumpJSON encodes the argument in JSON and writes the output on os.Stdout

func EncodeStream

func EncodeStream(recv RecvFunc) error

EncodeStream dumps a JSON stream where each line is a JSON-encoded object. EncodeStream is initially intended to dump a gRPC stream in JSON at os.Stdout.

func EncodeWhole

func EncodeWhole(recv RecvFunc) error

EncodeWhole builds an array of all the objects and encodes it in JSON at once. Warning: the whole stream will be buffered!

func JSON2Buf

func JSON2Buf(obj interface{}) []byte

JSON2Buf generates the JSON-encoded form of the given object, stored in the returned byte array. No indentation, no CRLF

func JSON2Str

func JSON2Str(x interface{}) string

JSON2Str generates a string with the JSON representation of the given object. No indentation, everything on one line. Errors ignored.

func NewStreamServerInterceptorZerolog

func NewStreamServerInterceptorZerolog() grpc.StreamServerInterceptor

func NewUnaryServerInterceptorZerolog

func NewUnaryServerInterceptorZerolog() grpc.UnaryServerInterceptor

func OverrideLogID

func OverrideLogID(ID string)

func StatusJSON

func StatusJSON(code int, ID, msg string) error

StatusJSON encodes a standard error structure and then forwards it to DumpJSON

Types

type ActionFunc

type ActionFunc func(ctx context.Context, cli *grpc.ClientConn) error

ActionFunc names the signature of the hook to be called when the gRPC connection has been established.

type ClientConfig

type ClientConfig struct {
	Default TargetConfig `yaml:"default" json:"default"`
	Proxy   TargetConfig `yaml:"proxy" json:"proxy"`
	Maps    TargetConfig `yaml:"maps" json:"maps"`
	Events  TargetConfig `yaml:"events" json:"events"`
	Regions TargetConfig `yaml:"regions" json:"regions"`
	Kratos  TargetConfig `yaml:"kratos" json:"kratos"`
	Keto    TargetConfig `yaml:"keto" json:"keto"`
}

func DefaultClientConfig

func DefaultClientConfig() ClientConfig

DefaultClientConfig

func (*ClientConfig) ApplyToDiscovery

func (cfg *ClientConfig) ApplyToDiscovery() error

ApplyToDiscovery

type EventServiceConfig

type EventServiceConfig struct {
	PathBase string `yaml:"base" json:"base"`
}

type MainConfig

type MainConfig struct {
	Client ClientConfig `yaml:"client" json:"client"`
	Server ServerConfig `yaml:"server" json:"server"`
}

func DefaultConfig

func DefaultConfig() MainConfig

DefaultConfig

func (*MainConfig) LoadFile

func (cfg *MainConfig) LoadFile(path string, must bool) error

LoadFile

type MapServiceConfig

type MapServiceConfig struct {
	PathRepository string `yaml:"repository" json:"repository"`
}

type RecvFunc

type RecvFunc func() (interface{}, error)

RecvFunc names the signature of the hook that consumes an input and returns an object for each PDU received. RecvFunc is initially intended to map any object from a gRPC stream into a generic interface{} that is still JSON-encodable.

type RegionServiceConfig

type RegionServiceConfig struct {
	PathDefs string `yaml:"definitions" json:"definitions"`
	PathLive string `yaml:"live" json:"live"`
}

type RegisterableMonitorable

type RegisterableMonitorable interface {
	// Register must plug the requests handlers of the backend in the grpc.Server
	Register(grpcServer *grpc.Server) error

	// Check must return a status of the whole backend, to be returned to the
	// client for health-check purposes.
	Check(ctx context.Context) grpc_health_v1.HealthCheckResponse_ServingStatus
}

RegisterableMonitorable summaries the expectations on the application backend.

type ServerConfig

type ServerConfig struct {
	EndpointService string `yaml:"bind" json:"bind"`
	EndpointMonitor string `yaml:"monitor" json:"monitor"`
	ServiceType     string `yaml:"type" json:"type"`
	PathKey         string `yaml:"key" json:"key"`
	PathCrt         string `yaml:"cert" json:"cert"`

	MapConfig MapServiceConfig    `yaml:"map" json:"map"`
	EvtConfig EventServiceConfig  `yaml:"evt" json:"evt"`
	RegConfig RegionServiceConfig `yaml:"reg" json:"reg"`
}

type StatelessDiscovery

type StatelessDiscovery interface {
	// Kratos locates an ORY kratos service (Authentication)
	Kratos() (string, error)

	// Keto locates an ORY keto service (Authorisation)
	Keto() (string, error)

	// Map locates map services in Hegemonie
	Map() (string, error)

	// Region locates an hegemonie's region service
	// Please note that those services are typically sharded. Stateless weighted polling
	// is only meaningful when it is necessary to instantiate a new Region.
	Region() (string, error)

	// Event locates an hegemonie's event services
	Event() (string, error)
}

StatelessDiscovery is the simplest form of Discovery API providing one call per type of service. Each call returns either a usable endpoint string or the error that occurred during the discovery process. The implementation of the StatelessDiscovery interface is responsible for the management of its concurrent accesses.

func NewStaticConfig

func NewStaticConfig() StatelessDiscovery

NewStaticConfig instantiates a StaticConfig with the default endpoint value for each service type.

type StaticConfig

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

StaticConfig is a StatelessDiscovery implementation with a different endpoint for each kind of service, configured once in the application.

func (*StaticConfig) Event

func (d *StaticConfig) Event() (string, error)

Event ... see StatelessDiscovery.Event

func (*StaticConfig) Keto

func (d *StaticConfig) Keto() (string, error)

Keto ... see StatelessDiscovery.Keto

func (*StaticConfig) Kratos

func (d *StaticConfig) Kratos() (string, error)

Kratos ... see StatelessDiscovery.Kratos

func (*StaticConfig) Map

func (d *StaticConfig) Map() (string, error)

Map ... see StatelessDiscovery.Map

func (*StaticConfig) Region

func (d *StaticConfig) Region() (string, error)

Region ... see StatelessDiscovery.Region

type TargetConfig

type TargetConfig struct {
	Address string        `yaml:"addr" json:"addr"`
	Timeout time.Duration `yaml:"timeout" json:"timeout"`
	PathKey string        `yaml:"key" json:"key"`
	PathCrt string        `yaml:"cert" json:"cert"`
}

func DefaultTargetConfig

func DefaultTargetConfig() TargetConfig

DefaultTargetConfig

Jump to

Keyboard shortcuts

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