handlers

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 58 Imported by: 0

Documentation

Overview

Package handlers implements HTTP handlers for the ploy server API.

pull.go implements the "pull resolution" endpoints for fetching diffs. These endpoints help CLI clients resolve run identifiers needed to pull diffs from the server.

Endpoints:

  • POST /v1/runs/{run_id}/pull — resolve repo metadata for a run
  • POST /v1/migs/{mig_id}/pull — resolve repo for a mig (last succeeded/failed)

Index

Constants

View Source
const DefaultMaxBodySize = 1 << 20

DefaultMaxBodySize is the default request body size limit (1 MiB).

Variables

This section is empty.

Functions

func RegisterRoutes

func RegisterRoutes(s *httpserver.Server, st store.Store, bs blobstore.Store, bp *blobpersist.Service, eventsService *events.Service, configHolder *ConfigHolder, tokenSecret string, gitAuth gitauth.Options, snapshots repoSnapshotWriter, registries ...*gitlabtokens.Registry)

RegisterRoutes mounts all HTTP endpoints on the given server.

Types

type ConfigHolder

type ConfigHolder struct {
	// contains filtered or unexported fields
}

ConfigHolder provides thread-safe access to runtime configuration, including global environment variables and typed Hydra overlays. Global env is stored as key → []GlobalEnvVar to support multiple targets per key. Hydra overlays are stored per section (pre_gate, post_gate, mig). Config In entries are section-keyed and synced into hydra overlays.

func NewConfigHolder

func NewConfigHolder(globalEnv map[string][]GlobalEnvVar) *ConfigHolder

NewConfigHolder creates a new config holder with an optional multi-target map of global environment variables.

func (*ConfigHolder) AddBundleMapping

func (h *ConfigHolder) AddBundleMapping(hash, bundleID string)

AddBundleMapping stores a shortHash → bundleID mapping so that the claim mutator can thread server-side bundle references into spec bundle_map.

func (*ConfigHolder) AddConfigIn

func (h *ConfigHolder) AddConfigIn(section string, entry ConfigInEntry)

AddConfigIn adds or replaces an in entry by destination in a section (dedup by dst, sort by dst).

func (*ConfigHolder) DeleteConfigIn

func (h *ConfigHolder) DeleteConfigIn(section, dst string)

DeleteConfigIn removes an in entry by destination from a section.

func (*ConfigHolder) DeleteGlobalEnvVar

func (h *ConfigHolder) DeleteGlobalEnvVar(key string, target domaintypes.GlobalEnvTarget)

DeleteGlobalEnvVar removes a global environment variable by key and target. No-op if the key+target does not exist. Persistence is the caller's responsibility.

func (*ConfigHolder) GetBundleMap

func (h *ConfigHolder) GetBundleMap() map[string]string

GetBundleMap returns a copy of all shortHash → bundleID mappings.

func (*ConfigHolder) GetGlobalEnvAll

func (h *ConfigHolder) GetGlobalEnvAll() map[string][]GlobalEnvVar

GetGlobalEnvAll returns a copy of all global environment entries grouped by key. Each key maps to a slice of entries (one per target).

func (*ConfigHolder) GetGlobalEnvEntries

func (h *ConfigHolder) GetGlobalEnvEntries(key string) []GlobalEnvVar

GetGlobalEnvEntries retrieves all entries for a key (one per target). Returns nil if the key does not exist.

func (*ConfigHolder) GetHydraOverlays

func (h *ConfigHolder) GetHydraOverlays() map[string]*HydraJobConfig

GetHydraOverlays returns a deep copy of all Hydra overlays keyed by section.

func (*ConfigHolder) SetConfigIn

func (h *ConfigHolder) SetConfigIn(section string, entries []ConfigInEntry)

SetConfigIn replaces the in entry set for a section and syncs into hydra overlays.

func (*ConfigHolder) SetGlobalEnvVar

func (h *ConfigHolder) SetGlobalEnvVar(key string, v GlobalEnvVar)

SetGlobalEnvVar sets or updates a global environment variable by key+target. If an entry for this key+target already exists, it is replaced. Persistence to the store is the caller's responsibility.

type ConfigInEntry

type ConfigInEntry struct {
	Entry   string `json:"entry"`
	Dst     string `json:"dst"`
	Section string `json:"section"`
}

ConfigInEntry represents a single global in mount entry with its section.

type GlobalEnvVar

type GlobalEnvVar struct {
	Value  string                      `json:"value"`
	Target domaintypes.GlobalEnvTarget `json:"target"`
	Secret bool                        `json:"secret"`
}

GlobalEnvVar represents a single global environment variable with its metadata. Used by ConfigHolder to track global env entries in memory. The Target field uses a typed enum (GlobalEnvTarget) to prevent typo-class bugs in target routing logic.

type HydraJobConfig

type HydraJobConfig struct {
	Envs map[string]string
	In   []string
	Out  []string
}

HydraJobConfig holds the typed Hydra overlay fields for a single job section. Used by the claim mutator pipeline to merge server-side configuration into the claim spec using per-field merge strategies.

func (*HydraJobConfig) IsEmpty

func (c *HydraJobConfig) IsEmpty() bool

IsEmpty reports whether all fields are empty.

type JobResourcesPayload

type JobResourcesPayload struct {
	CPUConsumedNs     int64 `json:"cpu_consumed_ns,omitempty"`
	DiskConsumedBytes int64 `json:"disk_consumed_bytes,omitempty"`
	MemConsumedBytes  int64 `json:"mem_consumed_bytes,omitempty"`
}

