headers

package
v1.23.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 7 Imported by: 7

Documentation

Index

Constants

View Source
const (
	CallerTypeOperator    = "operator"
	CallerTypeAPI         = "api"
	CallerTypeBackground  = "background"
	CallerTypePreemptable = "preemptable"

	CallerNameSystem = "system"
)
View Source
const (
	ClientNameHeaderName              = "client-name"
	ClientVersionHeaderName           = "client-version"
	SupportedServerVersionsHeaderName = "supported-server-versions"
	SupportedFeaturesHeaderName       = "supported-features"
	SupportedFeaturesHeaderDelim      = ","

	CallerTypeHeaderName = "caller-type"
)
View Source
const (
	ClientNameServer        = "temporal-server"
	ClientNameServerHTTP    = "temporal-server-http"
	ClientNameGoSDK         = "temporal-go"
	ClientNameJavaSDK       = "temporal-java"
	ClientNamePHPSDK        = "temporal-php"
	ClientNameTypeScriptSDK = "temporal-typescript"
	ClientNamePythonSDK     = "temporal-python"
	ClientNameCLI           = "temporal-cli"
	ClientNameUI            = "temporal-ui"

	// ServerVersion value can be changed by the create-tag Github workflow.
	// If you change the var name or move it, be sure to update the workflow.
	ServerVersion = "1.23.1"

	// SupportedServerVersions is used by CLI and inter role communication.
	SupportedServerVersions = ">=1.0.0 <2.0.0"

	// FeatureFollowsNextRunID means that the client supports following next execution run id for
	// completed/failed/timedout completion events when getting the final result of a workflow.
	FeatureFollowsNextRunID = "follows-next-run-id"
)

Variables

View Source
var (
	SystemBackgroundCallerInfo = CallerInfo{
		CallerName: CallerNameSystem,
		CallerType: CallerTypeBackground,
	}
	SystemPreemptableCallerInfo = CallerInfo{
		CallerName: CallerNameSystem,
		CallerType: CallerTypePreemptable,
	}
)
View Source
var (
	// AllFeatures contains all known features. This list is used as the value of the supported
	// features header for internal server requests. There is an assumption that if a feature is
	// defined, then the server itself supports it.
	AllFeatures = strings.Join([]string{
		FeatureFollowsNextRunID,
	}, SupportedFeaturesHeaderDelim)

	SupportedClients = map[string]string{
		ClientNameGoSDK:         "<2.0.0",
		ClientNameJavaSDK:       "<2.0.0",
		ClientNamePHPSDK:        "<2.0.0",
		ClientNameTypeScriptSDK: "<2.0.0",
		ClientNameCLI:           "<2.0.0",
		ClientNameServer:        "<2.0.0",
		ClientNameUI:            "<3.0.0",
	}
)

Functions

func GetClientNameAndVersion added in v1.15.0

func GetClientNameAndVersion(ctx context.Context) (string, string)

GetClientNameAndVersion extracts SDK name and version from context headers

func GetValues

func GetValues(ctx context.Context, headerNames ...string) []string

GetValues returns header values for passed header names. It always returns slice of the same size as number of passed header names.

func NewDefaultVersionChecker added in v1.0.0

func NewDefaultVersionChecker() *versionChecker

NewDefaultVersionChecker constructs a new VersionChecker using default versions from const.

func NewVersionChecker

func NewVersionChecker(supportedClients map[string]string, serverVersion string) *versionChecker

NewVersionChecker constructs a new VersionChecker

func Propagate added in v1.13.0

func Propagate(ctx context.Context) context.Context

Propagate propagates version headers from incoming context to outgoing context. It copies all headers to outgoing context only if they are exist in incoming context and doesn't exist in outgoing context already.

func SetCallerInfo added in v1.17.2

func SetCallerInfo(
	ctx context.Context,
	info CallerInfo,
) context.Context

SetCallerInfo sets callerName, callerType and CallOrigin in the context. Existing values will be overwritten if new value is not empty. TODO: consider only set the caller info to golang context instead of grpc metadata and propagate to grpc outgoing context upon making an rpc call

func SetCallerName added in v1.17.3

func SetCallerName(
	ctx context.Context,
	callerName string,
) context.Context

SetCallerName set caller name in the context. Existing caller name will be overwritten if exists and new caller name is not empty.

func SetCallerType added in v1.17.3

func SetCallerType(
	ctx context.Context,
	callerType string,
) context.Context

SetCallerType set caller type in the context. Existing caller type will be overwritten if exists and new caller type is not empty.

func SetOrigin added in v1.17.3

func SetOrigin(
	ctx context.Context,
	callOrigin string,
) context.Context

SetOrigin set call origin in the context. Existing call origin will be overwritten if exists and new call origin is not empty.

func SetVersions

func SetVersions(ctx context.Context) context.Context

SetVersions sets headers for internal communications.

func SetVersionsForTests

func SetVersionsForTests(ctx context.Context, clientVersion, clientName, supportedServerVersions, supportedFeatures string) context.Context

SetVersionsForTests sets headers as they would be received from the client. Must be used in tests only.

Types

type CallerInfo added in v1.17.2

type CallerInfo struct {
	// CallerName is the name of the caller.
	// It can either user namespace name or
	// the predefined CallerNameSystem.
	CallerName string

	// CallerType indicates if the call originates from
	// user API calls or from system background operations.
	CallerType string

	// CallOrigin is the first API method name in the call chain.
	// Currently, it is only specified when CallerType is CallerTypeAPI
	CallOrigin string
}

func GetCallerInfo added in v1.17.2

func GetCallerInfo(
	ctx context.Context,
) CallerInfo

GetCallerInfo retrieves caller information from the context if exists. Empty value is returned if any piece of caller information is not specified in the context.

func NewBackgroundCallerInfo added in v1.17.3

func NewBackgroundCallerInfo(
	callerName string,
) CallerInfo

NewBackgroundCallerInfo creates a new CallerInfo with Background callerType and empty callOrigin. This is equivalent to NewCallerInfo(callerName, CallerTypeBackground, "")

func NewCallerInfo added in v1.17.2

func NewCallerInfo(
	callerName string,
	callerType string,
	callOrigin string,
) CallerInfo

NewCallerInfo creates a new CallerInfo

func NewPreemptableCallerInfo added in v1.20.1

func NewPreemptableCallerInfo(
	callerName string,
) CallerInfo

NewPreemptableCallerInfo creates a new CallerInfo with Preemptable callerType and empty callOrigin. This is equivalent to NewCallerInfo(callerName, CallerTypePreemptable, "")

type VersionChecker

type VersionChecker interface {
	ClientSupported(ctx context.Context) error
	ClientSupportsFeature(ctx context.Context, feature string) bool
}

VersionChecker is used to check client/server compatibility and client's capabilities

Jump to

Keyboard shortcuts

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