api

package
v19.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package api contains internal APIs that are shared by agent and server code.

Index

Constants

View Source
const (
	// TraceAgentIDAttr is tracing attribute that holds an agent id.
	TraceAgentIDAttr attribute.Key = "agent_id"
	// TraceAgentTypeAttr is tracing attribute that holds an agent type.
	TraceAgentTypeAttr attribute.Key = "agent_type"

	// AgentKeyFieldName is the field name to log the agent key.
	AgentKeyFieldName = "agent_key"

	JWTAgentk = "gitlab-agent"
	JWTKAS    = "gitlab-kas"

	// JWTAutoFlow is the issuer of every AutoFlow token. Each capability such a token
	// grants gets its own audience below, so that a token cannot be presented as one of
	// another kind: that is the audience restriction mitigation for cross-JWT confusion.
	// See https://www.rfc-editor.org/rfc/rfc8725#section-3.12.
	JWTAutoFlow = "gitlab-autoflow"
	// JWTAutoFlowAgentChannel is the audience of an agent channel token: the send-only
	// capability minted for the AutoFlow module agent an action is invoked on. It names
	// that agent in `sub` and is spent on the module API, over the connection that
	// authenticates it.
	JWTAutoFlowAgentChannel = "gitlab-autoflow-agent-channel"
	// JWTAutoFlowWorkflowChannel is the audience of a workflow channel token: the send-only
	// capability spent on SendToWorkflowChannel, which authorizes it by the workflow token
	// presented alongside rather than by any principal the token names. StartWorkflow
	// returns one per channel in the workflow input, and a module obtains one by exchanging
	// an agent channel token it holds.
	JWTAutoFlowWorkflowChannel = "gitlab-autoflow-workflow-channel"
	// JWTAutoFlowWorkflow is the audience of AutoFlow workflow tokens, the capability handed to
	// the caller of StartWorkflow to manage that workflow. It keeps them cryptographically
	// distinct from every kind of channel token, which only allow sending on one channel.
	JWTAutoFlowWorkflow = "gitlab-autoflow-workflow"

	// FieldManager name for the ones agentk or kas own, see
	// https://kubernetes.io/docs/reference/using-api/server-side-apply/#field-management
	FieldManager = "agentk"

	// AgentKeyPrefix is the prefix to use for labels and annotations owned by kas/agentk.
	// See https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/#syntax-and-character-set.
	// See https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set.
	AgentKeyPrefix     = "agent.gitlab.com"
	AgentIDKey         = AgentKeyPrefix + "/id"
	ConfigProjectIDKey = AgentKeyPrefix + "/config_project_id"
	ProjectIDKey       = AgentKeyPrefix + "/project_id"
	// ProjectKey is the annotation/label key that has a GitLab project full path as its value, e.g. `gitlab-org/gitlab`.
	ProjectKey         = AgentKeyPrefix + "/project"
	CIPipelineIDKey    = AgentKeyPrefix + "/ci_pipeline_id"
	CIJobIDKey         = AgentKeyPrefix + "/ci_job_id"
	UsernameKey        = AgentKeyPrefix + "/username"
	EnvironmentSlugKey = AgentKeyPrefix + "/environment_slug"
	EnvironmentTierKey = AgentKeyPrefix + "/environment_tier"

	// WebSocketMaxMessageSize is an arbitrary historical limit we used from the early days.
	WebSocketMaxMessageSize = 10 * 1024 * 1024
	// GRPCMaxMessageSize is a limit that is under WebSocketMaxMessageSize.
	// Historically we didn't set gRPC limits:
	// - On the server the default value was 4MB.
	// - On the client the default value was 2GB.
	// We use 4MB explicitly to match the historical value.
	GRPCMaxMessageSize = 4 * 1024 * 1024
)

Variables

This section is empty.

Functions

func ParsePositiveID added in v19.4.0

func ParsePositiveID[I int16 | int32 | int64](idStr string) (I, error)

ParsePositiveID parses an ID that fits I. Only positive integers are accepted.

Types

type AgentKey

type AgentKey struct {
	ID   int64
	Type AgentType
}

AgentKey is agent's key consisting of type and id.

func (AgentKey) LogAttr

func (a AgentKey) LogAttr() slog.Attr

func (AgentKey) LogValue

func (a AgentKey) LogValue() slog.Value

func (AgentKey) String

func (a AgentKey) String() string

String returns the string representation of the agent key

type AgentToken

type AgentToken string

AgentToken is agent's bearer access token.

type AgentTokenWithType

type AgentTokenWithType struct {
	Token AgentToken
	Type  AgentType
}

AgentTokenWithType is agent's token and type

type AgentType

type AgentType byte

AgentType is agent's type.

const (
	AgentTypeKubernetes AgentType = iota
	AgentTypeWorkspace
	AgentTypeRunner
	AgentTypeRunnerController
	AgentTypeAutoFlowModule
	AgentTypeAutoFlowBuiltInModule
	AgentTypeUnknown
)

NOTE: AgentTypeKubernetes should always be at the top to ensure backwards compatibility.

func ParseAgentType

func ParseAgentType(s string) (AgentType, error)

ParseAgentType converts a string to an AgentType When parsing an agent type, we only expect real values like `agentk`, `agentw`. If we encounter any other value, we treat it as `AgentTypeUnknown` and raise an error.

func (AgentType) String

func (at AgentType) String() string

String returns the string representation of the agent type

type AutoFlowModuleKey added in v19.3.0

type AutoFlowModuleKey struct {
	// Path is the project where the module is registered.
	// Empty for built-in modules.
	Path string
	// Name is the name of the module.
	Name string
}

AutoFlowModuleKey represents an AutoFlow module identity.

func (AutoFlowModuleKey) String added in v19.3.0

func (k AutoFlowModuleKey) String() string

Jump to

Keyboard shortcuts

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