JobResourcesPayload contains per-job container resource consumption metrics.

type JobStatsPayload

type JobStatsPayload struct {
	// JobMeta is the structured gate/build/mig metadata to persist in jobs.meta JSONB.
	// When present, it is validated via contracts.UnmarshalJobMeta before persisting.
	// Empty/null values are treated as "no job meta" (not persisted).
	JobMeta json.RawMessage `json:"job_meta,omitempty"`

	// Metadata contains optional string key-value pairs for run-level context.
	Metadata map[string]string `json:"metadata,omitempty"`

	// DurationMs is the job execution duration in milliseconds (informational).
	DurationMs int64 `json:"duration_ms,omitempty"`

	// Error is an optional terminal error summary provided by node runtime.
	// This is populated for infrastructure/runtime failures where no structured
	// job_meta is available.
	Error string `json:"error,omitempty"`

	// JobResources carries per-job container resource consumption metrics.
	// When present, the handler persists a row in ploy.job_metrics.
	JobResources *JobResourcesPayload `json:"job_resources,omitempty"`
}

JobStatsPayload is the typed structure for the stats field in job completion. This replaces untyped map[string]any decoding at the API boundary, providing schema control over incoming stats payloads.

Wire format example:

{
  "job_meta": { "kind": "gate", "gate": { ... } },
  "metadata": { "reason": "..." },
  "duration_ms": 1234
}

The job_meta field, when present, must be valid per contracts.UnmarshalJobMeta. The metadata field contains string key-value pairs for run-level metadata merging.

func (JobStatsPayload) ErrorMessage

func (p JobStatsPayload) ErrorMessage() string

ErrorMessage returns the terminal error text from stats.error when present.

func (JobStatsPayload) HasJobMeta

func (p JobStatsPayload) HasJobMeta() bool

HasJobMeta returns true if job_meta is present and non-empty. Empty JSON objects ("{}") and null are treated as "no job meta".

func (JobStatsPayload) HasJobResources

func (p JobStatsPayload) HasJobResources() bool

HasJobResources returns true if job_resources is present.

func (JobStatsPayload) ValidateJobMeta

func (p JobStatsPayload) ValidateJobMeta() error

ValidateJobMeta validates the job_meta field using contracts.UnmarshalJobMeta. Returns nil if job_meta is absent/empty or if it passes validation. Returns an error describing the validation failure if job_meta is invalid.

func (JobStatsPayload) ValidateJobResources

func (p JobStatsPayload) ValidateJobResources() error

ValidateJobResources validates non-negative job resource values.

type RepoRunSummary

type RepoRunSummary struct {
	RunID      domaintypes.RunID     `json:"run_id"`
	MigID      domaintypes.MigID     `json:"mig_id"`
	RunStatus  domaintypes.RunStatus `json:"run_status"`
	BaseRef    string                `json:"base_ref"`
	Attempt    int32                 `json:"attempt"`
	StartedAt  *time.Time            `json:"started_at,omitempty"`
	FinishedAt *time.Time            `json:"finished_at,omitempty"`
}

RepoRunSummary is returned by GET /v1/repos/{repo_id}/runs.

type RepoSummary

type RepoSummary struct {
	RepoID     domaintypes.RepoID `json:"repo_id"`
	RepoURL    string             `json:"repo_url"`
	LastRunAt  *time.Time         `json:"last_run_at,omitempty"`
	LastStatus *string            `json:"last_status,omitempty"`
}

RepoSummary is returned by GET /v1/repos.

type RunResponse

type RunResponse struct {
	RunID           domaintypes.RunID     `json:"run_id"`
	RepoID          domaintypes.RepoID    `json:"repo_id"`
	RepoURL         string                `json:"repo_url"`
	BaseRef         string                `json:"base_ref"`
	SourceCommitSHA string                `json:"source_commit_sha,omitempty"`
	Status          domaintypes.RunStatus `json:"status"`
	Attempt         int32                 `json:"attempt"`
	LastError       *string               `json:"last_error,omitempty"`
	CreatedAt       time.Time             `json:"created_at"`
	StartedAt       *time.Time            `json:"started_at,omitempty"`
	FinishedAt      *time.Time            `json:"finished_at,omitempty"`
}

RunResponse represents one runsitory run within a wave for API responses. Exposes repo URL, refs, attempt count, status, error, and timing fields. v1 model: runs stores one runsitory execution; repo_id refers to runs.id.

type WaveRunStarter

type WaveRunStarter struct {
	// contains filtered or unexported fields
}

WaveRunStarter starts execution for queued runs in waves. It implements the wavescheduler.RunStarter interface.

func NewWaveRunStarter

func NewWaveRunStarter(st store.Store, bs blobstore.Store) *WaveRunStarter

NewWaveRunStarter creates a new WaveRunStarter with the given store.

func (*WaveRunStarter) StartQueuedRuns

StartQueuedRuns creates (or advances) job queues for queued runs in a wave.

type WaveSummary

type WaveSummary struct {
	ID         domaintypes.WaveID     `json:"id"`
	MigID      domaintypes.MigID      `json:"mig_id"`
	SpecID     domaintypes.SpecID     `json:"spec_id"`
	CreatedBy  *string                `json:"created_by,omitempty"`
	Status     domaintypes.WaveStatus `json:"status"`
	CreatedAt  string                 `json:"created_at"`
	StartedAt  *string                `json:"started_at,omitempty"`
	FinishedAt *string                `json:"finished_at,omitempty"`
	Counts     *domaintypes.RunCounts `json:"run_counts,omitempty"`
}

Jump to

Keyboard shortcuts

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