Package ctx
Package ctx contains methods to build authenticated contexts and retrieve information of them.
Package ctx is a "leaf" package - it is imported from many other goeasyops packages but does not import (many) other goeasyops packages.
This package supports the following usecases:
* Create a new context with an authenticated user from a service (e.g. a web-proxy)
* Create a new context with a user and no service (e.g. a commandline)
* Create a new context from a service without a user (e.g. a service triggering a gRPC periodically)
* Update a context service (unary inbound gRPC interceptor)
Furthermore, go-easyops in general will parse "latest" context version and "latest-1" context versions. That is so that functions such as auth.User(context) return the right thing wether or not called from a service that has been updated or from a service that is not yet on latest. The context version it generates is selected via cmdline switches.
The context returned is ready to be used for outbound calls as-is.
The context also includes a "value" which is only available locally (does not cross gRPC boundaries) but is used to provide information from the context.
Definition of CallingService: the LocalValue contains the service who called us. The context metadata contains this service definition (which in then is transmitted to downstream services)
Contexts are transformed on each RPC. typically this goes like this:
Context is created ( via ContextBuilder() or authremote.Context() ). This context has a localstate and OUTBOUND metadata.
Client calls an RPC
Server transforms inbound context into a new context and adds itself as callingservice ( ctx.inbound2outbound() ). The inbound context has no localstate and INBOUND metadata. The new context has a localstate and OUTBOUND metadata.
Server becomes client, calls another rpc..
- Constants
- Variables
- func AuthTags(ctx context.Context) []string
- func Context2DetailString(ctx context.Context) string
- func Context2String(ctx context.Context) string
- func DeserialiseContext(buf []byte) (context.Context, error)
- func DeserialiseContextFromString(s string) (context.Context, error)
- func DeserialiseContextFromStringWithTimeout(t time.Duration, s string) (context.Context, error)
- func DeserialiseContextWithTimeout(t time.Duration, buf []byte) (context.Context, error)
- func GetExperiments(ctx context.Context) []*ge.Experiment
- func GetLocalState(ctx context.Context) shared.LocalState
- func GetOrganisationID(ctx context.Context) string
- func GetRequestID(ctx context.Context) string
- func GetSessionID(ctx context.Context) string
- func HasAuthTag(ctx context.Context, tag string) bool
- func Inbound2Outbound(in_ctx context.Context, local_service *auth.SignedUser) context.Context
- func IsContextFromBuilder(ctx context.Context) bool
- func IsDebug(ctx context.Context) bool
- func IsExperimentEnabled(ctx context.Context, name string) bool
- func IsSerialisedByBuilder(buf []byte) bool
- func NewContextBuilder() shared.ContextBuilder
- func SerialiseContext(ctx context.Context) ([]byte, error)
- func SerialiseContextToString(ctx context.Context) (string, error)
Package files
context_builder.go
helper.go
query.go
Constants
const (
SER_PREFIX_STR = "CTX_SER_STRING"
)
Variables
var (
SER_PREFIX_BYT = []byte("CTX_SER_BYTE")
)
func AuthTags(ctx context.Context) []string
get authtags from context
func Context2DetailString(ctx context.Context) string
func Context2String(ctx context.Context) string
for debugging purposes we can convert a context to a human readable string
func DeserialiseContext(buf []byte) (context.Context, error)
this unmarshals a context from a binary blob into a context. Short for DeserialiseContextWithTimeout()
func DeserialiseContextFromString(s string) (context.Context, error)
this unmarshals a context from a string into a context. Short for DeserialiseContextFromStringWithTimeout()
func DeserialiseContextFromStringWithTimeout(t time.Duration, s string) (context.Context, error)
this unmarshals a context from a string into a context
func DeserialiseContextWithTimeout(t time.Duration, buf []byte) (context.Context, error)
this unmarshals a context from a binary blob into a context
func GetExperiments(ctx context.Context) []*ge.Experiment
func GetLocalState(ctx context.Context) shared.LocalState
return "localstate" from a context. This is never "nil", but it is not guaranteed that the LocalState interface actually resolves details
func GetOrganisationID(ctx context.Context) string
get organisationid from context.Session or "" (empty string) if none
func GetRequestID(ctx context.Context) string
get requestid from context
func GetSessionID(ctx context.Context) string
get sessionid from context or "" (empty string) if none
func HasAuthTag(ctx context.Context, tag string) bool
true if context has given authtag
func Inbound2Outbound(in_ctx context.Context, local_service *auth.SignedUser) context.Context
we receive a context from gRPC (e.g. in a unary interceptor). To use this context for outbound calls we need to copy the metadata, we also need to add a local callstate for the fancy_picker/balancer/dialer. This is what this function does.
It is intented to convert any (supported) version of context into the current version of this package
func IsContextFromBuilder(ctx context.Context) bool
returns true if this context was build by the builder
func IsDebug(ctx context.Context) bool
func IsExperimentEnabled(ctx context.Context, name string) bool
func IsSerialisedByBuilder(buf []byte) bool
check if 'buf' contains a context, serialised by the builder. a 'true' result implies that it can be deserialised from this package
func NewContextBuilder() shared.ContextBuilder
get a new contextbuilder
func SerialiseContext(ctx context.Context) ([]byte, error)
serialise a context to bunch of bytes
func SerialiseContextToString(ctx context.Context) (string, error)
serialise a context to bunch of bytes
Subdirectories