requestctx

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package requestctx defines typed request context values shared by the server middleware and HTTP controllers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccountCredentialStrategyOrDefault added in v1.1.0

func AccountCredentialStrategyOrDefault(ctx context.Context) account.CredentialStrategy

AccountCredentialStrategyOrDefault returns the credential policy the operator set for this request's account. It is the ceiling a per-request strategy may narrow and may never widen, so an unreadable account resolves to the default rather than to no policy at all.

func AccountIDOrDefault added in v1.1.0

func AccountIDOrDefault(ctx context.Context) string

AccountIDOrDefault returns the account the request runs under, falling back to the canonical account when no authenticated caller set one.

This is the single place that decides the account of a request that carries no key. An unauthenticated gateway still has to attribute usage, apply limits, and select credentials, and it attributes all of them to the default account.

func GetAPIKey

func GetAPIKey(ctx context.Context) (string, bool)

GetAPIKey returns the raw API key from the context.

func GetAPIKeyID

func GetAPIKeyID(ctx context.Context) (string, bool)

GetAPIKeyID returns the API key ID from the context.

func GetAPIKeyModel

func GetAPIKeyModel(ctx context.Context) (*apikey.APIKey, bool)

GetAPIKeyModel returns the API key model from the context.

func GetAccountRecord added in v1.1.0

func GetAccountRecord(ctx context.Context) (*account.Account, bool)

GetAccountRecord returns the account behind the authenticated key. It is absent when the deployment could not read the account, which is not an authentication failure: the key is still valid and the request falls back to the default governing policy.

func GetConsoleSession added in v1.2.0

func GetConsoleSession(ctx context.Context) (grant, subject string, ok bool)

GetConsoleSession returns the console session's grant kind and identity subject. The second return is false when the request carried no console session.

func GetTeamID added in v1.2.0

func GetTeamID(ctx context.Context) string

GetTeamID returns the team the serving key is attributed to. It is empty for a teamless key and for a request that carries no key model, so team attribution and the team budget both read one derivation.

func ReleaseTimeout added in v1.2.1

func ReleaseTimeout(ctx context.Context)

ReleaseTimeout releases the request timing bound. A request that carries no bound releases nothing, so a handler calls it without a check.

func WithAPIKey

func WithAPIKey(ctx context.Context, value string) context.Context

WithAPIKey stores the raw API key in the context.

func WithAPIKeyID

func WithAPIKeyID(ctx context.Context, value string) context.Context

WithAPIKeyID stores the API key ID in the context.

func WithAPIKeyModel

func WithAPIKeyModel(ctx context.Context, value *apikey.APIKey) context.Context

WithAPIKeyModel stores the API key model in the context.

func WithAccountID added in v1.1.0

func WithAccountID(ctx context.Context, value string) context.Context

WithAccountID stores the request account in the context.

func WithAccountRecord added in v1.1.0

func WithAccountRecord(ctx context.Context, value *account.Account) context.Context

WithAccountRecord stores the account behind the authenticated key.

func WithConsoleSession added in v1.2.0

func WithConsoleSession(ctx context.Context, grant, subject string) context.Context

WithConsoleSession stores the grant kind and identity subject of the console session a request arrived with.

func WithTimeoutRelease added in v1.2.1

func WithTimeoutRelease(ctx context.Context, release func()) context.Context

WithTimeoutRelease stores the release of the request timing bound.

Types

type Key

type Key string

Key is the typed context key used for server request metadata.

const (
	// APIKey stores the raw API key for downstream provider-key lookups.
	APIKey Key = "api_key"
	// APIKeyID stores the authenticated Starport API key ID.
	APIKeyID Key = "api_key_id"
	// APIKeyModel stores the authenticated API key model.
	APIKeyModel Key = "api_key_model" // #nosec G101 - context key name, not a credential.
	// AccountID stores the account the request runs under. It is distinct from
	// APIKeyID: many keys can belong to one account.
	AccountID Key = "account_id"
	// AccountRecord stores the account behind the authenticated key. It is the
	// operator's governing record: the credential strategy the request may run
	// under, and the limits it spends against.
	AccountRecord Key = "account_record"
	// ConsoleGrant stores the grant kind that minted a console session, when
	// the request arrived with one. The audit trail reads it to name the
	// actor behind a console mutation.
	ConsoleGrant Key = "console_grant"
	// ConsoleSubject stores who an identity provider said the console caller
	// is. It is empty for the machine-local grants, which prove where the
	// caller is and not who.
	ConsoleSubject Key = "console_subject"
	// TimeoutRelease stores the release of the request timing bound. The
	// middleware owns the bound, so a handler that commits to a long response
	// releases it here instead of clearing a write deadline that leaves the
	// parent context deadline in place.
	TimeoutRelease Key = "timeout_release"
)

Jump to

Keyboard shortcuts

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