Documentation
¶
Index ¶
- Constants
- func ConfigureEngine(engine *gin.Engine, cfg config.ServerConfig) error
- func ConvertAndSendWatchEvent[T any](c *gin.Context, e watch.Event, target T) bool
- func ConvertWatchEventObject[T any](c *gin.Context, e watch.Event, _ T) (T, bool)
- func ErrorFromWatchEvent(e watch.Event) error
- func FilteredWatchEventType(eventType watch.EventType, matches bool) (watch.EventType, bool)
- func LoggingMiddleware(cfg config.ServerConfig) gin.HandlerFunc
- func NewAuthMiddleware(ctx context.Context, cfg config.ServerConfig, client libClient.Client, ...) gin.HandlerFunc
- func SendSSEWatchError(c *gin.Context, err error)
- func SendSSEWatchEvent[T any](c *gin.Context, eventType watch.EventType, obj T) bool
- func SendSSEWatchStartError(c *gin.Context, err error) bool
- func SetSSEHeaders(c *gin.Context)
- func WriteSSEKeepalive(c *gin.Context) bool
- type AuthMiddlewareOpt
- type ImageStageMap
- type RefreshResourceType
- type Server
- type TagMap
- type WatchEvent
Constants ¶
const ( GroupByImageRepository = "image_repo" GroupByGitRepository = "git_repo" GroupByChartRepository = "chart_repo" OrderByFirstSeen = "first_seen" OrderByTag = "tag" )
const CLIVersionHeader = "X-Kargo-CLI-Version"
CLIVersionHeader is the HTTP header used to convey the CLI version in requests to the API server.
TODO(krancour): Move this closer to CLI-version-checking middleware once it exists.
Variables ¶
This section is empty.
Functions ¶
func ConfigureEngine ¶ added in v1.12.2
func ConfigureEngine(engine *gin.Engine, cfg config.ServerConfig) error
ConfigureEngine applies the settings every Gin engine serving Kargo's API must share, so that an engine built outside this package behaves like the one built within it.
Note: This sets Gin's mode, which is package-level state. Every engine in the process is in release mode as a result, which is what we want of all of them anyway.
func ConvertAndSendWatchEvent ¶ added in v1.11.0
ConvertAndSendWatchEvent converts a watch event's object to the target type and sends it as an SSE event. It handles both unstructured objects (from real clients) and typed objects (from fake clients in tests). Returns true if the caller should continue processing (including on conversion errors), false if the watch should be terminated (write failure or a watch.Error event).
func ConvertWatchEventObject ¶ added in v1.11.0
ConvertWatchEventObject converts a watch event's object to the target type. It handles both unstructured objects (from real clients) and typed objects (from fake clients in tests). Returns the converted object and true if successful, or the zero value and false if conversion failed.
func ErrorFromWatchEvent ¶ added in v1.11.0
ErrorFromWatchEvent maps Kubernetes watch.Error events into client-visible errors that watch handlers can return or stream.
func FilteredWatchEventType ¶ added in v1.11.0
FilteredWatchEventType returns the event type to send for a client-side filtered watch event. Kubernetes server-side selectors send a DELETED event when a previously matching object is modified so it no longer matches; this helper mirrors that behavior for filters we must evaluate in-process.
Because we hold no per-client matched set, we cannot tell whether a non-matching MODIFIED object previously matched, so we emit a synthetic DELETED for every non-matching MODIFIED event — including objects the client never received an ADDED for. This over-emits DELETEs relative to a real server-side selector, but a DELETE for an object the client is not tracking is a harmless no-op. Achieving exact fidelity would require tracking sent object identities per client, which is not worth the complexity here.
func LoggingMiddleware ¶ added in v1.12.0
func LoggingMiddleware(cfg config.ServerConfig) gin.HandlerFunc
LoggingMiddleware returns Gin middleware that records one line per request using Kargo's own logger, so that LOG_LEVEL governs the request log as it governs everything else.
Each line names the actor the request was authenticated as, in the same form used to attribute Promotions and Events, so that a request log can answer who did something and not only where it came from. A request that never authenticated is attributed to EventActorUnknown.
A server error is recorded at error level. A request that was refused is recorded at info level, because a refusal is never routine and is the first thing anyone looks for when a user reports being unable to do something. Everything else is operational detail and recorded at debug level, unless cfg.RequestLogAllEnabled raises it to info level.
The IP address a request came from is recorded only when cfg.RequestLogSourceIPEnabled is set, because it is personal data and is usually better recorded by whatever proxy sits in front of the server. It is resolved by the engine, which ConfigureEngine must have configured.
This must be the outermost middleware, so that the status and any reported error it records are the ones the client actually received.
func NewAuthMiddleware ¶ added in v1.11.0
func NewAuthMiddleware( ctx context.Context, cfg config.ServerConfig, client libClient.Client, opts ...AuthMiddlewareOpt, ) gin.HandlerFunc
NewAuthMiddleware returns an initialized Gin middleware handler for authentication.
func SendSSEWatchError ¶ added in v1.11.0
SendSSEWatchError sends a watch error as an SSE error event. Watch endpoints may have already sent response headers, so HTTP status codes are no longer a reliable way to report expired resource versions after streaming begins.
func SendSSEWatchEvent ¶ added in v1.11.0
SendSSEWatchEvent sends an object as an SSE watch event. Returns true if the caller should continue processing, false if the watch should be terminated (write failure).
func SendSSEWatchStartError ¶ added in v1.11.0
SendSSEWatchStartError sends startup watch errors that are part of the watch protocol as SSE error events. It returns true when the error was handled.
func SetSSEHeaders ¶ added in v1.11.0
SetSSEHeaders configures the standard headers for Server-Sent Events (SSE) streaming on a gin context.
func WriteSSEKeepalive ¶ added in v1.11.0
WriteSSEKeepalive writes a keepalive comment to keep the SSE connection alive. Returns true if successful, false if the write failed.
Types ¶
type AuthMiddlewareOpt ¶ added in v1.11.0
type AuthMiddlewareOpt func(*authMiddleware)
AuthMiddlewareOpt is a functional option for configuring the auth middleware returned by NewAuthMiddleware.
func WithExemptPaths ¶ added in v1.11.0
func WithExemptPaths(paths []string) AuthMiddlewareOpt
WithExemptPaths adds additional exempt paths for the auth middleware. These are added to the default exempt paths, which are /v1beta1/system/public-server-config and /v1beta1/login.
type ImageStageMap ¶ added in v1.8.8
ImageStageMap represents the stages where an image is used
type RefreshResourceType ¶ added in v1.8.8
type RefreshResourceType string
RefreshResourceType represents the type of Kargo resource to refresh. It is exported for use by the CLI, which uses it to identify the resource type requested by the user and to determine how to build the corresponding refresh request.
const ( RefreshResourceTypeClusterConfig RefreshResourceType = "ClusterConfig" RefreshResourceTypeProjectConfig RefreshResourceType = "ProjectConfig" RefreshResourceTypeStage RefreshResourceType = "Stage" RefreshResourceTypeWarehouse RefreshResourceType = "Warehouse" )
RefreshResourceType constants for supported resource types. They are PascalCase representations of the Kargo resource kinds for compatibility purposes with Kubernetes REST mappers.
func (RefreshResourceType) IsNamespaced ¶ added in v1.8.8
func (t RefreshResourceType) IsNamespaced() bool
IsNamespaced returns true if the resource type is namespaced.
func (RefreshResourceType) NameEqualsProject ¶ added in v1.8.8
func (t RefreshResourceType) NameEqualsProject() bool
NameEqualsProject returns true if the name of the resource should be the same as the project name. This is true for ProjectConfig resources.
func (RefreshResourceType) String ¶ added in v1.8.8
func (t RefreshResourceType) String() string
String returns the string representation of the RefreshResourceType.
type Server ¶
func NewServer ¶
func NewServer( cfg config.ServerConfig, kubeClient kubernetes.Client, rolesDB rbac.RolesDatabase, sender event.Sender, ) Server
type TagMap ¶ added in v1.8.8
type TagMap struct {
Tags map[string]*ImageStageMap `json:"tags"`
} // @name TagMap
TagMap represents the tags for a repository
type WatchEvent ¶ added in v1.8.8
WatchEvent represents a watch event in an SSE stream. It contains the event type (ADDED, MODIFIED, DELETED) and the object that was affected.
Source Files
¶
- abort_promotion.go
- abort_verification.go
- admin_login.go
- approve_freight.go
- auth_middleware.go
- body_limit_middleware.go
- common.go
- create_api_token.go
- create_config_map.go
- create_generic_credentials.go
- create_repo_credentials.go
- create_resource.go
- create_role.go
- delete_analysistemplate.go
- delete_api_token.go
- delete_cluster_config.go
- delete_clusteranalysistemplate.go
- delete_config_map.go
- delete_freight.go
- delete_generic_credentials.go
- delete_project.go
- delete_project_config.go
- delete_repo_credentials.go
- delete_resource.go
- delete_role.go
- delete_stage.go
- delete_warehouse.go
- engine.go
- get_analysisrun.go
- get_analysisrun_logs.go
- get_analysistemplate.go
- get_api_token.go
- get_cluster_config.go
- get_cluster_promotion_task.go
- get_clusteranalysistemplate.go
- get_config.go
- get_config_map.go
- get_controller_heartbeats.go
- get_freight.go
- get_freight_links.go
- get_generic_credentials.go
- get_project.go
- get_project_config.go
- get_promotion.go
- get_promotion_request.go
- get_promotion_task.go
- get_public_config.go
- get_repo_credentials.go
- get_role.go
- get_stage.go
- get_stage_links.go
- get_target.go
- get_version_info.go
- get_warehouse.go
- grant.go
- health.go
- list_analysistemplates.go
- list_api_tokens.go
- list_cluster_promotion_tasks.go
- list_clusteranalysistemplates.go
- list_config_maps.go
- list_for_watch_seed.go
- list_generic_credentials.go
- list_images.go
- list_project_events.go
- list_projects.go
- list_promotion_requests.go
- list_promotion_tasks.go
- list_promotions.go
- list_repo_credentials.go
- list_roles.go
- list_stages.go
- list_targets.go
- list_warehouses.go
- logging_middleware.go
- patch_config_map.go
- patch_generic_credentials.go
- patch_repo_credentials.go
- project_middleware.go
- promote_downstream.go
- promote_to_stage.go
- query_freight.go
- recovery_middleware.go
- refresh_cluster_config.go
- refresh_project_config.go
- refresh_promotion.go
- refresh_stage.go
- refresh_warehouse.go
- resource_version.go
- rest_router.go
- reverify.go
- revoke.go
- server.go
- update_config_map.go
- update_freight_alias.go
- update_generic_credentials.go
- update_repo_credentials.go
- update_resource.go
- update_role.go
- validators.go
- watch_helpers.go