...

Package ctx

import "golang.conradwood.net/go-easyops/ctx"
Overview
Index
Subdirectories

Overview ▾

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

const (
    SER_PREFIX_STR = "CTX_SER_STRING"
)

Variables

var (
    SER_PREFIX_BYT = []byte("CTX_SER_BYTE")
)

func AuthTags

func AuthTags(ctx context.Context) []string

get authtags from context

func Context2DetailString

func Context2DetailString(ctx context.Context) string

func Context2String

func Context2String(ctx context.Context) string

for debugging purposes we can convert a context to a human readable string

func DeserialiseContext

func DeserialiseContext(buf []byte) (context.Context, error)

this unmarshals a context from a binary blob into a context. Short for DeserialiseContextWithTimeout()

func DeserialiseContextFromString

func DeserialiseContextFromString(s string) (context.Context, error)

this unmarshals a context from a string into a context. Short for DeserialiseContextFromStringWithTimeout()

func DeserialiseContextFromStringWithTimeout

func DeserialiseContextFromStringWithTimeout(t time.Duration, s string) (context.Context, error)

this unmarshals a context from a string into a context

func DeserialiseContextWithTimeout

func DeserialiseContextWithTimeout(t time.Duration, buf []byte) (context.Context, error)

this unmarshals a context from a binary blob into a context

func GetExperiments

func GetExperiments(ctx context.Context) []*ge.Experiment

func GetLocalState

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

func GetOrganisationID(ctx context.Context) string

get organisationid from context.Session or "" (empty string) if none

func GetRequestID

func GetRequestID(ctx context.Context) string

get requestid from context

func GetSessionID

func GetSessionID(ctx context.Context) string

get sessionid from context or "" (empty string) if none

func HasAuthTag

func HasAuthTag(ctx context.Context, tag string) bool

true if context has given authtag

func Inbound2Outbound

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

func IsContextFromBuilder(ctx context.Context) bool

returns true if this context was build by the builder

func IsDebug

func IsDebug(ctx context.Context) bool

func IsExperimentEnabled

func IsExperimentEnabled(ctx context.Context, name string) bool

func IsSerialisedByBuilder

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

func NewContextBuilder() shared.ContextBuilder

get a new contextbuilder

func SerialiseContext

func SerialiseContext(ctx context.Context) ([]byte, error)

serialise a context to bunch of bytes

func SerialiseContextToString

func SerialiseContextToString(ctx context.Context) (string, error)

serialise a context to bunch of bytes

Subdirectories

Name Synopsis
..
ctxv2
shared