Documentation
¶
Overview ¶
Package remotestate provides the HTTP client, token resolution, plan conversion, and run-ID derivation for orun-backend remote state.
Index ¶
- func BackendJobStatusToLocal(s string) string
- func DeriveRunID(explicitID string) string
- func LocalJobStatusToBackend(s string) string
- type APIError
- type BackendPlan
- type BackendPlanJob
- type BackendPlanStep
- type ClaimJobRequest
- type ClaimJobResponse
- type Client
- func (c *Client) ClaimJob(ctx context.Context, runID, jobID, runnerID string) (*ClaimJobResponse, error)
- func (c *Client) CreateRun(ctx context.Context, req CreateRunRequest) (*RunResponse, error)
- func (c *Client) GetLog(ctx context.Context, runID, jobID string) (string, error)
- func (c *Client) GetRun(ctx context.Context, runID string) (*RunResponse, error)
- func (c *Client) GetRunnable(ctx context.Context, runID string) ([]string, error)
- func (c *Client) Heartbeat(ctx context.Context, runID, jobID, runnerID string) error
- func (c *Client) ListJobs(ctx context.Context, runID string) ([]JobResponse, error)
- func (c *Client) UpdateJob(ctx context.Context, runID, jobID, runnerID, status, errText string) error
- func (c *Client) UploadLog(ctx context.Context, runID, jobID, content string) error
- type CreateRunRequest
- type HeartbeatRequest
- type HeartbeatResponse
- type JobResponse
- type ListJobsResponse
- type LogUploadResponse
- type OIDCTokenSource
- type ResolveOptions
- type ResolvedAuth
- type RunResponse
- type RunnableResponse
- type SessionTokenSource
- type StaticTokenSource
- type TokenSource
- type UpdateJobRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BackendJobStatusToLocal ¶
BackendJobStatusToLocal converts a backend job status string to the local status string used by state.JobState.
func DeriveRunID ¶
DeriveRunID computes the run ID according to the documented precedence:
- explicitID (from --exec-id or ORUN_EXEC_ID)
- GitHub Actions: gha_{GITHUB_RUN_ID}_{GITHUB_RUN_ATTEMPT}
- Local fallback: local_{ts_hex}_{rand_hex}
func LocalJobStatusToBackend ¶
LocalJobStatusToBackend converts a local job status to a backend status value.
Types ¶
type BackendPlan ¶
type BackendPlan struct {
Checksum string `json:"checksum"`
Version string `json:"version"`
Jobs []BackendPlanJob `json:"jobs"`
CreatedAt string `json:"createdAt"`
}
BackendPlan is the plan format expected by the orun-backend CreateRun API.
func ConvertPlan ¶
func ConvertPlan(plan *model.Plan) *BackendPlan
ConvertPlan converts a CLI model.Plan to the BackendPlan format without mutating the original plan.
type BackendPlanJob ¶
type BackendPlanJob struct {
JobID string `json:"jobId"`
Component string `json:"component"`
Deps []string `json:"deps"`
Steps []BackendPlanStep `json:"steps"`
}
BackendPlanJob is a job entry in BackendPlan.
type BackendPlanStep ¶
type BackendPlanStep struct {
StepID string `json:"stepId"`
Uses string `json:"uses"`
With map[string]interface{} `json:"with"`
}
BackendPlanStep is a step entry in BackendPlanJob.
type ClaimJobRequest ¶
type ClaimJobRequest struct {
RunnerID string `json:"runnerId"`
}
ClaimJobRequest is the body for POST /v1/runs/{runID}/jobs/{jobID}/claim.
type ClaimJobResponse ¶
type ClaimJobResponse struct {
Claimed bool `json:"claimed"`
Takeover bool `json:"takeover,omitempty"`
CurrentStatus string `json:"currentStatus,omitempty"`
DepsWaiting bool `json:"depsWaiting,omitempty"`
DepsBlocked bool `json:"depsBlocked,omitempty"`
}
ClaimJobResponse represents the extended coordinator claim result.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an HTTP client for the orun-backend REST API.
func NewClient ¶
func NewClient(baseURL, version string, tokenSrc TokenSource) *Client
NewClient creates a Client for baseURL using the given TokenSource and CLI version.
func (*Client) ClaimJob ¶
func (c *Client) ClaimJob(ctx context.Context, runID, jobID, runnerID string) (*ClaimJobResponse, error)
ClaimJob calls POST /v1/runs/{runID}/jobs/{jobID}/claim. This operation is not retried on 5xx because partial state may exist.
func (*Client) CreateRun ¶
func (c *Client) CreateRun(ctx context.Context, req CreateRunRequest) (*RunResponse, error)
CreateRun calls POST /v1/runs. Idempotent: if the run already exists the backend verifies the plan checksum and returns the existing run.
func (*Client) GetLog ¶
GetLog calls GET /v1/runs/{runID}/logs/{jobID} and returns the log as a string.
func (*Client) GetRunnable ¶
GetRunnable calls GET /v1/runs/{runID}/runnable.
func (*Client) UpdateJob ¶
func (c *Client) UpdateJob(ctx context.Context, runID, jobID, runnerID, status, errText string) error
UpdateJob calls POST /v1/runs/{runID}/jobs/{jobID}/update. Not retried because the backend is idempotent by run+job+runner identity and a duplicate terminal update is harmless.
type CreateRunRequest ¶
type CreateRunRequest struct {
Plan *BackendPlan `json:"plan"`
RunID string `json:"runId,omitempty"`
NamespaceID string `json:"namespaceId,omitempty"`
RepoFullName string `json:"repoFullName,omitempty"`
DryRun bool `json:"dryRun,omitempty"`
TriggerType string `json:"triggerType,omitempty"`
Actor string `json:"actor,omitempty"`
}
CreateRunRequest is the body for POST /v1/runs.
type HeartbeatRequest ¶
type HeartbeatRequest struct {
RunnerID string `json:"runnerId"`
}
HeartbeatRequest is the body for POST /v1/runs/{runID}/jobs/{jobID}/heartbeat.
type HeartbeatResponse ¶
type HeartbeatResponse struct {
OK bool `json:"ok"`
}
HeartbeatResponse is returned by the heartbeat endpoint.
type JobResponse ¶
type JobResponse struct {
JobID string `json:"jobId"`
RunID string `json:"runId"`
Component string `json:"component"`
Status string `json:"status"`
Deps []string `json:"deps"`
RunnerID *string `json:"runnerId"`
StartedAt *string `json:"startedAt"`
FinishedAt *string `json:"finishedAt"`
LastError *string `json:"lastError"`
HeartbeatAt *string `json:"heartbeatAt"`
LogRef *string `json:"logRef"`
}
JobResponse is the backend Job object.
type ListJobsResponse ¶
type ListJobsResponse struct {
Jobs []JobResponse `json:"jobs"`
}
ListJobsResponse wraps the job list from GET /v1/runs/{runID}/jobs.
type LogUploadResponse ¶
LogUploadResponse is returned by POST /v1/runs/{runID}/logs/{jobID}.
type OIDCTokenSource ¶
type OIDCTokenSource struct {
Audience string
// contains filtered or unexported fields
}
OIDCTokenSource requests a GitHub Actions OIDC token from the GitHub Actions token endpoint with the configured audience.
func NewOIDCTokenSource ¶
func NewOIDCTokenSource(audience string) *OIDCTokenSource
NewOIDCTokenSource returns an OIDCTokenSource using the given audience (default "orun" if empty).
type ResolveOptions ¶ added in v1.12.54
type ResolveOptions struct {
BackendURL string
Version string
Interactive bool
RequireLogin bool
NamespaceID string
}
ResolveOptions controls token and namespace resolution.
type ResolvedAuth ¶ added in v1.12.54
type ResolvedAuth struct {
TokenSource TokenSource
NamespaceID string
GitHubLogin string
ResolvedMode string
}
ResolvedAuth describes the selected auth source and optional local namespace.
func ResolveAuth ¶ added in v1.12.54
func ResolveAuth(ctx context.Context, opts ResolveOptions) (*ResolvedAuth, error)
ResolveAuth returns the appropriate remote-state auth information.
type RunResponse ¶
type RunResponse struct {
RunID string `json:"runId"`
Status string `json:"status"`
PlanChecksum string `json:"planChecksum"`
TriggerType string `json:"triggerType"`
Actor *string `json:"actor"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
FinishedAt *string `json:"finishedAt"`
JobTotal int `json:"jobTotal"`
JobDone int `json:"jobDone"`
JobFailed int `json:"jobFailed"`
DryRun bool `json:"dryRun"`
}
RunResponse is the backend Run object returned by /v1/runs/*.
type RunnableResponse ¶
type RunnableResponse struct {
JobIDs []string `json:"jobs"`
}
RunnableResponse is from GET /v1/runs/{runID}/runnable.
type SessionTokenSource ¶ added in v1.12.54
SessionTokenSource resolves and refreshes a local Orun CLI session token.
type StaticTokenSource ¶
type StaticTokenSource struct {
// contains filtered or unexported fields
}
StaticTokenSource returns a pre-configured bearer token as-is.
func NewStaticTokenSource ¶
func NewStaticTokenSource(token string) *StaticTokenSource
NewStaticTokenSource wraps a fixed bearer token (e.g. from ORUN_TOKEN).
type TokenSource ¶
TokenSource resolves the bearer token for backend requests.
func ResolveTokenSource ¶
func ResolveTokenSource(ctx context.Context, opts ResolveOptions) (TokenSource, string, string, error)
ResolveTokenSource returns the remote-state token source plus local namespace.
type UpdateJobRequest ¶
type UpdateJobRequest struct {
RunnerID string `json:"runnerId"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
}
UpdateJobRequest is the body for POST /v1/runs/{runID}/jobs/{jobID}/update.